Export Idw to DXF

Export Idw to DXF

meck
Collaborator Collaborator
8,731 Views
25 Replies
Message 1 of 26

Export Idw to DXF

meck
Collaborator
Collaborator

Hi All,

I've been trying to get the Inventor help sample code PublishDXF to work, but I keep getting an error on line "Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)" The error message in attached. I'm running the code in an .ipt file using iLogic. I unfold a sheet metal part then place the flat pattern on an .idw with some text. I set the .idw active and then call the PublishDXF sub.

 

It may help if I knew what all the pieces of the code was doing. For instance what is the purpose of creating.ini file,  if that's what it is doing? Does it have to be placed in a certain location? It's just very difficult to debug when I do not know what any of the arguments are doing.

 

I've tried running the code in VBA from inside the idw, but I get the same error.

 

Please can someone give me some direction?

 

Thanks in advance.

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Accepted solutions (1)
8,732 Views
25 Replies
Replies (25)
Message 2 of 26

CattabianiI
Collaborator
Collaborator

Are you sure the error occurs on SaveCopyAs line? From your image it seems HasSaveCopyAsOptions method throwing the error.

 

Could you paste here your code?

0 Likes
Message 3 of 26

meck
Collaborator
Collaborator

Oops! Your correct. I was tinkering trying to get something to work and I edited that line of code. I changed it back and now I get the error on Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium).

 

See attached...

 

BTW thanks for posting so quickly!!!!

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 4 of 26

MechMachineMan
Advisor
Advisor

Not easy to give you guidance without your code to look at.


--------------------------------------
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 26

meck
Collaborator
Collaborator

Here is the code of the entire rule.

 

Remember this is in an .ipt sheet metal file.

 

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Sub Main
'Exit Sub
    Call CreateFlatInPart
    Call MakeFlatPattern(1)
    
    Dim PartName As String = "PART NUMBER: " & ThisDoc.FileName(False) 'without extension
    Dim RevNo As String = "REVISION NUMBER: " & iProperties.Value("Project", "Revision Number")
    Dim Matl as String = "MATERIAL: " & iProperties.Material
    Dim Drafter As String = "DESIGNER: " & iProperties.Value("Project", "Designer")
    Dim sText As String
    sText = PartName & vbNewLine & RevNo & vbNewLine & Matl & vbNewLine & Drafter
    
    Call AddGeneralNote(sText, 0, 0)
    
   
    'Call ExportToDXF
    Call PublishDXF(ThisDoc.PathAndFileName(False))
End Sub

Public Sub CreateFlatInPart
'This sub creates a flat parttern within the sheetmetal model file.

'Connect to the active document
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

'Make a sheet metal component
Dim oCompDef As SheetMetalComponentDefinition

'Try setting the part file to sheet metal (This is just a test to make sure the file is sheet metal)
Try
    oCompDef = oDoc.ComponentDefinition
Catch
    ThisApplication.SilentOperation = False    
    MessageBox.Show("A sheet metal part file must be active to generate the flat pattern.", "Invalid Part File!")
    Exit Sub
End Try

'Unfold the part file if it is not already unfolded
If oCompDef.HasFlatPattern = False Then
    oCompDef.Unfold
Else
    oCompDef.FlatPattern.Edit
End If

'Try switching back to the folded part
Try
    oCompDef.FlatPattern.ExitEdit
Catch
    'MsgBox("Error Exitting Flat Pattern!")
End Try

End Sub



Public Sub MakeFlatPattern(ViewScale As Double)
'This rule creates a 1:1 scale flat pattern on a blank idw
'IMPORTANT!!!!!!!!!
'These Imports MUST be added at the top of the rule in order for this sub to work!
'    Imports Inventor.ViewOrientationTypeEnum
'    Imports Inventor.DrawingViewStyleEnum

'Declare required objects
Dim oDrawingDoc As DrawingDocument
Dim oPartDoc As Document
Dim oSheet As Sheet
Dim oView4 As DrawingView
'ViewScale = 1

'Connect to the active part
oPartDoc = ThisApplication.ActiveDocument
'Define IDW Template File Location
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "", True)
'Connect to the first drawing sheet
oSheet = oDrawingDoc.Sheets.Item(1)
' Create a new NameValueMap object
Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

oBaseViewOptions.Add( "SheetMetalFoldedModel", False)
'Define 2d view bottom left corner points for four views
oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(20, 18) ' flat pattern
oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, ViewScale, kDefaultViewOrientation, kHiddenLineDrawingViewStyle, , , oBaseViewOptions)

