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: 

Export STEP file from member of ipart and assign specific name to it

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
cgoethalsFU8PY
332 Views, 5 Replies

Export STEP file from member of ipart and assign specific name to it

Dear Autodesk members.

 

I am trying to adapt my code to bulk export .STEP files from .iam documents and while doing this assign them the following name: Subject - Filename of .iam

When I use the following code my .iam-files are exported to .STEP-files, but the right name is not assigned as I want. Would it be possible to help me out?

Thank you very much on forehand!

Sub main()
    Dim oSTEPTranslator As TranslatorAddIn
    Dim oContext As TranslationContext
    Dim oOptions As NameValueMap
    Dim oDataMedium As DataMedium

    Call ConfigureoSTEPTranslatorSettings(oSTEPTranslator, oContext, oOptions, oDataMedium)

    Dim oFileDlg As Inventor.FileDialog = Nothing
    InventorVb.Application.CreateFileDialog(oFileDlg)
    'oFileDlg.Filter = "Inventor Files (*.iam)|*.iam"
    oFileDlg.DialogTitle = "Delete Ilogic Rule in drawing"
    oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName ' ThisDoc.Path
    oFileDlg.MultiSelectEnabled = True
    'oFileDlg.FilterIndex = 1
    oFileDlg.CancelError = True
    On Error Resume Next
    oFileDlg.ShowOpen()
    If Err.Number <> 0 Then
        MessageBox.Show("File not chosen.", "Dialog Cancellation")
    ElseIf oFileDlg.FileName <> "" Then
        For Each wrd In oFileDlg.FileName.Split("|") 'Words
            Dim odoc As Document = ThisApplication.Documents.Open(wrd, True)
            On Error Resume Next
            oOptions.Value("FileName") = odoc.iProperties.Value("Summary", "Subject") & " - " & odoc.FileName(False)
            oDataMedium.FileName = Left(odoc.FullFileName, (InStrRev(odoc.FullFileName, ".", -1, vbTextCompare) - 1)) & ".stp"
            Call oSTEPTranslator.SaveCopyAs(odoc, oContext, oOptions, oDataMedium)
            odoc.Close
        Next
    End If
    MessageBox.Show("STEP-Export geslaagd. Proficiat! Je hebt zonet heel wat tijd uitgespaard! Groetjes, jullie programmeergenie Cor :)")
End Sub

Sub ConfigureoSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
    oPath = ThisDoc.Path
    oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

 

 

Labels (5)
5 REPLIES 5
Message 2 of 6
WCrihfield
in reply to: cgoethalsFU8PY

Hi @cgoethalsFU8PY.  You can give this slightly edited version a try.

 

Sub main()
    Dim oSTEPTranslator As TranslatorAddIn
    Dim oContext As TranslationContext
    Dim oOptions As NameValueMap
    Dim oDataMedium As DataMedium

    Call ConfigureoSTEPTranslatorSettings(oSTEPTranslator, oContext, oOptions, oDataMedium)

    Dim oFileDlg As Inventor.FileDialog = Nothing
    InventorVb.Application.CreateFileDialog(oFileDlg)
    'oFileDlg.Filter = "Inventor Files (*.iam)|*.iam"
    oFileDlg.DialogTitle = "Delete Ilogic Rule in drawing"
    oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName ' ThisDoc.Path
    oFileDlg.MultiSelectEnabled = True
    'oFileDlg.FilterIndex = 1
    oFileDlg.CancelError = True
    On Error Resume Next
    oFileDlg.ShowOpen()
    If Err.Number <> 0 Then
        MessageBox.Show("File not chosen.", "Dialog Cancellation")
    ElseIf oFileDlg.FileName <> "" Then
        For Each wrd In oFileDlg.FileName.Split("|") 'Words
            Dim odoc As Document = ThisApplication.Documents.Open(wrd, True)
			Dim oPath As String = System.IO.Path.GetDirectoryName(odoc.FullFileName)
            Dim sSubject As String = odoc.PropertySets.Item(1).Item("Subject").Value
			Dim sFileNameWOExt As String = System.IO.Path.GetFileNameWithoutExtension(odoc.FullFileName)
            oDataMedium.FileName = oPath & "\" & sSubject & " - " & sFileNameWOExt & ".stp"
            Call oSTEPTranslator.SaveCopyAs(odoc, oContext, oOptions, oDataMedium)
            odoc.Close
        Next
    End If
    MessageBox.Show("STEP-Export geslaagd. Proficiat! Je hebt zonet heel wat tijd uitgespaard! Groetjes, jullie programmeergenie Cor :)")
