question

Mark S3 avatar image
1 Like"
Mark S3 asked Phil BoBo answered

How can I cast directly while writing a DLL?

If object A has a label, the label stores data of type Vec3.

I can't get the value of this label correctly in DLL. I try to cast the type and it looks fine, but I get an error during the edit phase.

Maybe I should know how to type cast in a DLL.How can I cast directly while writing a DLL ?

qq图片20220107133230.png

FlexSim 21.1.0
dllvec3cast
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ryan Clark avatar image Ryan Clark commented ·

Hi @Mark S3, was Jordan Johnson's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·
Phil BoBo avatar image
0 Likes"
Phil BoBo answered

Use the Vec3 constructor that takes 3 parameters.

Variant loc = A->labels["LOC"]->value;
Vec3 oldLOC = Vec3(loc[1], loc[2], loc[3]);

Since an Array doesn't have x, y, or z properties, the constructor that it is trying to use is returning compiler errors.

· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mark S3 avatar image Mark S3 commented ·

Thank you This reply solved my problem very well. But then I had a problem. How do I give an object a label of type Vec3? I tried something but it didn't work.

20220114100941.png

0 Likes 0 ·
20220114100941.png (35.7 KiB)
Phil BoBo avatar image Phil BoBo ♦♦ Mark S3 commented ·
Variant loc = A->labels["LOC"]->value;
Vec3 oldLOC = Vec3(loc[1], loc[2], loc[3]);
Vec3 newLOC = oldLOC.project(station1, station2);
Array arrayLoc = Array();
arrayLoc[1] = newLOC.x;
arrayLoc[2] = newLOC.y;
arrayLoc[3] = newLOC.z;
A->labels["LOC"]->value = arrayLoc;
1 Like 1 ·
Mark S3 avatar image Mark S3 Phil BoBo ♦♦ commented ·

Thanks. With your help, I succeeded in solving my problem.

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Mark S3 commented ·

Vec3 is not a Datatype for a label. You can only cast it as an array. If you need a Vec3 variable you have to cast it from your array.

Maybe you should try to test your coding in FlexSim directly before you implement it a DLL. So you can see what FlexSim supports.

0 Likes 0 ·
Mark S3 avatar image Mark S3 Joerg Vogel commented ·

Thank you for reply .

0 Likes 0 ·
Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered Phil BoBo converted comment to answer

You can only use objectAs() when you are casting the data on a treenode to a SimpleDataType*, a CouplingDataType* or an ObjectDataType*, or a derivative of those classes.

Vec3 isn't one of those classes. You can, however, cast it as an Array (which can be stored on a node because it is a Variant), and then cast the Array back to a Vec3:

// You can explicitely cast a Variant as an array. Then the compiler should be able to implicitly cast the array to a Vec3
Vec3 oldLoc = (Array)A->labels["LOC"]->value;
· 7
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mark S3 avatar image Mark S3 commented ·

Hi,Jordan.I tried to use your code, but I still got an error when compiling it.

error.png

0 Likes 0 ·
error.png (57.6 KiB)
Phil BoBo avatar image Phil BoBo ♦♦ Mark S3 commented ·

Jordan's answer presumes you are using the Module SDK to build your DLL with the latest FlexSim header files.

If you are using the DLL Maker instead of the Module SDK, then you won't have access to all of those properties and methods.

See How create subnodes using DLL Maker - FlexSim Community

0 Likes 0 ·
Mark S3 avatar image Mark S3 Phil BoBo ♦♦ commented ·

Hi,Phil. I am using the Module SDK to build your DLL,but not with the latest FlexSim header files .Does that matter ?

20220111082634.png


0 Likes 0 ·
20220111082634.png (17.2 KiB)
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.