API Rename Bodies

Hello

I am looking to facilitate the understanding and drawing of a multi-body file. To do this, one of my avenues of reflection would be to rename the bodies of this part by incremented subset. All via a macro that allows me to click on the bodies that are renamed.

In a clearer and more explicit way: imagine a part file of a piece of furniture made up of multiple sub-assemblies: body, door, drawer, shelves. These sub-assemblies are themselves made up of several distinct bodies (for example for the drawer: the front, the knob, the bottom, the sides and the back). To make this readable, I would like to launch a macro that asks me to click on the bodies in the 3D view that make up the drawer and rename these bodies "drawer [1], drawer[2], drawer[3], ... ". When I have identified all the pieces of the drawer, I click on the right button and the macro automatically switches to renaming the door elements: "door [1], door [2], ..."  And so on for all subsets. After several searches, I found a macro that allows you to display the name of a body when you click on it, which I mixed with another one that allows you to rename with swbody.name=. I stumble over the editing of the loops, especially the right-click test.

I'm almost new to APIs, my old experiences are unfortunately totally forgotten, due to a lack of regular practice. I know that API experts are active here (I actually stole the selection macro from the tutorials in .PL), any help in what must be quite basic for them will be welcome.

Thank you.

Sebastian

2 Likes

Hello

Something quite simple and within everyone's reach, is to make a macro by learning, so you can see how SolidWorks does it!

Otherwise, there is some interesting information here:

https://forum.solidworks.com/thread/81918

And maybe here:

https://forum.solidworks.com/thread/55341

1 Like

Thank you for this first feedback. I have already found and exploited the second link.

My problem is not so much on SW anymore, but rather on VBA. Learning macros under SW doesn't allow me to learn how to code a loop and its output events (right button in this case).

My script would be:

  • implementation in the code of a list of names (drawer, shelf, ...) -> I'll look for it, not too much of a problem I think
  • when launching the macro, it asks me to click on the items in the first list (drawer) -> partially OK
  • I click on X body successively with the left button, the macro changes the name of the bodies to drawer1, drawer2,...,  drawerX ("drawer" being the first on the list)-> OK thanks to the 2nd link and macro.PL
  • I click on the right button, the macro resumes the loop just above by asking me to click on the items on the shelf (2nd on the list) -> This is where I get stuck
  • End of the macro when right-clicking on the last piece of the last list (which may be empty).

Afterwards, I'll look for how to get the list to enter through a dialog box at startup, but it's really accessory.

I'm going to go through and test based on the first link I hadn't found, there is some very interesting information in it at first glance. But I don't know if the right-click action is used.

Thank you.

2 Likes

For the click, search for "event click".

See this page:

https://books.google.fr/books?id=ftVsBgAAQBAJ&pg=PA97&lpg=PA97&dq=event+click+solidworks&source=bl&ots=11x9fcPapa&sig=yk4KI0H_hDwF6M2BpRQBoPdH5ow&hl=fr&sa=X&redir_esc=y#v=onepage&q=event%20click%20solidworks&f=false

Or see here:

http://help.solidworks.com/2015/English/api/sldworksapi/Run_SOLIDWORKS_Commands_and_Synthesize_Mouse_Events_Example_VB.htm

http://help.solidworks.com/2012/English/api/sldworksapiprogguide/Overview/Events.htm?id=6328edd0faf9464baf45de5be3f06f30