Error using copyobject with conveyors

Error using copyobject with conveyors

iago_mf
Not applicable
278 Views
8 Replies
Message 1 of 9

Error using copyobject with conveyors

iago_mf
Not applicable

[ FlexSim 23.2.0 ]

Hi,

I was trying to use de fuction copyobject() with conveyors, but i've found that it's not possible to set properties of the new conveyor, some errors appear.

Why is this happening?

23.2 Error copyobject Conveyor.fsm

Thanks!

0 Likes
Accepted solutions (1)
279 Views
8 Replies
Replies (8)
Message 2 of 9

jason_lightfoot_adsk
Autodesk
Autodesk
Accepted solution


Worked for me with:

Vec3 newlocation =  Vec3(0,0,1);    // update implicit cast from [0,0,1] is also okay - this was a red herring

You should not need the function_s call, since that is done by the property's setValue function.

0 Likes
Message 3 of 9

iago_mf
Not applicable

Hi @Jason Lightfoot

I'm still getting the same error in that way. Also, using copy instance is working with [0,0,1]

error2.gif

0 Likes
Message 4 of 9

jason_lightfoot_adsk
Autodesk
Autodesk

Yes - you're right - if you step through to debug the script with the 3D view open it works, while just running it outright (mostly) or stepping through with the 3D view closed seems not to.

As you say, this works:

Object newconv = conv.copy(model());
Message 5 of 9

iago_mf
Not applicable

Using the next expression after createcopy works (moreless), maybe it's something about doing instantly:

Object conv = Model.find("StraightConveyor1");
Object newconv = createcopy(conv, model());

await Delay.realTime(0);

Vec3 newlocation =  Vec3(0,0,1);
newconv.setProperty("StartLocation",newlocation);
repaintall();
0 Likes
Message 6 of 9

jason_lightfoot_adsk
Autodesk
Autodesk
That doesn't work if the 3D view is closed. So now the question is why the treenode copy() method works and the createcopy() function doesn't. However 'createcopy()' is deprecated so I'll not create a report - use the treenode copy method instead.
0 Likes
Message 7 of 9

iago_mf
Not applicable

Thank you Jason!

0 Likes
Message 8 of 9

philboboADSK
Autodesk
Autodesk

treenode.copy() automatically fires the OnCreate event unless you pass a flag to suppress it.

createcopy() does not. You have to call firecreateevent() yourself to execute the OnCreate event if you use createcopy().

(The original problem was caused by the conveyor's OnCreate event not being fired.)



Phil BoBo
Sr. Manager, Software Development
Message 9 of 9

iago_mf
Not applicable

Thanks for finding the cause, Phil !

0 Likes