How to create a simple macro in SolidWorks?

Tutorial by Kir Ari

Ok, here it is. The Macro is attached. The screenshot of the macro is also attached. This macro creates a plane, draws a rectangle and extrudes it, every time in the same position irrespective of any other already presented features etc.

There are comments for each operation, so It should be pretty clear now. Couple of main points:

1) Every time you create the sketch you have to assign it as an object to a new variable of type Object (in our case it is Sketch_Hardi) before(!) closing it. This way you will have all sketch names organized, and you will always select the right one.

2) Every new feature you create (Plane, Extrude, etc) with new variable of type Object as well. This gives you the same control of selection only the right features as you want them (By referring to it's name). Like in our case it is Hardi_Plane.Name and Hardi_Extrude.Name

3) If you have a lot of features, just use arrays of type Object (if you need help with arrays, loops etc, let me know)

4) We have a proper Object-Oriented code, so think in classes, methods, and instances. Again, need help, just point to the part that you do not understand and I'll explain it to you on a basic level.

Hope this helps, enjoy

  1. Step 1:

    See green comments step by step


Please log in to add comments