Getting model iProperties from referenced models in drawing

Getting model iProperties from referenced models in drawing

Anonymous
Not applicable
494 Views
4 Replies
Message 1 of 5

Getting model iProperties from referenced models in drawing

Anonymous
Not applicable

Hello everyone.

 

I am using a code from Inventortrenches to save a pdf of each sheet in my drawing file. The drawing contains an assembly and each sheet represents a subpart.

 

My problem is that I want each pdf to be named after the partnumber of the referenced model on each sheet, and I am unable to figure out how.

 

The code I am currently using can be found here:

 

http://inventortrenches.blogspot.dk/2011/07/ilogic-to-save-pdf-files-to-new.html

 

Thank you - Dave

0 Likes
495 Views
4 Replies
Replies (4)
Message 2 of 5

bretrick30
Advocate
Advocate

I just modified the code that was in that link you mentioned.

 

This will save each sheet as a separate PDF as the part number of the file on the sheet in the same folder as the Inventor drawing is saved.

 

SyntaxEditor Code Snippet

'------start of iLogic-------
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
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

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos -1)
'find the sheet number
iSheetNumber = Right(oSheet.Name, sLen -lPos)

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"

'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

Dim PNum As String

Try
PNum = oSheet.DrawingViews.Item(1).ReferencedFile.DisplayName
Catch
PNum = ""
End Try

If PNum <> "" Then
'Set the PDF target file name
oDataMedium.FileName = oPath & "\" & PNum & ".pdf"

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

Next
'------end of iLogic-------
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for the modified rule, however this rule only provides me PDFs named after the sheets and not the referenced models part numbers.

 

I managed to modify some rules myself and get the desired result. Now I am trying to figure out a way to choose which sheets the save as pdfs.

 

Here is the code i am currently using:

 

SyntaxEditor Code Snippet

'------start Of iLogic-------
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
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

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos -1)
'find the sheet number
iSheetNumber = Right(oSheet.Name, sLen -lPos)

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"

'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

modelDoc = oSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
prtNumber = modelDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value





'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & prtNumber  & ".pdf"

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Next
'------end of iLogic------
0 Likes
Message 4 of 5

bretrick30
Advocate
Advocate

This part below is the part I modified in the code.  It is grabbing the part number of the part on the current sheet and creating a pdf.

 

I put a try and catch in there just in case you have a sheet that doesnt have a view on it, it will just skip over that sheet.

 

Try
PNum = oSheet.DrawingViews.Item(1).ReferencedFile.DisplayName
Catch
PNum = ""
End Try

If PNum <> "" Then
'Set the PDF target file name
oDataMedium.FileName = oPath & "\" & PNum & ".pdf"

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If
0 Likes
Message 5 of 5

GosponZ
Collaborator
Collaborator

i'm using this one for long time. Copy paste path of folder where pdf need to be.

response = MessageBox.Show("Did you change path in this rule?", "Reminder",MessageBoxButtons.YesNo)
If response = vbNo Then Exit Sub

 
'Save PDF with options
'SaveLoc = "C:\"
'FileName = ThisDoc.FileName(True)
'ThisDoc.Document.SaveAs(FileName & (".pdf") , True)
oPath = ThisDoc.Path
PN = iProperties.Value("Project", "Part Number")


'path_and_namePDF = ThisDoc.Pathandname(False)
oFileName = ThisDoc.FileName(False) 'without extension
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




If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
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") = 4
End If



'Set the destination file name 
oPath = "C:\TEST\"
oPath = InputBox("Replace Path","New Path")
 
oDataMedium.FileName = oPath & "\" & PN & ".pdf"
'Publish document 
 'Confirmation message
 MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)
 


On Error Goto handlePDFLock
'Publish document.
Call oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)


'--------------------------------------------------------------------------------------------------------------------


Exit Sub


handlePDFLock: 
MessageBox.Show("PDF could not be saved, most likely someone else has it open", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next


handleXLSLock: 
MessageBox.Show("No XLS", "iLogic")
Resume Next


 Good Luck

0 Likes