iLogic Code for single sheet pdf creation

iLogic Code for single sheet pdf creation

Anonymous
Not applicable
1,533 Views
8 Replies
Message 1 of 9

iLogic Code for single sheet pdf creation

Anonymous
Not applicable

Hi all, I am new to iLogic having an issue getting my pdf creator to work. So far I have two, one that creates all drawing sheets in one pdf. This works great.

The other single drawing pdf creator works, but doesn't keep the correct part number.

 

Say I have an assembly drawing, A570abcd, and 11 more sheet drawings that are the parts, A510EFGH, A510IJKL etc. that make up the the entire assembly.

What I want to do with my code is create only A510EFGH and have the pdf named correctly. Currently it only names it A570abcd.

 

I want to know how to get my code to read the part number of the model on the active sheet.

 

Below is one of the many code iterations I've tried:

 

 '------start of iLogic-------
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
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") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentsheet
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If 


'get PDF target folder path
oFolder = opath


'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 & "\" & oFileName & ".pdf" 


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------end of iLogic-------

 I know the line - oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf" - is the issue. I just can't figure out how to read the iProperties part number of the part on the drawing.

 

Thanks,

Van

 

 

0 Likes
Accepted solutions (1)
1,534 Views
8 Replies
Replies (8)
Message 2 of 9

skyngu
Collaborator
Collaborator

modify the line:

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 1099 StartFragment: 314 EndFragment: 1067 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

oFileName=iProperties.Value("Project", "Part Number")

the code you provided works fine on my company inventor 2014 sp2

Autodesk Inventor Professional 2019
0 Likes
Message 3 of 9

GosponZ
Collaborator
Collaborator

Try this

'Set PDF target folder path

oFolder = "C:\

'Set the PDF target file name

oDataMedium.FileName = oFolder&"\"&oFileName&" "&sSheetName&" "&sSheetNumber&".pdf"

0 Likes
Message 4 of 9

GosponZ
Collaborator
Collaborator

Ok here is complete code and save separate pdf's.

For your need add or remove part of code what is after part number.

Also change path.

 

 

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

DimoDrawingAsDrawingDocument

oDrawing = ThisDoc.Document

 

 

DimoSheetAsSheet

DimlPosAsLong

DimrPosAsLong

DimsLenAsLong

DimsSheetNameAsString

DimsSheetNumberAsInteger

 

 

'step through each drawing sheet

ForEachoSheetInoDrawing.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

sSheetNumber = Right(oSheet.Name, sLen-lPos)

 

 

'set PDF Options

IfoPDFAddIn.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") = sSheetNumber

oOptions.Value("Custom_End_Sheet") = sSheetNumber

EndIf

 

 

'get PDF target folder path

'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"

oFolder = "C:\"

 

'Check for the PDF folder and create it if it does not exist

IfNotSystem.IO.Directory.Exists(oFolder)Then

   System.IO.Directory.CreateDirectory(oFolder)

EndIf

 

 

'Set the PDF target file name

oDataMedium.FileName = oFolder&"\"&oFileName&" "&sSheetName&" "&sSheetNumber&".pdf"

 

 

'Publish document

oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

 

 

Next

 

Message 5 of 9

Anonymous
Not applicable

While this works well & creates all of the pdfs, it doesn't only create the active sheet I'm looking at.


Also, for the target name I'm looking for something like this;
oDataMedium.FileName = oFolder & "\" & sSheetName & ".pdf"

 

But "SheetName" isn't autofed from the iproperties of the part.

 

The attached picture of my drawing tree shows the breakdown of part drawings on sheets.

A57xxxxx is my top level assembly

--A51xxxxx are the parts making that assembly

 

The issue is the iProperties of this drawing file are only fed from the  A57xxxxx model and not the individual piece parts.

0 Likes
Message 6 of 9

Anonymous
Not applicable
Would I be able to drive my sheet names from the parts I place on each drawing? If there is a way to make a form for that, I believe that'd be the a really good route to take.
0 Likes
Message 7 of 9

GosponZ
Collaborator
Collaborator
Accepted solution

Trigger this rule before save doc

You can remove Authority value if you do not need. or add what you want .Your browser tree will have this values and after you run pdf rule every sheet got own number  and description

oDoc=ThisDoc.Document
oSheets=oDoc.Sheets
ForEachoSheetInoSheets
oSheet.activate
oView=oSheet.DrawingViews.Item(1)
modelName=oView.ReferencedDocumentDescriptor.ReferencedDocument
oProp=modelName.PropertySets.Item("Design Tracking Properties")
ActiveSheet.Sheet.Name=oProp.Item("Part Number").Value&""&oProp.Item("Description").Value&""&oProp.Item("Authority").Value

Next
oSheets(1).activate

0 Likes
Message 8 of 9

Anonymous
Not applicable

@MisterZS wrote:

Trigger this rule before save doc

You can remove Authority value if you do not need. or add what you want .Your browser tree will have this values and after you run pdf rule every sheet got own number  and description

oDoc=ThisDoc.Document
oSheets=oDoc.Sheets
ForEachoSheetInoSheets
oSheet.activate
oView=oSheet.DrawingViews.Item(1)
modelName=oView.ReferencedDocumentDescriptor.ReferencedDocument
oProp=modelName.PropertySets.Item("Design Tracking Properties")
ActiveSheet.Sheet.Name=oProp.Item("Part Number").Value&""&oProp.Item("Description").Value&""&oProp.Item("Authority").Value

Next
oSheets(1).activate


This is exactly what i was looking for! Thanks MisterZS.

0 Likes
Message 9 of 9

GosponZ
Collaborator
Collaborator

I'm glad if i can share. Smiley Wink

0 Likes