cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
Joel Buehler
Enthusiast

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

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 Solution

Accepted Solutions
Miha Nahtigal
Expert

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 in Archicad - BETA testers needed.

Go to post

2 Replies 2
Miha Nahtigal
Expert

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 in Archicad - BETA testers needed.
Joel Buehler
Enthusiast

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. 

 

 

 

 

 

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!