Export Inventor Model to AutoCad

Export Inventor Model to AutoCad

timothy_berg
Advocate Advocate
2,843 Views
13 Replies
Message 1 of 14

Export Inventor Model to AutoCad

timothy_berg
Advocate
Advocate

I'm looking for an iLogic Rule that will export my Inventor Model to a .dwg file.

0 Likes
Accepted solutions (1)
2,844 Views
13 Replies
Replies (13)
Message 2 of 14

HermJan.Otterman
Advisor
Advisor

First create a drawing,

 

then look in the Inventor Help, API help, at the examples you will find this:

Export to DWG API Sample

Public Sub PublishDWG()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    Set DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\tempDWGOut.ini"
        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    'Set the destination file name
    oDataMedium.FileName = "c:\tempdwgout.dwg"

    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 14

timothy_berg
Advocate
Advocate

Sorry I think I have you confused, I am looking for an iLogic rule that will export my .iam file (Inventor Model) to AutoCad 3d.  And when i tried running your code it came back with an error.

0 Likes
Message 4 of 14

MechMachineMan
Advisor
Advisor

So you want to save it out as a .step file so you can load it in autocad 3d?

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@timothy_berg,

 

Try the below iLogic code which is converted from above VBA code. Before executing code, specify the path of "tempDWGOut.ini" file.

 

Public Sub Main()
    ' Get the DWG translator Add-In.
    Dim DWGAddIn As TranslatorAddIn
    DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        Dim strIniFile As String
        strIniFile = "C:\tempDWGOut.ini"
        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    'Set the destination file name
    oDataMedium.FileName = "c:\tempdwgout.dwg"

    'Publish document.
    Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 14

timothy_berg
Advocate
Advocate

No my firm still uses an AutoCad 3d file with the .dwg file extension for layout work.

EXPORT TO DWG.PNG

0 Likes
Message 7 of 14

timothy_berg
Advocate
Advocate

THAT WORKED!! Thanks

0 Likes
Message 8 of 14

rhasell
Advisor
Advisor

Hi

I stumbled across this thread while looking to do exactly the same thing, as I export my solid models all the time, but never really thought of automating it.

 

I ran the code and discovered that there is no way to create an ".ini" file for a model export.

After reviewing the code a little more, I discovered that it is exactly the same method as exporting a drawing file. (.idw) I tested my existing code, and it works perfectly.

 

I am now using  the same code that I use to export my drawings, and it uses the same '.ini' file for both '.iam' and '.idw'

 

Reg
2026.1
0 Likes
Message 9 of 14

rhasell
Advisor
Advisor

Hi

 

Apologies.

It appears that I was wrong with the INI file. Still investigating.

 

Reg
2026.1
0 Likes
Message 10 of 14

rhasell
Advisor
Advisor

Hi

 

Okay, as promised, I found it.

http://adndevblog.typepad.com/manufacturing/2016/07/configure-options-of-saveas-dwg-of-part-or-assem...

 

I modified it slightly, as the Version did not work, and changed the version as follows:

 

If oDocument.DocumentType = kPartDocumentObject Or oDocument.DocumentType = kAssemblyDocumentObject Then
                'Acad 2010 = 29
		'Acad 2013 = 31
		'Acad 2018 = 32
		oOptions.Value("DwgVersion") = 31
		oOptions.Value("Solid") = True
                oOptions.Value("Surface") = False
                oOptions.Value("Sketch") = False
        End If

It all works now.

 

 

Reg
2026.1
0 Likes
Message 11 of 14

sundaram1087
Advocate
Advocate

Hi

The code for converting the inventor assembly to autocad is working but i would like to convert it into 2007 version

 

may i know the Equivalent value for the oOptions.Value("DwgVersion") for the autocad 2007 version

 

Thanks & Regards

K.Shunmugasundaram

 

0 Likes
Message 12 of 14

rhasell
Advisor
Advisor

Hi

 

Apologies for the delay.

 

here is a list of the values:

 

SyntaxEditor Code Snippet

If oDocument.DocumentType = kPartDocumentObject Or oDocument.DocumentType = kAssemblyDocumentObject Then
                        'Acad 2000 = 23 (AC1015)
			'Acad 2004 = 25 (AC1018)
			'Acad 2007 = 27 (AC1021)
			'Acad 2010 = 29 (AC1024)
			'Acad 2013 = 31 (AC1027)
			'Acad 2018 = 32 (AC1032)
			oOptions.Value("DwgVersion") = 31
			oOptions.Value("Solid") = True
            oOptions.Value("Surface") = False
            oOptions.Value("Sketch") = False
        End If 

 

Reg
2026.1
0 Likes
Message 13 of 14

mblaptok
Contributor
Contributor

Is it possible to export only that views which are is visible in the border ? (via VBA)

 

Many times i have auxiliary views, cross-sections etc. outside the border and i do not want to export it to dwg.

0 Likes
Message 14 of 14

rhasell
Advisor
Advisor

Hi

 

Sorry mate, I have no idea. I used to do it manually in AutoCAD, but then binned that idea very quickly.

 

There might be a method to move all the geometry outside the drawing border to a new/frozen layer? (That's what I did manually, it was way too tedious, and really painful to manage with design changes.)

 

Reg
2026.1
0 Likes