Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA code to read access drawing view blocks while Inventor drawing is open

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
425 Views, 5 Replies

VBA code to read access drawing view blocks while Inventor drawing is open

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

5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

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

Message 3 of 6
Ralf_Krieg
in reply to: Anonymous

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.


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 4 of 6
Anonymous
in reply to: Ralf_Krieg

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?

Message 5 of 6
Ralf_Krieg
in reply to: Anonymous

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. 🙂


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 6 of 6
Anonymous
in reply to: Anonymous

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report