End Sub

Public Sub AddGeneralNote(sText As String, XPos As Double, YPos As Double)
    'This sub places sText on the active drawing sheet @ (Xos, YPos)
    XPos = XPos * 2.54
    YPos = YPos * 2.54
    
    ' a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    ' a reference to the active sheet.
    Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.ActiveSheet
    
    ' a reference to the GeneralNotes object
    Dim oGeneralNotes As GeneralNotes
    oGeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes
    
    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oGeneralNote As GeneralNote
    
    oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(XPos, YPos), sText)

    oDrawDoc = Nothing
    oActiveSheet = Nothing
    oGeneralNotes = Nothing
    oTG = Nothing
    oGeneralNote = Nothing
End Sub

Public Sub PublishDXF(PathToSave As String)
    ' Get the DXF translator Add-In.
    Dim DXFAddIn As TranslatorAddIn
    transID = "{C24E3AC4-122E-11D5-8E91-0010B541CD80}"
    DXFAddIn = ThisApplication.ApplicationAddIns.ItemById(transID)
    
    If DXFAddIn.Activated = False Then
         DXFAddIn.Activate()
     End If
    
    '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
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
    
    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Check whether the translator has 'SaveCopyAs' options
    If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
        Dim strIniFile As String
        strIniFile = "C:\temp\dxfout.ini"

        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If


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

    'Set the destination file name
    'MsgBox(PathToSave & ".dxf")
    oDataMedium.FileName = PathToSave & ".dxf"

    'DXF Exporter does NOT overwrite and will hang if previous files found
    If System.IO.File.Exists(oDataMedium.FileName) Then
        System.IO.File.Delete(oDataMedium.FileName)
    End If

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

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 6 of 26

MechMachineMan
Advisor
Advisor

Have you verified that the Make DXF section of the rule is actually grabbing the drawing document, and not actually the part document? It usually makes sense to pass the document object in the code instead of assuming that the document you want is always the active one....

 

The modified version below is half done, to give you an idea of what i mean.

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum

Sub Main
'Exit Sub
	Dim oPartDoc As PartDocument
	On Error Resume Next
		oPartDoc = ThisApplication.ActiveDocument
		If Err.Number <> 0 Then
			MsgBox("Rule only valid for part documents!")
			Exit Sub
		End If
	On Error Goto 0

    Call CreateFlatInPart(oPartDoc)
	
	Dim oDwgDoc As DrawingDocument
    Call MakeFlatPattern(oPartDoc, oDwgDoc, 1)
    
	'Need to change this yet
    Dim PartName As String = "PART NUMBER: " & ThisDoc.FileName(False) 'without extension
    Dim RevNo As String = "REVISION NUMBER: " & iProperties.Value("Project", "Revision Number")
    Dim Matl as String = "MATERIAL: " & iProperties.Material
    Dim Drafter As String = "DESIGNER: " & iProperties.Value("Project", "Designer")
    Dim sText As String
    sText = PartName & vbNewLine & RevNo & vbNewLine & Matl & vbNewLine & Drafter
    
    Call AddGeneralNote(sText, 0, 0)
    
   
    'Call ExportToDXF
    Call PublishDXF(oDwgDoc, ThisDoc.PathAndFileName(False))
End Sub

Public Sub CreateFlatInPart(oDoc As Document)
	'This sub creates a flat parttern within the sheetmetal model file.
	
	'Make a sheet metal component
	Dim oCompDef As SheetMetalComponentDefinition
	
	'Try setting the part file to sheet metal (This is just a test to make sure the file is sheet metal)
	Try
		oCompDef = oDoc.ComponentDefinition
	Catch
		ThisApplication.SilentOperation = False    
		MessageBox.Show("A sheet metal part file must be active to generate the flat pattern.", "Invalid Part File!")
		Exit Sub
	End Try
	
	'Unfold the part file if it is not already unfolded
	If oCompDef.HasFlatPattern = False Then
		oCompDef.Unfold
	Else
		oCompDef.FlatPattern.Edit
	End If
	
	'Try switching back to the folded part
	Try
		oCompDef.FlatPattern.ExitEdit
	Catch
		'MsgBox("Error Exitting Flat Pattern!")
	End Try

End Sub



