question

Ryosuke S avatar image
0 Likes"
Ryosuke S asked Matthew Gillespie answered

Changing the location of 3dObject created by createInstance

After creating object with createInstance, I want change its location. But I seem to fail. In the past answers, it say to use setloc(), but it is deprecated now, and I don't know what to use as replacement to that API. What api should I use? My code looks like below

    string lib_name = "?" + strObj;    
    obj_3d = createinstance(library().find(lib_name),model());
    obj_3d.name = strObjName;
    
    double loc_x = tb[i][3];
    double loc_y = tb[i][4];
    double loc_z = tb[i][5];
    
    Vec3 vec = [loc_x, loc_y, loc_z];
    
    obj_3d.location = vec;

I also tried setLocation() but that didn't work either...

FlexSim 20.1.3
flexscriptflexsim 20.1.3createinstance
5 |100000

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

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered

I'm not sure what the problem is with your code snippet because several of the variables aren't defined, so I assume you haven't posted the full code. The biggest potential problem is that obj_3d needs to be declared as an Object type.

Here's a code snippet that works:

string class = "Processor";
Object obj = createinstance(library().find("?" + class), model());
obj.location = Vec3(5, 5, 0);

Or here's another one using the setLocation() method:

string class = "Processor";
Object obj = createinstance(library().find("?" + class), model());
obj.setLocation(5, 5, 0);
5 |100000

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