Choose your top Archicad wishes!

Read more
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

DG::Browser: How to send a Array from the Browser Control to Archicad?

Joel Buehler
Enthusiast

Hehey fellow Developers!

 

I might have a easy and simple question. 

id like to send a array from the browser controll to archicad. i have seen that there is Array class in the JSValues.hpp header. i thought that the usage is similar to the GetStringFromJavaScriptVariable Method used in the DG::Browser example. But i dont get it to work. i do it this way:

 

 

	GS::Ref<JS::Array> jsArrayRef = GS::DynamicCast<JS::Array>(jsArray);
	const GS::Array <GS::Ref<JS::Base>>& items = jsArrayRef->GetItemArray();

 

 

but this gives me errors form the CountedPtrlmpi.hpp. 

Does anyone know how to implement a simple function that takes a JS array from the browser controll and convert it to a GS::Array? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Miha Nahtigal
Advocate

Sth like this:

 

GS::Array<API_Guid>* ConvertFromJsArray2GuidsArray(GS::Ref<JS::Base> jsVariable)
{
    GS::Ref<JS::Array> jsArray = GS::DynamicCast<JS::Array>(jsVariable);
    if (DBVERIFY(jsArray != nullptr)) {
        GS::Array<API_Guid>* guids = new GS::Array<API_Guid>();
        GS::Array<GS::Ref<JS::Base>> items = jsArray->GetItemArray();
        for (const GS::Ref<JS::Base> guid : items) {
            guids->PushNew(APIGuidFromString(GS::DynamicCast<JS::Value>(guid)->GetString().ToCStr().Get()));
        }
        return guids;
    }
    return nullptr;
}

 

BIMquants.comBETA - Quantities and Costs Estimation with Archicad AddOn :: looking for beta testers - DM

View solution in original post

2 REPLIES 2
Solution
Miha Nahtigal
Advocate

Sth like this:

 

GS::Array<API_Guid>* ConvertFromJsArray2GuidsArray(GS::Ref<JS::Base> jsVariable)
{
    GS::Ref<JS::Array> jsArray = GS::DynamicCast<JS::Array>(jsVariable);
    if (DBVERIFY(jsArray != nullptr)) {
        GS::Array<API_Guid>* guids = new GS::Array<API_Guid>();
        GS::Array<GS::Ref<JS::Base>> items = jsArray->GetItemArray();
        for (const GS::Ref<JS::Base> guid : items) {
            guids->PushNew(APIGuidFromString(GS::DynamicCast<JS::Value>(guid)->GetString().ToCStr().Get()));
        }
        return guids;
    }
    return nullptr;
}

 

BIMquants.comBETA - Quantities and Costs Estimation with Archicad AddOn :: looking for beta testers - DM

thank you very much for your help!

it works now! 🙂 

 

as a little side note: the problem in my case was not a wrong conversion Method, but a wrong static JS call regristration. The method where JS Functions get registred was using JS::Array instead of JS::Base. this does not work and VS does not show a error. The Compiler does also not tell you that the problem is in the JS Regristation Method.