Change VBA code from AxDbDocument to AcadDatabase method

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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