question

Ameen M Shabeer avatar image
0 Likes"
Ameen M Shabeer asked Joshua S commented

Planar Mid Points of an Object Using Code

Hi,

How can i access Planar Mid Points of an Object Using Code ?

FlexSim 18.2.2
planar mid points
capture.jpg (59.2 KiB)
5 |100000

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

Steven Hamoen avatar image
3 Likes"
Steven Hamoen answered Jason Lightfoot edited
@Ameen MS

If you check the helpfile Class reference and look for the getLocation method of the Object class you should be able to figure it out. The example actually shows you how to get the center

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

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

Also to allow for hierarchies I would recommend always projecting to the layer for which you want coordinates. For example (model coordinates):

Object targetspace=model();
Object myobject=Model.find("?Combiner1");
Vec3 objloc=myobject.getLocation(0.5,0.5,0.5).project(up(myobject),targetspace); 
double x=objloc.x;
double y=objloc.y;  //etc..
1 Like 1 ·
Sebastian Hemmann avatar image
2 Likes"
Sebastian Hemmann answered Joshua S commented

Hey, the easiest and fastest way I think is to look into an objects trigger where you want to define the location, take the Pickoption and see what development team does by default.

So I took an Processors On Entry trigger and did:

The default option seems to be what your are looking for:

And if you now open the Script Window of the Trigger you can see

the command you are looking for is

setloc();

and there are Parameters for the Object, the X Y Z Location and than you are allowed to implement Factors. these Factors are in your case xFactor = 0.5, yFactor = 0.5, zFactor = 0!


view1.png (20.6 KiB)
view2.png (9.0 KiB)
view3.png (30.0 KiB)
· 4
5 |100000

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

Ameen M Shabeer avatar image Ameen M Shabeer commented ·

Hi, Thanks For your Reply

I have the object already in Model. I want to get the Center location using Code.

0 Likes 0 ·
Sebastian Hemmann avatar image Sebastian Hemmann commented ·

If you want to access the position/ location there are different ways you can try.

1. Use the Method .location that is implemented for all Objects

2. You can use xloc();yloc();zloc(); to get the same results like the Method of 1

3. Tryout Vec3 to get the location of objects in Containers relative to everything you want

But I assume all of these ways will return the left bottom point of the 3 D Object as it was referenced before we got these nice placement feature.

So what you can do is calculate the position by getting for example:

double d_CenterXloc = Object.location.x + (Object.size.x/2);
0 Likes 0 ·
Ameen M Shabeer avatar image Ameen M Shabeer Sebastian Hemmann commented ·

Hi, This method will not work in Z Rotated Objects

1 Like 1 ·
Joshua S avatar image Joshua S Ameen M Shabeer commented ·

@Ameen MS

Use this, which is basically what sebastian was referencing to earlier

Object Obj="Your Object";
Vec3 Center=Obj.location+Obj.size/2*Vec3(1,-1,1);
Center.z=Obj.location.z;
return Center;

What do you mean it won't work around Z rotated objects, the center is the Z axis about which you are rotating an object, so that wouldn't matter.

0 Likes 0 ·

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.