Get iProperty from file being exported

Get iProperty from file being exported

Chris_TPR
Contributor Contributor
401 Views
2 Replies
Message 1 of 3

Get iProperty from file being exported

Chris_TPR
Contributor
Contributor

G'day,

 

I have an export PDF and DXF Rule that I have taken from someone else (on here, I think - it was a while ago). I have slightly modified it to add the "Revision Number" iProperties value to the end of the exported filename.

 

My problem is that when I use the "All open documents" selection, it obtains the REV number value for the active file in the window, and not the value of the specific file being exported. I cannot for the life of me work out what command is required to correct this.

 

I have a rule taken from Clint Brown's website for exporting DXF flat patterns for all sheet metal parts in an assembly, and I have successfully modified it to add the rev number to these files.. But this particular rule has aluded me. Extensive searching and even asking ChatGPT for help has returned no solutions. Haha! Any help would be appreciated.

 

Sub Main()
  Dim myDate As String = Now().ToString("yyyy-MM-dd HHmmss")
  myDate = myDate.Replace(":","")  ' & " - " & TypeString
 userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 UserSelectedActionList = New String(){"DXF & PDF", "PDF Only", "DXF Only"}
  UserSelectedAction = InputListBox("What action must be performed with selected views?", _
          UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options")
      Select UserSelectedAction
   Case "DXF & PDF": UserSelectedAction = 3
   Case "PDF Only": UserSelectedAction = 1
   Case "DXF Only":    UserSelectedAction = 2
   End Select
 If userChoice Then
   Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate, UserSelectedAction)
   Else
    For Each oDoc In ThisApplication.Documents
    If oDoc.DocumentType = kDrawingDocumentObject
     Try
      If Len(oDoc.File.FullFileName)>0 Then
        Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction)
       End If
       Catch
      End Try
     End If
    Next
   End If
 End Sub
 Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer)
 ' oPath = oDocument.Path
 ' oFileName = oDocument.FileName(False) 'without extension
  'oDocument = ThisApplication.ActiveDocument
  oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
  ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
  oContext = ThisApplication.TransientObjects.CreateTranslationContext
  oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  oOptions = ThisApplication.TransientObjects.CreateNameValueMap
  oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
 oFullFileName = oDocument.File.FullFileName
  oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1)
  oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\"))
  oFilePart = Left(oFileName, InStrRev(oFileName, ".")-1)
 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number")
  'oDocument = ThisApplication.ActiveDocument
 ' If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
  oOptions.Value("All_Color_AS_Black") = 0
  oOptions.Value("Remove_Line_Weights") = 0
  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
 'get PDF target folder path
  'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"
  oFolder = oPath & "\iLogic PDF's (" & DateString & ")"
 'Check for the PDF folder and create it if it does not exist
  If Not System.IO.Directory.Exists(oFolder) Then
   System.IO.Directory.CreateDirectory(oFolder)
  End If
 'Set the PDF target file name
  oDataMedium.FileName = oFolder & "\" & oFilePart & "_" & iProperties.Value(oDocument, "Project", "Revision Number") & ".pdf"
 'Publish document
  If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then
   oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's
  End If
  If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then
   oDocument.SaveAs(oFolder & "\" & oFilePart & "_" & iProperties.Value(oDocument,"Project", "Revision Number") & ".dxf", True) 'For DXF's
  End If
  'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".dxf"), True) 'For DXF's
  '------end of iLogic-------
 End Sub

 

0 Likes
Accepted solutions (1)
402 Views
2 Replies
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @Chris_TPR . Try this code:

Sub Main()
	Dim myDate As String = Now().ToString("yyyy-MM-dd HHmmss")
	myDate = myDate.Replace(":","")  ' & " - " & TypeString
	userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
	UserSelectedActionList = New String(){"DXF & PDF", "PDF Only", "DXF Only"}
	UserSelectedAction = InputListBox("What action must be performed with selected views?", _
	UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options")
	Select UserSelectedAction
	Case "DXF & PDF": UserSelectedAction = 3
	Case "PDF Only": UserSelectedAction = 1
	Case "DXF Only":    UserSelectedAction = 2
	End Select
	If userChoice Then
		Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate, UserSelectedAction)
	Else
		For Each oDoc In ThisApplication.Documents
			If oDoc.DocumentType = kDrawingDocumentObject
				Try
					If Len(oDoc.File.FullFileName)>0 Then
						Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction)
					End If
				Catch
				End Try
			End If
		Next
	End If
End Sub

Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer)
	oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
	oFullFileName = oDocument.File.FullFileName
	oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1)
	oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\"))
	oFilePart = Left(oFileName, InStrRev(oFileName, ".")-1)
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	oFolder = oPath & "\iLogic PDF's (" & DateString & ")"
	Dim sRevNumb As String = oDocument.PropertySets("Design Tracking Properties")("Part Number").Value
	If Not System.IO.Directory.Exists(oFolder) Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If
	oDataMedium.FileName = oFolder & "\" & oFilePart & "_" & sRevNumb & ".pdf"
	If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	End If
	If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then
		oDocument.SaveAs(oFolder & "\" & oFilePart & "_" & sRevNumb & ".dxf", True)
	End If
 End Sub

 Line 44 receives the Part Number of a specific document.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 3

Chris_TPR
Contributor
Contributor

G'day Andrii,

 

Thanks for the reply. This successfully pulled the property from the correct file, but obviously not the right property.

 

I adjusted Line 44 to:

 

Dim sRevNumb As String = oDocument.PropertySets("Inventor Summary Information")("Revision Number").Value

Your code gave me the insight to know what to look for, and I used the link below to determine the correct string:

 

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

 

Much appreciated. My rule now works as intended!