End Sub

Sub ConfigureoSTEPTranslatorSettings(ByRef oSTEPTranslator As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
    oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6
cgoethalsFU8PY
in reply to: WCrihfield

Thank you very much!

Message 4 of 6

@WCrihfield

I'm having the same issue with my pdf exporter since I need to refer to the subject of one of my drawing views. How do you suggest tackling this? Hereby you can find my code.

 

 

Sub main()
	
Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium
Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.idw)|*.idw"
oFileDlg.DialogTitle = "Delete Ilogic Rule in drawing"
oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName ' ThisDoc.Path
oFileDlg.MultiSelectEnabled =True 
oFileDlg.FilterIndex = 1
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
	MessageBox.Show("File not chosen.", "Dialog Cancellation")
ElseIf oFileDlg.FileName <> "" Then
	For Each wrd In oFileDlg.FileName.Split("|") 'Words
		Dim odoc As Document = ThisApplication.Documents.Open(wrd, True)
		Dim oPath As String = System.IO.Path.GetDirectoryName(odoc.FullFileName)
		Dim oView As DrawingView
		Dim sSubject As String = oView.ReferencedDocumentDescriptor.ReferencedDocument.iProperties.Value(oViewModelName, "Subject")
		Dim sFileNameWOExt As String = System.IO.Path.GetFileNameWithoutExtension(odoc.FullFileName)
        oDataMedium.FileName = oPath & "\" & oPartname & " - " & sFileNameWOExt & ".pdf"
		Call PDFAddIn.SaveCopyAs(odoc, oContext, oOptions, oDataMedium)
		odoc.Close
	Next

	
End If
MessageBox.Show("PDF-Export geslaagd. Proficiat! Je hebt zonet heel wat tijd uitgespaard!")

End Sub

Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oPath = ThisDoc.Path
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 1
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 1
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

 

Message 5 of 6
WCrihfield
in reply to: cgoethalsFU8PY

Hi @cgoethalsFU8PY.  I am not sure if this will work for you or now without asking several related questions, but here is an attempt to fix your PDF export iLogic rule code.  I left a few comments in there that may help you, if it does not work right away.

Sub Main
	Dim PDFAddIn As TranslatorAddIn
	Dim oContext As TranslationContext
	Dim oOptions As NameValueMap
	Dim oDataMedium As DataMedium
	Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
	Dim oFileDlg As Inventor.FileDialog = Nothing
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Inventor Files (*.idw)|*.idw"
	oFileDlg.DialogTitle = "Delete Ilogic Rule in drawing"
	oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName ' ThisDoc.Path
	oFileDlg.MultiSelectEnabled =True 
	oFileDlg.FilterIndex = 1
	oFileDlg.CancelError = True
	Try
		oFileDlg.ShowOpen
	Catch
		MessageBox.Show("File not chosen.", "Dialog Cancellation")
		Exit Sub
	End Try
	Dim sSelection As String = oFileDlg.FileName
	If sSelection = "" Then Exit Sub
	Dim oFiles As New List(Of String)
	If sSelection.Contains("|") = False Then
		oFiles.Add(sSelection)
	ElseIf sSelection.Contains("|") = True Then
		oFiles.AddRange(sSelection.Split("|"))
	End If
	For Each sFile In oFiles
		'since the file filter is for drawing files only, I assume every file will be a drawing file
		Dim oDDoc As DrawingDocument = ThisApplication.Documents.Open(sFile, False)
		Dim oPath As String = System.IO.Path.GetDirectoryName(oDDoc.FullFileName)
		'and here I assume there will always be a DrawingView on the first sheet of the drawing file, representing the model we need to access
		Dim oView As DrawingView = oDDoc.Sheets.Item(1).DrawingViews.Item(1)
		'the model file being referenced within that view should already be loaded into Inventor's memory by opening the drawing
		Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		Dim sSubject As String = oViewDoc.PropertySets.Item(1).Item("Subject").Value
		Dim sFileNameWOExt As String = System.IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
		oDataMedium.FileName = oPath & "\" & sSubject & " - " & sFileNameWOExt & ".pdf"
		Call PDFAddIn.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
		oDDoc.Close
	Next
	ThisApplication.Documents.CloseAll(True) 'True  = closes unreferenced documents only
	MessageBox.Show("PDF-Export geslaagd. Proficiat! Je hebt zonet heel wat tijd uitgespaard!")
End Sub

Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 1
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 1
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6
cgoethalsFU8PY
in reply to: WCrihfield

@WCrihfield thank you. It is clear for me now that not all heroes wear capes!

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report