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)
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.
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
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?
Is there a way to select scale and units yet?
I found this post:
But I cant seem to incorporate it into my code and have the options.
It shows the DWG file is open already.