Macro, scan feature tree of assembly, rename parts

Ill first preface this post with the following: Ive never used macros. But its now getting to the point where im sick to death of wasting hours doing tedious work that could be done with macros.

I have some assemblies that are imports of Inventor files, during this import its added a lot of unnecessary junk to the file names, which is giving me invalid paths stopping me from saving them into native solidworks files.

I have looked at a few tutorials on creating macros and searched around for a macro that will do what I want, havent found anything yet but I would like to create my own macro so I can learn how to do this myself.

An example filename:

Copy of TK-380-DT-01-01.ipt^Copy of TK-380-DT-01.iam_Copy of TK-380-DT-00.iam_Copy of TK-380-BOD-00.iam_Copy of TK-380-ASY-00.iam_TK-380-ASY-00-1@TK-380-ASY-00

As you can see lots of junk. What I would like to do in a nutshell:

  • Go through the feature tree and change each file in the following way
    • Delete first instance of "copy of" and delete anything after the . at ".ipt". In the case of the above part name it will reduce it down to "TK-380-DT-01-01"

Is it possible to do this kind of commands in macros? If so where is a good place I can learn how to do these types of commands? Is it also possible to ask for user input during the running of a macro? (like choose a folder for example)

Is there also somewhere I can get explanations on what things mean, for example Part.Extension.SelectByID2

SolidworksApi macros
Answers 2
MS
MS 2018-04-02 Best Answer

Hi Ben,

Yes, you can certainly get in and learn the SOLIDWORKS API to do what you're asking.  You will need some code language knowledge to start.  If you want to go all-in, I'd recommend a formal course like this one...

MySolidWorks - Official SOLIDWORKS Community

Or, there are dozens of great online resources including free and paid offerings from YouTube, blogs and CADSharp at SolidWorks API Video Tutorials​

Insert shameless book plug here as well...

https://www.amazon.com/Automating-SOLIDWORKS-2017-Using-Macros/dp/1630570842/ref=sr_1_1?ie=UTF8&qid=1522708871&sr=8-1&ke…

You'll get lots of help in this forum when you have specific questions!  This is a great group.  Best of luck!

Mike

BR
BR 2018-04-04

Thanks Michael, have been considering purchasing your book actually!