Products

Automation as a CAD Standards Enabler

CAD Standards, especially those pertaining to layers can be enforced effectively by providing tools to the user that will make him/her easy to adhere to the published guidelines.

The previous article on automation in the Draft environment for layers discussed purging un-used layers in a Draft document. This article shows in-depth how to make a layer ‘Active’ simply by picking an object on the layer.

This comes in handy when you want to start dimensioning and need to place them on the layer meant for this, as per company CAD standards.

The process involves:

1. Allowing user to pick an object.

2. Ensure user picks only one object.

3. Ensure user picks atleast one object.

4. Get the layer of the picked object.

5. Make the layer Active.

6. Inform user.

1. Begin with connecting to a running instance of Solid Edge and storing a currently open Draft document:

01.png

Next comes the critical part of the code – getting the selected object. This can be achieved using a Selection Set which was discused thoroughly in the Select Set article.

02.png

The special thing about a SelectSet is that it exists even when no object is selected by user interactively. Insert this dummy line of code just below the previous one and run the program.

03.png

04.png

The count of selected entities is reported as zero.

This also applies to the Documents collection in that the Count of Documents is reported as zero when all documents are closed, meaning the collection exists even if there are no actual documents available or open.

This behavior can be used to implement Step (3) in checking if user has selected at least one object to make its layer Active.

For this, use an IF statement as below and notify the user:

05.png

Note the use of Exit Sub which terminates the macro after displaying a message if no object was found selected.

Similarly, when the user has picked more than one object at the time of running the macro from a button on the Ribbon or so, a similar message is displayed and the macro terminates.

 06.png

Now that the minimum necessary conditions are met, the layer of the selected object is extracted by first storing the selected entity as an Object:

With the couple of checks in place, the first object found in the selection set can be safely stored as the object selected by user.

07.png

Note the Layer property is a string and stored in sLayer as seen on the second line above.

08.png

The final step is to simply make this layer Active. For this, the name of the layer is used to pick the actual Layer object from the Layers collection in one shot as below and then activated:

09.png

A recommended way is to break the line down and make it a more granular hence readable code:

 10.png

The notification on the last line is optional.

If you have a CAD standard in your company that you think might be easy to enforce via automation, do leave a comment and I will try to provide hints or some code snippets or macros for the same.

As always, the Solid Edge Dev Forum is a click away for any issues you might face when coding.

-Tushar Suradkar

http://surfandcode.blogspot.in

www.cadvertex.com

Tushar Suradkar

Solid Edge blogger, Programmer

More from this author

Comments

4 thoughts about “Automation as a CAD Standards Enabler

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/solidedge/automation-as-a-cad-standards-enabler/