2024-03-10 05:30 PM - last edited on 2024-09-17 11:06 AM by Doreena Deng
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?
Solved! Go to Solution.
2024-03-10 06:08 PM - edited 2024-03-10 06:09 PM
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;
}
2024-03-10 06:08 PM - edited 2024-03-10 06:09 PM
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;
}
2024-03-10 07:07 PM - edited 2024-03-13 02:42 PM
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.