AnswerHub Upload Issue
Our AnswerHub community currently has a bug that prevents you from attaching your model or other files to your questions. AnswerHub is aware of this issue and they are working on a fix. Until we receive their patch, you can upload your models and other files to FlexSim's file share site. Include the file name in your question so that we know which upload to reference.

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
dllcastvec3
· 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.

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.

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)
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 ♦♦ ·

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

0 Likes 0 ·

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 ·

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.

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)

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 ♦♦ ·

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.