Simply sharing

Simply sharing

bferrell
Contributor Contributor
350 Views
2 Replies
Message 1 of 3

Simply sharing

bferrell
Contributor
Contributor

Greetings all,

 

I simply wanted to share some code with you in hopes that it might help you in some way.

It is derived from various sources here in this forum as well as in Google-land.

I am very new to iLogic, so this is in no way 'advanced' code and very little of it is 'original' coding on my part.

But in all the searching I had to do to get this far, I thought it only kind to share it with others.

 

The rule:

Save BOM To PDF

The parts list is exported to a pdf, formatted using a predetermined xls template and saved in the same folder as the idw.

It also comes with extra code to append the file name with the current Revision (if indeed there is one).

**Currently no error trap to check for the presence of a parts list**

 

Now, I know Inventor allows other ways to export to pdf, but our company really wanted to have the extra options, control and a 'one button solution' for this seemingly simple task.

The rule exists and can therefore be placed as a button on a form that controls all req'd information for out drawing title blocks.

(We no longer have to access iProperties dialog...ever...and that is wonderful lol)

 

Ok, I will shut up now 🙂

Here is the code - peace!

 

If dorev = 0 Then altName = ".pdf" Else altName = " (REV " & iProperties.Value("Project","Revision Number") & ")" & ".pdf"
pathfname = ThisDoc.PathAndFileName(False)
dorev = iProperties.Value("Project","Revision Number")
 If dorev = 0 Then altName = " BOM" Else altName = " BOM (REV " & iProperties.Value("Project","Revision Number") & ")"

Dim oDoc As Inventor.DrawingDocument
oDoc = ThisDoc.Document

Dim oSheet As Inventor.Sheet
'oSheet = oDoc.Sheets(1) ' first sheet
oSheet = oDoc.Sheets("1:1") ' sheet by name

' say there is a Partslist on the sheet.
Dim oPartslist As PartsList
oPartslist = oSheet.PartsLists(1)

' create a new NameValueMap object
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'specify an existing template file 
'to use For formatting colors, fonts, etc
oOptions.Value("Template") = "D:\Path to you're template file goes here\whatever\whenever\My BOM Template.xls"


'choose to autofit the column width in the xls file
oOptions.Value("AutoFitColumnWidth") = True

' export the Partslist to Excel.

' folderName = "C:\temp"
folderName = ThisDoc.Path
'oPartslist.Export(folderName & "\BOM.xls", PartsListFileFormatEnum.kMicrosoftExcel, oOptions)
oPartslist.Export(pathfname & altName, PartsListFileFormatEnum.kMicrosoftExcel, oOptions)

 

TBForm.PNG

 
351 Views
2 Replies
Replies (2)
Message 2 of 3

bferrell
Contributor
Contributor

One last thing:

I fully believe in giving credit where it is due.

Unfortunately, when you travel the world looking for code, you inevitably forget where you got it originally.

I apologize to the contributors who made this code possible.

 

My sincere thanks go to you (you likely know who you are) and if you recognize YOUR code in this, please let us know!

You are an invaluable asset to all of us noobs 🙂

 

Regards,

0 Likes
Message 3 of 3

bferrell
Contributor
Contributor

I found the origins of the above code along with other very helpful information on xls formatting.

 

http://inventortrenches.blogspot.co.uk/2011/06/ilogic-export-parts-list-with-options.html

 

Thank you Curtis Waguespack!
0 Likes