I have a number of repetitive tasks that I would like to automate and it seems the best way to do this is to create a simple VBA routine and apply them.

The first part of the task is to run a query on the loaded drawing and split it in to Inside and Outside layers. For the example lets say I have two shapes, one is inside the other and I want to drop these on the separate layers then apply a tool path to them individually.

The query is prety simple and works by itself.

Import layers from active drawing (often the file I have has been pulled in from a DXF with no layers)

if (is Inside Another = TRUE)
Then "InsideLayer"
ElseIf (is Inside Another = FALSE)
Then "OutsideLayer"

Next part was to create a simple button to run the query so I dont need to load it every time I want to use it.

Dim Drw As Drawing
Set Drw = App.ActiveDrawing
Drw.RunQuery ("InOutQuery.agq")
End

If I load the drawing the Load the VBA add-In with the button it works fine.
If i then close then drawing and open another drawing then use the button it does not work
If i create a new drawing, put a shape inside another shape the button works fine.

It is almost as if the Geometry layer on the drawing is not being activated or App.ActiveDrawing is being ignored by the simple function when an existing drawing is opened.

I would appreciate any suggestions as to how to fix this.

The end goal is to create a nice little function that with the click of a button will split the inside and outside profiles, Add an offset to each that will be used as a flange add an inside offset that will be used as a pocket and then create a drill hole pattern on the part saving a whole pile of manual processing time.

Similar Threads: