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. When I close the Inventor DWG, the script runs fine.
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. Perhaps this is not the correct method to pursue?
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
Solved! Go to Solution.
Solved by Ralf_Krieg. Go to Solution.
Update
I have just discovered that my script works ok if I run it directly after opening the Inventor DWG. If I save the Inventor DWG, and then try to run the script, it does not work (I can not get access to the view blocks in the Inventor DWG).
This still doesn't suit the workflow.
Any ideas to what is causing this issue, or how to solve it?
Thanks
Hello
Not sure, but I think saving destroys the loaded object. Or, in other words, the loaded object is not longer the same as the saved. AFAIK Inventor saves documents by making a save as, remove the old file and rename the new one to the old name.
Either you don't save or you load just right before use / reload the document again after saving.
Thanks for your feedback. It is possible that this is causing the problem.
My workflow is : change Inventor drawing, save, run script, and repeat etc.
Currently it is : change Inventor drawing, save, close Inventor drawing, run script, re-open Inventor drawing, and repeat etc.
Closing and re-opening the Inventor DWG is a cumbersome addition to the workflow.
Any ideas how I can overcome this?
Hello
Can you try to create a copy of the InventorDWG every time you save and point your ACAD script to the copy?
Create an Logic rule in your InventorDWG and paste this code. Change the path if needed.
System.IO.File.Copy(ThisDoc.Document.FullFileName , "C:\Temp\" & ThisDoc.FileName(True),True)
Add this rule to the iLogic Eventtrigger "After Document Save" on the "This Document" Tab. Now, every time you save your InventorDWG it should be copied to C:\Temp and if your ACAD script opens this copy ... hopefully all runs fine. 🙂
Thankyou so much for this.
I tried it out and it works a treat. I just need to tweak my AutoCad VBA to point at the temp copy.
Awesome!!
Can't find what you're looking for? Ask the community or share your knowledge.