question

Axel Kohonen avatar image
3 Likes"
Axel Kohonen asked Matthew Gillespie edited

How do I set the photo eye type in code?

Hi,

I have a photo eye that I put on a conveyor using code (just create the photo eye into the conveyor to create the link automatically) and I would want the photo to be a certain pre-defined type that I have created earlier. How can I set the type in code? Should I first create a basic photo eye with createinstance and then set the type or can I create a copy of the instance in the conveyor system?

Thank you!

Kind regards,

Axel

FlexSim 16.0.1
conveyorcodephoto eyeautobuildcreateinstance
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
2 Likes"
Matthew Gillespie answered Ben Wilson commented

Photo Eyes (and all conveyor objects) have a type variable that points at their type object. This can either be a global type stored on the Conveyor System object or a custom type stored in the objects variables.

To set the type just point the type variable at the desired type:

treenode photoEye = node("PE1", model());
treenode typeVar = getvarnode(photoEye, "type");
treenode desiredType = node("ConveyorSystem>variables/photoEyeTypes/PEType1", model());

nodepoint(typeVar, desiredType);

You can sample the types in the toolbox from the sampler in the script console to get the paths to each type.

To set the type to custom point the "type" variable at the object's "localType" variable.


typesampler.png (15.9 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.

Arun Kr avatar image Arun Kr commented ·

Hi Mathew,

Can you explain why you used nodepoint() command?

Is the photo eye type a coupling data in the photo-eye object.

Regards,

Arun KR

0 Likes 0 ·
Ben Wilson avatar image Ben Wilson ♦♦ Arun Kr commented ·

Anyone finding this thread looking for more information on couplings, in addition to the nodepoint() command, which is a one-way pointer, be sure to check out createcoupling(), which creates a two-way pointer/reference.

3 Likes 3 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Arun Kr commented ·

Yes, I used the nodepoint command because the type variable has coupling data. This means it stores a reference to another node, or that it "points" at another node. The way that you set what a coupling node is pointing at is to use the nodepoint command.

@Axel Kohonen

1 Like 1 ·
Axel Kohonen avatar image Axel Kohonen commented ·

Thank you Matthew! Works well. I would like to know the answer to Arun's comment as well.

Axel

0 Likes 0 ·