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: 

How to import dxf into sketch with vba

5 REPLIES 5
Reply
Message 1 of 6
stevec781
1943 Views, 5 Replies

How to import dxf into sketch with vba

I would like to write a macro to import specific layers from a dxf into a sketch and then extrude the part.  I havent been able to find anything in the help that I can understand but assume its possible using sketch.dataIO.

 

Can anyone give me a couple of lines of code to get me started.

 

Thanks

Steve

(good at autocad vba but struggling with Inventor vba)

5 REPLIES 5
Message 2 of 6
JarFu
in reply to: stevec781

Hi Steve,

 

Your idea is correct but API hasn't implemented Sketch.DataIO to import dwg or dxf files- there was a WISHLIST in our bug system. The workaround is to use ControlDefinitions("SketchInsertAutoCADFileCmd").Execute, here is the VBA:

 

Sub ImportDWGOrDXFDataToSk()
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
   
    Dim oPlnSk As PlanarSketch
    Set oPlnSk = oPartDoc.ComponentDefinition.Sketches(1)
   
    oPlnSk.Edit
    ThisApplication.SilentOperation = True
   
    Dim sFileName As String
    sFileName = "C:\Users\Public\Documents\Autodesk\Inventor 2011\Tutorial Files\Automotive\900501_D Size.dxf"
   
    Dim oCmdMgr As CommandManager
    Set oCmdMgr = ThisApplication.CommandManager
   
    oCmdMgr.PostPrivateEvent kFileNameEvent, sFileName
    oCmdMgr.ControlDefinitions("SketchInsertAutoCADFileCmd").Execute
   
    ThisApplication.SilentOperation = False
    oPlnSk.ExitEdit
End Sub

 

It only can be used to import dwg or dxf with default layer and object data.



Jar Fu
SW Engineer
Inventor QA
Autodesk, Inc.
Message 3 of 6
stevec781
in reply to: stevec781

Thanks Jar

Thats a great help, I have multiple layers to import to multiple parts but I guess I can use acad vba to create 1 file per layer and then use your code and lopp through each file.

Cheers

Steve

Message 4 of 6
manf88
in reply to: JarFu

Hey,

i am using ur code aswell to import DXF data and it works quite well, but there are no dependencies. It's just imported as single Lines, Arcs etc.

When I import the DXF by Hand i can use the two checkboxes on the left to add the dependencies, are there any Objects in the API to access them?

 

Unbenannt.png

Message 5 of 6
dersanli
in reply to: JarFu

Is this still the only method as of today?
Message 6 of 6
cencinaNB2ET
in reply to: dersanli

Is there a way to select scale and units yet?

I found this post:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/import-options-when-importing-a-dxf-...

But I cant seem to incorporate it into my code and have the options.

It shows the DWG file is open already.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report