Public Sub MakeFlatPattern(oPartDoc As Document, ByRef oDrawingDoc As DrawingDocument, ViewScale As Double)
	'This rule creates a 1:1 scale flat pattern on a blank idw
	'IMPORTANT!!!!!!!!!
	'These Imports MUST be added at the top of the rule in order for this sub to work!
	'    Imports Inventor.ViewOrientationTypeEnum
	'    Imports Inventor.DrawingViewStyleEnum
	
	'Declare required objects
	Dim oDrawingDoc As DrawingDocument
	Dim oPartDoc As Document
	Dim oSheet As Sheet
	Dim oView4 As DrawingView
	'ViewScale = 1
	
	'Define IDW Template File Location
	oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "", True)
	'Connect to the first drawing sheet
	oSheet = oDrawingDoc.Sheets.Item(1)
	' Create a new NameValueMap object
	Dim oBaseViewOptions As NameValueMap
	oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
	
	oBaseViewOptions.Add( "SheetMetalFoldedModel", False)
	'Define 2d view bottom left corner points for four views
	oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(20, 18) ' flat pattern
	oView4 = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint4, ViewScale, kDefaultViewOrientation, kHiddenLineDrawingViewStyle, , , oBaseViewOptions)

End Sub

Public Sub AddGeneralNote(sText As String, XPos As Double, YPos As Double)
    'This sub places sText on the active drawing sheet @ (Xos, YPos)
    XPos = XPos * 2.54
    YPos = YPos * 2.54
    
    ' a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    ' a reference to the active sheet.
    Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.ActiveSheet
    
    ' a reference to the GeneralNotes object
    Dim oGeneralNotes As GeneralNotes
    oGeneralNotes = oActiveSheet.DrawingNotes.GeneralNotes
    
    Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry

    Dim oGeneralNote As GeneralNote
    
    oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(XPos, YPos), sText)

    oDrawDoc = Nothing
    oActiveSheet = Nothing
    oGeneralNotes = Nothing
    oTG = Nothing
    oGeneralNote = Nothing
End Sub

Public Sub PublishDXF(oDocument As DrawingDocument, PathToSave As String)
    ' Get the DXF translator Add-In.
    Dim DXFAddIn As TranslatorAddIn
    transID = "{C24E3AC4-122E-11D5-8E91-0010B541CD80}"
    DXFAddIn = ThisApplication.ApplicationAddIns.ItemById(transID)
    
    If DXFAddIn.Activated = False Then
         DXFAddIn.Activate()
     End If

    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    'oContext.Type = kFileBrowseIOMechanism
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
    
    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Check whether the translator has 'SaveCopyAs' options
    If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
        Dim strIniFile As String
        strIniFile = "C:\temp\dxfout.ini"

        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If


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

    'Set the destination file name
    'MsgBox(PathToSave & ".dxf")
    oDataMedium.FileName = PathToSave & ".dxf"

    'DXF Exporter does NOT overwrite and will hang if previous files found
    If System.IO.File.Exists(oDataMedium.FileName) Then
        System.IO.File.Delete(oDataMedium.FileName)
    End If

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

--------------------------------------
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 7 of 26

meck
Collaborator
Collaborator

I am really appreciating the quick responses. Thanks people!!!!

 

I saved the .idw. Then I placed just the PublishDXF sub into a rule and ran the code (see below). I get the same error.

 

 
Sub Main
Trigger = iTrigger0
Call PublishDXF(ThisDoc.PathAndFileName(False))
iLogicVb.UpdateWhenDone = True
End Sub

Public Sub PublishDXF(PathToSave As String)
    ' Get the DXF translator Add-In.
    Dim DXFAddIn As TranslatorAddIn
    transID = "{C24E3AC4-122E-11D5-8E91-0010B541CD80}"
    DXFAddIn = ThisApplication.ApplicationAddIns.ItemById(transID)
    
    If DXFAddIn.Activated = False Then
         DXFAddIn.Activate()
     End If
    
    '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
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
    
    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Check whether the translator has 'SaveCopyAs' options
    If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
        Dim strIniFile As String
        strIniFile = "C:\temp\dxfout.ini"

        ' Create the name-value that specifies the ini file to use.
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

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

    'Set the destination file name
    'MsgBox(PathToSave & ".dxf")
    oDataMedium.FileName = PathToSave & ".dxf"

    'DXF Exporter does NOT overwrite and will hang if previous files found
    If System.IO.File.Exists(oDataMedium.FileName) Then
        System.IO.File.Delete(oDataMedium.FileName)
    End If

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

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 8 of 26

CattabianiI
Collaborator
Collaborator

