Solved

Chancing the Material with a Macro

  • 28 September 2020
  • 1 reply
  • 180 views

Hello,

I would like to change the material properties of certain object types using a macro.

Therefore I would like to use a For loop to scan all object types and change the material and all coatings of my CAD parts in mirrors.


In itself very simple, but I did not find out how to use my commands.

GetNSCObjectData is my plan for the Objecttype

To change the material and the coaatings I am not sure about the right command.

Additionally it would be good to know if there is a 'number specification' of all objects, comparable to .length in other languages.


If a ZOS API application is required for this it would be good to know if I need to pay attention to this.




With kind regards

icon

Best answer by Csilla Timar-Fulep 28 September 2020, 15:10

View original

1 reply

Userlevel 5
Badge +2

Hello Christian,

Thanks for your question here!

First, in order to read the Object type of an object in the NSC Editor, you need to use the NPRO() numeric macro function:

200928-134422-image.png

As said in the Help, in order to read string values, you have to use the  $buffer() function. So for example to extract the type of the first object, you need code 0, and the lines as in the example below:

type = NPRO(1,1,0,0)objectType$ = $buffer()print 'object type: ',print objectType$

GetNSCObjectData will not work from the ZPL macro, it is for the extensions, as you may check it from the header in the Help:

200928-135554-image.png

Then, once you have checked the object type, you may use the SETNSCPROPERTY keyword to change the material and the coating on the object. The proper syntax is as follows:

SETNSCPROPERTY surface, object, code, face, value

For the material you need code 4, and for the Coat/Scatter properties you can use codes 5...41 as discussed in the Help. You may read more about how to use the SETNSCPROPERTY keyword in the Help file at: The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > SETNSCPROPERTY (keywords)

For further reference, please check out the knowledgebase article about how to add coatings to non-sequential objects:https://support.zemax.com/hc/en-us/articles/1500005486641-How-to-add-coatings-and-scattering-functions-to-Non-Sequential-objects

Please make sure to use the UPDATE keyword after modifying the object parameters! You may read more about this in the Help at: The Programming Tab > About the ZPL > KEYWORDS (about the zpl) > UPDATE

Finally, to define the length of the FOR loop, you can use the NOBJ() numerical function to extract the number of objects in the NSC Editor:

200928-140523-image.png

If you are in pure non-sequential mode please use 1 for the surface number input:

​​​numberOfObjects = NOBJ(1)

If you have further questions, please let us know and we will be happy to help!

Best regards,

Csilla

Reply