Referencing a custom iProperty from a drawing.

Referencing a custom iProperty from a drawing.

Anonymous
Not applicable
475 Views
3 Replies
Message 1 of 4

Referencing a custom iProperty from a drawing.

Anonymous
Not applicable

Hi, I am trying to create a ribbon button on a drawing to export the drawing as a PDF to a location and name the PDF as a custom iproperty that is contained in the part file.

 

My code right now pulls the iproperty from the drawing called "Part Number".  I want it to pull a custom iproperty from the part called "Item Code".

 

Here's my code which is almost complete:

 

DrawingName = iProperties.Value("Project", "Part Number")
DesiredPath = "C:\JACKRABBIT\INVENTOR TEMPLATES 2022\MISC\PDF"

NewFileName = DesiredPath & "\" & DrawingName & ".pdf"


'check file name to see if it is used
	'if it is, ask the user to overwrite
	'if it's not, save the file

question = MessageBox.Show("Is this a good file name?:  " & DrawingName & ".pdf", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If question=vbYes Then

	If System.IO.File.Exists(NewFileName) Then
	
		question = MessageBox.Show("File exists, do you want to overwrite?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	
			If question = vbYes Then 
				System.IO.File.Delete(NewFileName)
				ThisDoc.Document.SaveAs(NewFileName, True)
			Else If question =vbNo Then
				MessageBox.Show("File was not overwritten", "iLogic Message")
			End If
	
	Else 
		
		ThisDoc.Document.SaveAs(NewFileName, True)
		
	End If 

Else If question=vbNo Then
	MessageBox.Show("Please fix Part Number")
End If

 

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

bhavik4244
Collaborator
Collaborator

@Anonymous 

 

This code can solve your issue.

 

Sub Main
DrawingName = iProperties.Value("Custom", "Item Code")

DesiredPath = "C:\JACKRABBIT\INVENTOR TEMPLATES 2022\MISC\PDF"

NewFileName = DesiredPath & "\" & DrawingName & ".pdf"

question = MessageBox.Show("Is this a good file name?:  " & DrawingName & ".pdf", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If question=vbYes Then

	If System.IO.File.Exists(NewFileName) Then
	
		question = MessageBox.Show("File exists, do you want to overwrite?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	
			If question = vbYes Then 
				System.IO.File.Delete(NewFileName)
'				ThisDoc.Document.SaveAs(NewFileName, True)
				Call export_PDF
			Else If question =vbNo Then
				MessageBox.Show("File was not overwritten", "iLogic Message")
				Call export_PDF
			End If
	
	Else 
		
		Call export_PDF
		
	End If 

Else If question=vbNo Then
	MessageBox.Show("Please fix Part Number")
End If

End Sub


Function export_PDF()
    ' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
         PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    Dim oDocument As Document    ' a reference to the active document (the document to be published).
         oDocument = ThisApplication.ActiveDocument
    Dim cdoc As Inventor.Document
         cdoc = ThisApplication.ActiveDocument
	DrawingName = iProperties.Value("Custom", "Description")
	
    Dim Fname As String
        Fname = cdoc.FullFileName
    Dim Name As String
        'name = Left(Fname, Len(Fname) - 4) & "\PDF" & ".pdf"
        Name = DrawingName & ".pdf"
    Dim oContext As TranslationContext
         oContext = ThisApplication.TransientObjects.CreateTranslationContext
        oContext.Type = kFileBrowseIOMechanism
    Dim oOptions As NameValueMap ' Create a NameValueMap object
         oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    Dim oDataMedium As DataMedium ' Create a DataMedium object
         oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then ' Check whether the translator has 'SaveCopyAs' options
	
MessageBox.Show(Name, "Title")

    ' Options for drawings...
        oOptions.Value("All_Color_AS_Black") = 0
        'oOptions.Value("Remove_Line_Weights") = 0
        oOptions.Value("Vector_Resolution") = 1200
        oOptions.Value("Sheet_Range") = kPrintAllSheets
        'oOptions.Value("Custom_Begin_Sheet") = 2
        'oOptions.Value("Custom_End_Sheet") = 4
    End If
    oDataMedium.FileName = Name '& "\" & "PDF" & "\" ' the destination file name"
    'Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
    
End Function

Bhavik Suthar
0 Likes
Message 3 of 4

Anonymous
Not applicable
DrawingName = iProperties.Value("Custom", "Item Code")

This line of code refers to the custom iproperty 'Item Code' within the drawing, but I need the custom iproperty 'Item Code'  that is in the part file.

0 Likes
Message 4 of 4

bhavik4244
Collaborator
Collaborator
Accepted solution

@Anonymous 

 

Here you go 🙂

 

Sub Main

docname = ThisDoc.FileName(False) 'without extension

oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

ItemNumber = iProperties.Value(oModelDoc, "Custom", "Item Code")

MessageBox.Show(ItemNumber, "Item Code")

DesiredPath = "C:\JACKRABBIT\INVENTOR TEMPLATES 2022\MISC\PDF"

NewFileName = DesiredPath & "\" & DrawingName & ".pdf"

question = MessageBox.Show("Is this a good file name?:  " & DrawingName & ".pdf", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

If question=vbYes Then

	If System.IO.File.Exists(NewFileName) Then
	
		question = MessageBox.Show("File exists, do you want to overwrite?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	
			If question = vbYes Then 
				System.IO.File.Delete(NewFileName)
'				ThisDoc.Document.SaveAs(NewFileName, True)
				Call export_PDF
			Else If question =vbNo Then
				MessageBox.Show("File was not overwritten", "iLogic Message")
				Call export_PDF
			End If
	
	Else 
		
		Call export_PDF
		
	End If 

Else If question=vbNo Then
	MessageBox.Show("Please fix Part Number")
End If

End Sub


Function export_PDF()
    ' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
         PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    Dim oDocument As Document    ' a reference to the active document (the document to be published).
         oDocument = ThisApplication.ActiveDocument
    Dim cdoc As Inventor.Document
         cdoc = ThisApplication.ActiveDocument

docname = ThisDoc.FileName(False) 'without extension

oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

ItemNumber = iProperties.Value(oModelDoc, "Custom", "Item Code")
	
    Dim Fname As String
        Fname = cdoc.FullFileName
    Dim Name As String
        'name = Left(Fname, Len(Fname) - 4) & "\PDF" & ".pdf"
        Name = ItemNumber & ".pdf"
    Dim oContext As TranslationContext
         oContext = ThisApplication.TransientObjects.CreateTranslationContext
        oContext.Type = kFileBrowseIOMechanism
    Dim oOptions As NameValueMap ' Create a NameValueMap object
         oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    Dim oDataMedium As DataMedium ' Create a DataMedium object
         oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then ' Check whether the translator has 'SaveCopyAs' options
	
MessageBox.Show(Name, "Title")

    ' Options for drawings...
        oOptions.Value("All_Color_AS_Black") = 0
        'oOptions.Value("Remove_Line_Weights") = 0
        oOptions.Value("Vector_Resolution") = 1200
        oOptions.Value("Sheet_Range") = kPrintAllSheets
        'oOptions.Value("Custom_Begin_Sheet") = 2
        'oOptions.Value("Custom_End_Sheet") = 4
    End If
    oDataMedium.FileName = Name '& "\" & "PDF" & "\" ' the destination file name"
    'Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
    
End Function

 


Bhavik Suthar
0 Likes