Change VBA code from AxDbDocument to AcadDatabase method

Change VBA code from AxDbDocument to AcadDatabase method

Anonymous
Not applicable
1,092 Views
3 Replies
Message 1 of 4

Change VBA code from AxDbDocument to AcadDatabase method

Anonymous
Not applicable

I am trying to update some VBA code that I wrote 6-7 years ago, and my coding skills are very rusty, at best.

The code runs in AutoCad and updates the blocks in the active AutoCad DWG, based on the source blocks from an Inventor DWG (which is open).

It ran ok on my old PC (Windows 8, Acad 2014, Inv 2014) but does not run on newer hardware/software (Windows 10, Acad 2022, Inv 2022).

The problem seems to be that the script cannot access the Inventor DWG using the AxDbDocument method, when the Inventor DWG file is open.
I need to have the Inventor file open for my workflow.

From my research, I think I need to update the script to use AcadDatabase method rather than AxDbDocument method, but am struggling to make it work.

The key lines I need to replace are :

 

Dim ObjDbx As AxDbDocument
Set ObjDbx = ThisDrawing.Application.GetInterfaceObject("objectdbx.axdbdocument.24")
ObjDbx.Open SourceDrawing

''SourceDrawing is a string of the file pathname eg. C:\ACAD\test.dwg

Dim objBlock As AcadBlock

For each objBlock In ObjDbx.Blocks

''run the existing code

Next

 


Can anyone please help me to update my code to get the Inventor file from the filepath, and access the blocks, to update the blocks in the AutoCad DWG.

Many Thanks

 

0 Likes
1,093 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

There is no methods with AcadDatabase class that are equivalent to AxDbDocument (which is the COM implementation of the drawing database, BTW).

 

You should focus on figuring out what exactly the error is from. Are you sure it is because of the Dwg file being open by Inventor (i.e. at this line ObjDbx.Open SourceDrawing )? if so, can you manually try to open the drawing in AutoCAD while it is opened in Inventor to see if you get any error, or prompt/warning? Or, you can even try to change your code to open the drawing AutoCAD and access the data with AcadDocument/ThisDrawing, instead of AxDbDocument, just to verify that AxDbDocument cannot open the drawing, if it has been opened in Inventor; or you may also want to see if Inventor can open DWG file in different way (such as open exclusively, or share allowed; sorry, I do not Inventor, so, just a speculation). Or, you can even make a copy the the DWG file and let AxDbDocument work on the copy...

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks for the reply.

The VBA script runs ok when the Inventor DWG is closed, but does not run when it is open, so I assumed that that is the issue.

 

I found some info on another post about this:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/object-dbx-and-the-documents-collect...

 

 

 

 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

When the Inventor DWG is closed, the VBA code can access the blocks.

 

When the Inventor DWG is open, only PaperSpace0 is available to access using the same VBA code.

 

Any ideas?

0 Likes