Export all Open .IDWs or Only the active .IDW to PDF, DXF, DWG

Export all Open .IDWs or Only the active .IDW to PDF, DXF, DWG

omatthewsZA8PL
Participant Participant
1,143 Views
7 Replies
Message 1 of 8

Export all Open .IDWs or Only the active .IDW to PDF, DXF, DWG

omatthewsZA8PL
Participant
Participant

Hi, 

I have cobbled together some basic code found here on the forums to export .idw's as PDFs DXFs & DWGs. It works well for a single file, finding the correct folder to place the corresponding format into and appending the either (REL) or (Rev "No.") to the end of the file name. 

 

I am struggling to get a loop to work, 

I want the code to ask if I want only the current .IDW or to look for all currently open .IDW's

Then ask what format to save it as.

Then either export the single file or loop though all the open files placing the correct file name and appending the correct revision number

Then at the end display a message that its done.

 

My coding skills are quite basic any help is appreciated. 

Thanks, 

Sub Main()
'-----Check path----- 
	oPath = ThisDoc.Path 

'-----Get Target folder paths-----
	oPDFFolder = Left(oPath, InStrRev(oPath, "\")) & "3. PDFs"
	oDXFFolder = Left(oPath, InStrRev(oPath, "\")) & "4. DXFs"
	oDWGFolder = Left(oPath, InStrRev(oPath, "\")) & "5. DWGs"

'-----Check for the folder paths and create it if they do not exist-----
	If Not System.IO.Directory.Exists(oPDFFolder) Then
	System.IO.Directory.CreateDirectory(oPDFFolder)
	End If

	If Not System.IO.Directory.Exists(oDXFFolder) Then
	System.IO.Directory.CreateDirectory(oDXFFolder)
	End If
	
	If Not System.IO.Directory.Exists(oDWGFOLDER) Then
	System.IO.Directory.CreateDirectory(oDWGFolder)
	End If
	

'-----Inital User Input -----
	'-----User defined Scope-----
	UserChoice = InputRadioBox("What files do you want to export", "Only This Open Document", "All Open Documents", True, Title := "Defined the scope")
	
	'-----User question setup -----
	UserSelectedActionList = New String(){"Sheet Metal - PDF, DXF & DWG", "Machined Part - PDF & DWG", "PDF Only", "DXF Only", "DWG Only"}
	'-----User question input -----
	UserSelectedAction = InputListBox("What Format is Required ?", _
	UserSelectedActionList, UserSelectedActionList(0), Title := "File Type to Export", ListName := "File Format Type")
    Select UserSelectedAction
		Case "Sheet Metal - PDF, DXF & DWG" : UserSelectedAction = 1
		Case "Machined Part - PDF & DWG" : UserSelectedAction = 2
		Case "PDF Only" : UserSelectedAction = 3
		Case "DXF Only" : UserSelectedAction = 4
		Case "DWG Only" : UserSelectedAction = 5
	End Select


'-----Set active document-----
	oDocument = ThisApplication.ActiveDocument

'-----Load file iproperties into variables-----
	oFileName = ThisDoc.FileName(False)		'file name Without extesion 
	oPartNumber = iProperties.Value("Project", "Part Number")
	oDescription = iProperties.Value("Project", "Description")
	oRevNum = iProperties.Value("Project", "Revision Number")

'-----Load PDF Add In-----
	oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	'oDocument = ThisApplication.ActiveDocument
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'-----PDF options -----
	If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
		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") = 2
		'oOptions.Value("Custom_End_Sheet") = 4
	End If



'----- Sets the appened Revision Number text-----	
	If oRevNum = "REL" Then
		oRevString = " (" & oRevNum & ")"
		Else
		oRevString = " (REV " & oRevNum & ")"
	End If

'	MessageBox.Show("This is the rev Number:" & oRevString, "Title")


'-----Set the PDF target file name-----
	oDataMedium.FileName = oPDFFolder & "\" & oFileName & oRevString & ".pdf"


'-----Publish User selected formats -----
	If UserSelectedAction = 1 Then
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		'Export DXF
		oDocument.SaveAs(oDXFFolder & "\" & oFileName & oRevString & ".dxf", True)
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFileName & oRevString & ".dwg", True)		
	End If
	
	If UserSelectedAction = 2 Then
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFileName & oRevString & ".dwg", True)
	End If
	
	If UserSelectedAction = 3 Then
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	End If
	
	If UserSelectedAction = 4 Then
		'Export DXF
		oDocument.SaveAs(oDXFFolder & "\" & oFileName & oRevString & ".dxf", True)
	End If
	
	If UserSelectedAction = 5 Then
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFileName & oRevString & ".dwg", True)	
	End If
	
	
'-----Successful complete message-----
	If UserSelectedAction = 1 Then
		MessageBox.Show("File successfully exported to PDF, DXF & DWG", "Export Complete")
	End If

	If UserSelectedAction = 2 Then
		MessageBox.Show("File successfully exported to PDF & DWG", "Export Complete")
	End If
		
	If UserSelectedAction = 3 Then
		MessageBox.Show("File successfully exported to PDF", "Export Complete")
	End If

	If UserSelectedAction = 4 Then
		MessageBox.Show("File successfully exported to DXF", "Export Complete")
	End If
	
	If UserSelectedAction = 5 Then
		MessageBox.Show("File successfully exported to DWG", "Export Complete")
	End If


End Sub

 

0 Likes
Accepted solutions (3)
1,144 Views
7 Replies
Replies (7)
Message 2 of 8

Zach.Stauffer
Advocate
Advocate

I would try to separate the different actions you're doing into their own subroutines/functions. This allows you to more easily expand, reuse, and fix bugs in your code. I've attached an example using some of what you are doing, it should be relatively self explanatory. The important bit about searching for each document is in the ExportAllOpenDrawings subroutine.

 

Sub Main
    'your other code to get user choice etc.
    Dim userChoice = InputRadioBox("What files do you want to export", "Only This Open Document", "All Open Documents", True, Title := "Defined the scope")
    Dim UserSelectedActionList = New String(){"Sheet Metal - PDF, DXF & DWG", "Machined Part - PDF & DWG", "PDF Only", "DXF Only", "DWG Only"}
	Dim UserSelectedAction As String = InputListBox("What Format is Required ?", UserSelectedActionList, UserSelectedActionList(0), Title := "File Type to Export", ListName := "File Format Type")

    if userChoice = True then       'userChoice will be true if first option selected.
        ExportCurrentDrawing(UserSelectedAction)
    Else
        ExportAllOpenDrawings(UserSelectedAction)
    End if

End Sub

Sub ExportCurrentDrawing(string UserSelectedOption)
    Dim currentDocument = ThisApplication.ActiveDocument
    Select Case UserSelectedOption
        Case "Sheet Metal - PDF, DXF & DWG"
            PrintPDF(currentDocument)
            PrintDWG(currentDocument)
            PrintDXF(currentDocument)
            MessageBox.Show("File successfully exported to PDF, DXF & DWG", "Export Complete")
        Case "Machined Part - PDF & DWG"
            PrintPDF(currentDocument)
            PrintDWG(currentDocument)
            MessageBox.Show("File successfully exported to PDF & DWG", "Export Complete")
    End Select
End Sub

Sub ExportAllOpenDrawings(string UserSelectedOption)
    For Each openDocument As Document In ThisApplication.Documents.VisibleDocuments
        if openDocument.DocumentType = kDrawingDocumentObject then
            Select Case UserSelectedOption
                Case "Sheet Metal - PDF, DXF & DWG"
                    PrintPDF(openDocument)
                    PrintDWG(openDocument)
                    PrintDXF(openDocument)
                    MessageBox.Show("File successfully exported to PDF, DXF & DWG", "Export Complete")
                Case "Machined Part - PDF & DWG"
                    PrintPDF(openDocument)
                    PrintDWG(openDocument)
                    MessageBox.Show("File successfully exported to PDF & DWG", "Export Complete")
            End Select
        End if
    Next
End Sub

Sub PrintPDF(Document printDoc)
    'do pdf print things here
End Sub

Sub PrintDWG(Document printDoc)
    'do dwg print things here
End Sub

Sub PrintDXF(Document printDoc)
    'do dxf print things here
End Sub

 

Message 3 of 8

omatthewsZA8PL
Participant
Participant

Thanks @Zach.Stauffer the subroutines really neaten things up and the For loop works really well, however in the ExportAllOpenDrawings subroutine I am struggling to pass the different file names and revisions of each open document to the Sub PrintPDF 

 

My code keeps pulling the active documents info, (the document containing the rule) and applying it to all the files. 

 

Any suggestions on how to make the loop get the iproperties from each file to populate my naming convention ?

 

"Part number" "Description" "Revision Number" .PDF

 

Thanks 

 

 

0 Likes
Message 4 of 8

omatthewsZA8PL
Participant
Participant
Accepted solution

Sorry forgot to add my code, 

so far I have gotten the code working to output either a single file or all open drawing files, in any of the chosen formats from the user selected list. I just cant get any of the iProperty values to be updated for each file in the loop ? It only reads the iproperty value of the active document (file the rule has been run from) not the other files in the loop. 

 

Anyone know how to fix this ?

 

This is my code so far,

 

Sub Main ()
'-----Inital User Input -----
	'-----User defined Scope-----
	Dim UserChoice = InputRadioBox("What files do you want to export", "Only This Open Document", "All Open Documents", True, Title := "Defined the scope")
	
	'-----User question setup -----
	Dim UserSelectedActionList = New String(){"Sheet Metal - PDF, DXF & DWG", "Machined Part - PDF & DWG", "PDF Only", "DXF Only", "DWG Only"}
	'-----User question input -----
	Dim UserSelectedAction As String = InputListBox("What Format is Required ?", UserSelectedActionList, UserSelectedActionList(0), Title := "File Type to Export", ListName := "File Format Type")

	If UserChoice = True Then	'UserChoice will be True is first option is selected
		oDoc = ThisApplication.ActiveDocument
		Call ExportFile(oDoc, UserSelectedAction)
		'----- Single File Success Message-----
		Select Case UserSelectedAction
			Case "Sheet Metal - PDF, DXF & DWG"
				MessageBox.Show(" File successfully exported to PDF, DXF & DWG ", "Export Complete")
			Case "Machined Part - PDF & DWG"
				MessageBox.Show(" File successfully exported to PDF & DWG ", "Export Complete")
			Case "PDF Only"
				MessageBox.Show(" File successfully exported to PDF ", "Export Complete")	
			Case "DXF Only"
				MessageBox.Show(" File successfully exported to DXF ", "Export Complete")
			Case "DWG Only"
				MessageBox.Show(" File successfully exported to DWG ", "Export Complete")
		End Select
		
		Else
			
			For Each openDocument As Document In ThisApplication.Documents.VisibleDocuments
				If openDocument.DocumentType = kDrawingDocumentObject Then
					Try
						If Len(openDocument.File.FullFileName) >0 Then
							Call ExportFile(openDocument, UserSelectedAction)
						End If
					Catch
					End Try
				End If
			Next
		'----- Multi File Success Message -----
		Select Case UserSelectedAction
			Case "Sheet Metal - PDF, DXF & DWG"
				MessageBox.Show(" All files successfully exported to PDF, DXF & DWG ", "Export Complete")
			Case "Machined Part - PDF & DWG"
				MessageBox.Show(" All files successfully exported to PDF & DWG ", "Export Complete")
			Case "PDF Only"
				MessageBox.Show(" All files successfully exported to PDF ", "Export Complete")	
			Case "DXF Only"
				MessageBox.Show(" All files successfully exported to DXF ", "Export Complete")
			Case "DWG Only"
				MessageBox.Show(" All files successfully exported to DWG ", "Export Complete")
		End Select

	End If


End Sub


Sub ExportFile(ByRef oDocument As Document, UserSelectedOption As String)	
'-----Check path----- 
	oPath = ThisDoc.Path 

'-----Get Target folder paths-----
	oPDFFolder = Left(oPath, InStrRev(oPath, "\")) & "3. PDFs"
	oDXFFolder = Left(oPath, InStrRev(oPath, "\")) & "4. DXFs"
	oDWGFolder = Left(oPath, InStrRev(oPath, "\")) & "5. DWGs"

'-----Check for the folder paths and create it if they do not exist-----
	If Not System.IO.Directory.Exists(oPDFFolder) Then
	System.IO.Directory.CreateDirectory(oPDFFolder)
	End If

	If Not System.IO.Directory.Exists(oDXFFolder) Then
	System.IO.Directory.CreateDirectory(oDXFFolder)
	End If
	
	If Not System.IO.Directory.Exists(oDWGFolder) Then
	System.IO.Directory.CreateDirectory(oDWGFolder)
	End If

'----- Fill Variables -----
	
	oFullFileName = oDocument.File.FullFileName  
	oPath = Left(oFullFileName, InStrRev(oFullFileName, "\") -1)
	oFileName = Right(oFullFileName, Len(oFullFileName) -InStrRev(oFullFileName, "\"))
	oFilePart = Left(oFileName, InStrRev(oFileName, ".") -1)
	
	oPartNumber = iProperties.Value(oDocument,"Project", "Part Number")
	oDescription = iProperties.Value(oDocument,"Project", "Description")
	oRevNum = iProperties.Value(oDocument,"Project", "Revision Number")
	
'----- Debug Message -----
'	MessageBox.Show("File Name: " & oFilePart _ 
'	& vbLf & "Part Number: " & oPartNumber _ 
'	& vbLf & "Description: " & oDescription _ 
'	& vbLf & "Rev Number: " & oRevNum _
'	& vbLf & "variable: " & oProp, "Debug")
'-------------------------

'-----Load PDF Add In-----
	oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	'oDocument = ThisApplication.ActiveDocument
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'-----PDF options -----
	If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
		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
	End If

'----- Sets the appened Revision Number text-----	
	If oRevNum = "REL" Then
		oRevString = " (" & oRevNum & ")"
		Else
		oRevString = " (REV " & oRevNum & ")"
	End If

'-----Set the PDF target file name-----
	oDataMedium.FileName = oPDFFolder & "\" & oFilePart & oRevString & ".pdf"
	
'-----Export User Selection-----
	Select Case UserSelectedOption
	Case "Sheet Metal - PDF, DXF & DWG"
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		'Export DXF
		oDocument.SaveAs(oDXFFolder & "\" & oFilePart & oRevString & ".dxf", True)
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFilePart & oRevString & ".dwg", True)
	
	Case "Machined Part - PDF & DWG"
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFilePart & oRevString & ".dwg", True)
		
	Case "PDF Only"
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		
	Case "DXF Only"
		'Export DXF
		oDocument.SaveAs(oDXFFolder & "\" & oFilePart & oRevString & ".dxf", True)
	
	Case "DWG Only"
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFilePart & oRevString & ".dwg", True)
		
	End Select


End Sub

 

 

0 Likes
Message 5 of 8

A.Acheson
Mentor
Mentor
Accepted solution

You will need to replace the ilogic snippets with the API equivalent Property sets.

oPartNumber = iProperties.Value(oDocument,"Project", "Part Number")

The ilogic snippets will not work for visible documents collection. Here is an article on API PropertySets. You can either use the snippets alone or set them up as a function to return a value. 

https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 oPartNumber = oDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 8

omatthewsZA8PL
Participant
Participant

Thanks @A.Acheson , that was exactly what I needed. 

0 Likes
Message 7 of 8

A.Acheson
Mentor
Mentor

Glad you got it working. Don't forget @Zach.Stauffer did the heavy lifting contribution in the post. I would accept that workflow as one of the answers. If possible post back in the rule that does work and accept that also. As it is now someone might end up using the rule with ilogic snippets and end up scratching their head. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 8 of 8

omatthewsZA8PL
Participant
Participant
Accepted solution

Thanks for everyone's help with this rule, finally got it working.

 

Anyone looking to use it will also need to account for the fact that it pulls the iProp values from the drawing sheet itself not the model, I have another rule that runs on a trigger when a drawing is saved to copy the models iProps to the drawings iProps.

 

There is probably a way of combining these two rules, to update the drawing before it exports but I don't have a good enough understanding to implement it. 

 

Thanks again for everyone's help 

Happy Exporting. 

 

Sub Main ()
'-----Inital User Input -----
	'-----User defined Scope-----
	Dim UserChoice = InputRadioBox("What files do you want to export", "Only This Open Document", "All Open Documents", True, Title := "Defined the scope")
	
	'-----User question setup -----
	Dim UserSelectedActionList = New String(){"Sheet Metal - PDF, DXF & DWG", "Machined Part - PDF & DWG", "PDF Only", "DXF Only", "DWG Only"}
	'-----User question input -----
	Dim UserSelectedAction As String = InputListBox("What Format is Required ?", UserSelectedActionList, UserSelectedActionList(0), Title := "File Type to Export", ListName := "File Format Type")

	If UserChoice = True Then	'UserChoice will be True is first option is selected
		oDoc = ThisApplication.ActiveDocument
		Call ExportFile(oDoc, UserSelectedAction)
		'----- Single File Success Message-----
		Select Case UserSelectedAction
			Case "Sheet Metal - PDF, DXF & DWG"
				MessageBox.Show(" File successfully exported to PDF, DXF & DWG. ", "Export Complete")
			Case "Machined Part - PDF & DWG"
				MessageBox.Show(" File successfully exported to PDF & DWG. ", "Export Complete")
			Case "PDF Only"
				MessageBox.Show(" File successfully exported to PDF. ", "Export Complete")	
			Case "DXF Only"
				MessageBox.Show(" File successfully exported to DXF. ", "Export Complete")
			Case "DWG Only"
				MessageBox.Show(" File successfully exported to DWG. ", "Export Complete")
		End Select
		
		Else
			
			For Each openDocument As Document In ThisApplication.Documents.VisibleDocuments
				If openDocument.DocumentType = kDrawingDocumentObject Then
					Try
						If Len(openDocument.File.FullFileName) >0 Then
							Call ExportFile(openDocument, UserSelectedAction)
						End If
					Catch
					End Try
				End If
			Next
		'----- Multi File Success Message -----
		Select Case UserSelectedAction
			Case "Sheet Metal - PDF, DXF & DWG"
				MessageBox.Show(" All files successfully exported to PDF, DXF & DWG. ", "Export Complete")
			Case "Machined Part - PDF & DWG"
				MessageBox.Show(" All files successfully exported to PDF & DWG. ", "Export Complete")
			Case "PDF Only"
				MessageBox.Show(" All files successfully exported to PDF. ", "Export Complete")	
			Case "DXF Only"
				MessageBox.Show(" All files successfully exported to DXF. ", "Export Complete")
			Case "DWG Only"
				MessageBox.Show(" All files successfully exported to DWG. ", "Export Complete")
		End Select

	End If


End Sub


Sub ExportFile(ByRef oDocument As Document, UserSelectedOption As String)	
'-----Check path----- 
	oPath = ThisDoc.Path 

'-----Get Target folder paths-----
	oPDFFolder = Left(oPath, InStrRev(oPath, "\")) & "3. PDFs"
	oDXFFolder = Left(oPath, InStrRev(oPath, "\")) & "4. DXFs"
	oDWGFolder = Left(oPath, InStrRev(oPath, "\")) & "5. DWGs"

'-----Check for the folder paths and create it if they do not exist-----
	If Not System.IO.Directory.Exists(oPDFFolder) Then
	System.IO.Directory.CreateDirectory(oPDFFolder)
	End If

	If Not System.IO.Directory.Exists(oDXFFolder) Then
	System.IO.Directory.CreateDirectory(oDXFFolder)
	End If
	
	If Not System.IO.Directory.Exists(oDWGFolder) Then
	System.IO.Directory.CreateDirectory(oDWGFolder)
	End If

'----- Fill Variables -----
	
	oFullFileName = oDocument.File.FullFileName  
	oPath = Left(oFullFileName, InStrRev(oFullFileName, "\") -1)
	oFileName = Right(oFullFileName, Len(oFullFileName) -InStrRev(oFullFileName, "\"))
	oFilePart = Left(oFileName, InStrRev(oFileName, ".") -1)
	
'----- get the partnumber, Description & Rev Number from iprops ------

	'oPartNumber = iProperties.Value(oDocument,"Project", "Part Number")
	'oDescription = iProperties.Value(oDocument,"Project", "Description")
	'oRevNum = iProperties.Value(oDocument,"Project", "Revision Number")
	
	' Get the PropertySets object.
    Dim oPropSets As PropertySets
    oPropSets = oDocument.PropertySets

    ' Get the design tracking property set.
    Dim oPropSet As PropertySet
    oPropSet = oPropSets.Item("Design Tracking Properties")

    ' Get the part number iProperty.
    Dim oPartNumiProp 'As Property
    oPartNumiProp = oPropSet.Item("Part Number")
	
	'Get the description
	Dim oDescriptioniProp
	oDescriptioniProp = oPropSet.Item("Description")
	
	'Get the Rev Number
	oPropSet = oPropSets.Item("Inventor Summary Information")
	Dim oRevNumiProp
	oRevNumiProp = oPropSet.Item("Revision Number")
	
    'MessageBox.Show("iProp Part Number: "& oPartNumiProp.Value, "Title")
	
'----- Debug Message -----
'	MessageBox.Show("File Name: " & oFilePart _ 
'	& vbLf & "Part Number: " & oPartNumiProp.Value _ 
'	& vbLf & "Description: " & oDescription.Value _ 
'	& vbLf & "Rev Number: " & oRevNum.Value _
'	& vbLf & "variable: " & oProp, "Debug")
'-------------------------

'-----Load PDF Add In-----
	oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	'oDocument = ThisApplication.ActiveDocument
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'-----PDF options -----
	If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
		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
	End If

'----- Sets the appened Revision Number text-----	
	If oRevNumiProp.Value = "REL" Then
		oRevString = " (" & oRevNumiProp.Value & ")"
		Else
		oRevString = " (REV " & oRevNumiProp.Value & ")"
	End If

'-----Set the PDF target file name-----
	oDataMedium.FileName = oPDFFolder & "\" & oFilePart & oRevString & ".pdf"
	
'-----Export User Selection-----
	Select Case UserSelectedOption
	Case "Sheet Metal - PDF, DXF & DWG"
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		'Export DXF
		oDocument.SaveAs(oDXFFolder & "\" & oFilePart & oRevString & ".dxf", True)
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFilePart & oRevString & ".dwg", True)
	
	Case "Machined Part - PDF & DWG"
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFilePart & oRevString & ".dwg", True)
		
	Case "PDF Only"
		'Export PDF
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
		
	Case "DXF Only"
		'Export DXF
		oDocument.SaveAs(oDXFFolder & "\" & oFilePart & oRevString & ".dxf", True)
	
	Case "DWG Only"
		'Export DWG
		oDocument.SaveAs(oDWGFolder & "\" & oFilePart & oRevString & ".dwg", True)
		
	End Select


End Sub

 

 

This is the additional code that has been setup to run on a trigger when a drawing is saved. 

It reads the modelled part iProps and copy's them to the drawing. 

 

I put this together from reading this post by @chandra.shekar.g :

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/copy-model-iproperty-settings-with-i... 

 

'--- EXISTING DRAWINGS UPDATE THE IPROPS------
oRefDoc = ThisDrawing.ModelDocument
Dim oPropValue As String 

'Description
	oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Description").Value 
	iProperties.Value("Project", "Description") = oPropValue

'Designer
	oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Designer").Value 
	iProperties.Value("Project", "Designer") = oPropValue

'Engineer
	oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Engineer").Value 
	iProperties.Value("Project", "Engineer") = oPropValue

'Part Number
	oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value 
	iProperties.Value("Project", "Part Number") = oPropValue

'Project
	oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Project").Value 
	iProperties.Value("Project", "Project") = oPropValue

'Revision Number
	oPropValue = oRefDoc.PropertySets("Summary Information").Item("Revision Number").Value 
	iProperties.Value("Summary", "Revision Number") = oPropValue

'Stock Number
	oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Stock Number").Value 
	iProperties.Value("Project", "Stock Number") = oPropValue
	
'--- MODERN TEMPLATE IPROPS UPDATE ----
Dim oControlDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
oControlDef.Execute2(True)

 

0 Likes