Try using DataIO API instead of TranslatorAddin

 

Your PublishDXF method should be something like this:

 

SyntaxEditor Code Snippet

 Public PublishDXF(PathToSave As String)
' Get the active document. This assumes it is a part document. Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument ' Get the DataIO object. Dim oDataIO As DataIO oDataIO = oDoc.ComponentDefinition.DataIO ' Build the string that defines the format of the DXF file. Dim sOut As String sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer" ' Create the DXF file. oDataIO.WriteDataToFile(sOut, PathToSave + ".dxf")
End Sub

  

For set the options you interested in refer to the link above or google "FlatPattern to dxf DataIO" 

0 Likes
Message 9 of 26

meck
Collaborator
Collaborator

Thanks for the response Cattabinil.

This is how I started this project using this procedure. It exports the flat pattern with ease, but I need to add text to the dxf file. I was able to edit the dxf using streamwriter but it is slow. Really slow like 2 minutes. The flat pattern has about 100 holes in it so when you open the dxf in notepad it is really long. 
 
Below is the code I used to edit the dxf file.
 
If you have a faster way of adding text to the dxf file or some way to add the text before I export it to dxf that would be great.
 
 
Public Sub EditDXFFile(TextToAdd As String)

FileName = ThisDoc.FileName(False)
oPath = ThisDoc.Path
oRevNum = iProperties.Value("Project", "Revision Number")
If oRevNum = "0" Or oRevNum = "" Then oRevNum = "1"
sFname = oPath & "\" & FileName & "_" & oRevNum '& ".dxf"

sourcePath = sFname & ".dxf"
destinationPath = sFname & ".txt"

'Check that the source file exists" If not then stop running
If System.io.file.Exists(sourcePath) = False Then Exit Sub
'Check that the destination file exists: If it does delete it
If System.io.file.Exists(destinationPath) = True Then System.io.file.Delete(destinationPath)

'Change dxf to a text file so text can be added to it
System.IO.File.Move(sourcePath, destinationPath)

'Start reading each line of the text file
'Search for the Word "ENTITIES". This is where the entities begin in the file
Dim file As System.IO.File  
Dim line As String 
Dim reader() As String = System.IO.File.ReadAllLines(destinationPath)

'____Open and read a text file_______________________
oRead = System.IO.File.OpenText(destinationPath)
EntireFile = oRead.ReadToEnd()
oRead.Close()
System.IO.File.Delete(destinationPath)


Dim FoundEntities as Boolean = False

Dim NewFileText As String
Dim count As Integer=0
For Each sLine In reader
    If FoundEntities = False Then
        If sline.Contains("ENTITIES") Then 
            'MsgBox("Found ENTITIES")
            FoundEntities = True
        End If 
    ElseIf AddedMtaxt = False Then
        'Find the end of the ENTITIES by searching for the next ENDSEC
        If sline.Contains("ENDSEC") Then
            NewFileText &= vbNewLine & TextToAdd
            NewFileText &= vbNewLine & "0"
            AddedMtaxt = True
        End If
    End If
    If count = 0 Then
        NewFileText = sLine
    Else
        NewFileText &= vbNewLine & sLine
    End If
    count = count+1
    ThisApplication.StatusBarText = count
Next
 

ThisApplication.StatusBarText = "Checking the orginal file and deleting if needed"
'Check that the source file exists" If it does delete it
If System.io.file.Exists(sourcePath) = True Then System.io.file.Delete(sourcePath)

ThisApplication.StatusBarText = "Creating the new file"
'____Create and write to a text file_________________
oWrite = System.IO.File.CreateText(destinationPath)
oWrite.WriteLine(NewFileText)
oWrite.Close()

ThisApplication.StatusBarText = "Renaming the file"

'Return txt file to a dxf file
System.IO.File.Move(destinationPath, sourcePath)
End Sub

 

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 10 of 26

MechMachineMan
Advisor
Advisor

I converted your version to VBA to test, and it worked fine for me. The one issue I did run into was that it crashed at that line if the dxfout.ini did not exist in the specified location. It doesn't hurt to add in the check to make sure that file exists as well.

 

Attached is the version so you can do your own testing using the VBA's environments better toolks.

 

Sub Test()
    PublishDXF ("C:\Users\Public\Documents\test")
    Shell ("explorer.exe  C:\Users\Public\Documents")
End Sub

