|Home » Forums » CAD » Message||Login|
You are not logged in. Consider these WOODWEB Member advantages:
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)
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
If I load the drawing the Load the VBA add-In with the button it 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.
It sounds more to me like you have lost connection to the active application.
You should be able to check that with a watch window. Highlight the text for the app in your code and drag and drop it into the watch window (open the watch window if need be), and see if it's active and has data.
It does seem strange. I don't do AlphaCAM VBA, but do understand that the drawing itself (the active document), in a VBA context, is how the code knows the application is there. If it were VB6 then it might be a 'late bound' or 'early bound' issue, but this is VBA. Mike may drop in and answer your question better. I will try and give him a head's up.
"Dim Drw As Drawing", is probably not needed, as whatever the default AlphaCAM object is in the project explorer is, is the default name and document. In AutoCAD VBA it is called "ThisDrawing". When working with multiple documents you will have to explicitly name them and switch between them. You don't note whether or not the code is set to run explicit:
"Option Explicit" at the top sometimes makes it easier to find the bug.
Other than that, I have no idea other than your binding to the application is broken.
Thank you David for the ideas, will try a few of them and see how they go. It makes sense that the active drawing is some how loosing focus. I'm somewhat new to VB although have programmed in C and a few other languages.
Our new 5 Axis HOMAG just turned up yesterday and is being installed so may be a few days before I get the chance to try a few other things out but will keep everyone posted as to what the issue ends up being.
Totally loving the VB and Alphacam scripting system as it realy does make the creation of commonly used geometries so simple.
send me your macro. I will help you with this.