Public Sub PublishDXF(PathToSave As String)
    Dim DXFAddIn As TranslatorAddIn
    transID = "{C24E3AC4-122E-11D5-8E91-0010B541CD80}"
    Set DXFAddIn = ThisApplication.ApplicationAddIns.ItemById(transID)
    
    If DXFAddIn.Activated = False Then
         Call DXFAddIn.Activate
    End If

    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
        Dim strIniFile As String
        strIniFile = "C:\temp\dxfout.ini"
        oOptions.Value("Export_Acad_IniFile") = strIniFile
    End If

    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    oDataMedium.FileName = PathToSave & ".dxf"

    Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

 


--------------------------------------
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 11 of 26

meck
Collaborator
Collaborator

I did try using VBA. Just to double check I pasted your code into VBA and I get an error on the same line of code that says "Invalid procedure call or argument".

Is there anyway to check what the values of the arguments should be?

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 12 of 26

MechMachineMan
Advisor
Advisor
Accepted solution

Did you double check the ini file and it's location?

 

What I would do is add a watch to the "oOptions", "oDataMedium", "oContext", and "oDocument" variables so that you can expand them in the watch window to double check that the value are actually assigned. If they all have values assigned as corresponds to your code, then it's either something to do with the location or wrong information assigned to them.

 

But before doing that, I would double check the ini location. If it exists there, I would export another ini file from inventor UI and then test the code with that version.


--------------------------------------
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
Message 13 of 26

CattabianiI
Collaborator
Collaborator

Hi @MechMachineMan,

 

did your code work on a flat pattern? Not for me in Inventor 2018.1

 

I talked about DataIO because I think that's the way to export a flat pattern even thru UI (I mean, I don't know if internally Inventor uses TranslatorAddin or DataIO, but thru the UI File-->Export there isn't the dxf format but for drawing)

Message 14 of 26

meck
Collaborator
Collaborator

I got it to finally work. The ini file was not being created, so I created one manually first and then ran the code. Worked perfectly. Was I suppose to do that in the first place?

Thank you all for you generous help!

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 15 of 26

meck
Collaborator
Collaborator

Are you talking about the code that adds the text into the dxf file?

 

The DatatIO version of the code always worked for me, but was extremely slow when trying to add the text to the file. Using the PublishDXF code from the Inventor help example is easier for to add the text and way faster.

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 16 of 26

CattabianiI
Collaborator
Collaborator
EDIT: sorry @meck I misunderstood your original post, I thought you would work directly on the flat pattern of the ipt, without creating the drawing. Please ignore the following lines.
 

@meck wrote:

Are you talking about the code that adds the text into the dxf file?


 I was talking about the code @MechMachineMan posted here, but if it works for you I'll be missing something somewhere, don't worry.


@meck wrote:

The DataIO version of the code always worked for me, but was extremely slow when trying to add the text to the file. Using the PublishDXF code from the Inventor help example is easier for to add the text and way faster.


I don't really get this point, how do you add the text with translatorAddin solution? Do you call EditDXFFile posted above after the dxf creation? If yes the performance should be the same. Or do you achieve your goal in another way, doing something before the dxf creation?

 

By the way, you got a solution to your problem and that's what matters.

0 Likes
Message 17 of 26

MechMachineMan
Advisor
Advisor

Hi @CattabianiI

 

From @meck's code, it had looked like he was trying to work out the export using the drawing environment. Your method works for part files, but not drawing files AFAIK.

 

And yes meck, the .ini needs to be created before. It is your configured settings that the program imports to set it the specific settings (ie; ACAD export version, etc)


--------------------------------------
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 18 of 26

CattabianiI
Collaborator
Collaborator

You're right I misunderstood the original post, sorry for adding comments not focused on the question.

0 Likes
Message 19 of 26

meck
Collaborator
Collaborator

Correct MechMachineMan,

I created the dxf directly from the ipt. I then edited the dxf file by changing the dxf to a txt file and adding the text to the text in the dxf file. I deleted the original dxf file and saved the new text with the text I added and changed the extension to a dxf.

That all works. It truly did, but it took 2+ minutes to edit the text file because depending on the part the file could have 5000 lines in it.

 

In my case I could not just add the text to the end of the text file, it had to be placed after the Entities of the part and before the end of the that section. As I said it was very slow.

 

Is there a document somewhere stating how the ini file is formatted?

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes
Message 20 of 26

MechMachineMan
Advisor
Advisor

Don't think so. BUT what you do is manually export a dxf, set the settings you like, and in the dxf export dialog box still, you can export a config file. This is the .ini file.


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