Home ▼
T h u r s d a y, F e b r u a r y 2 4 , 2 0 1 1
iLogic Code for Parts Lists, Title Blocks and Saving out a PDF
Here is a snippet of iLogic code that does a short list of common tasks for drawing files:
Sorts the parts list by Part Number
Exports the Parts List to an XLS file
Sets the Drawn By and Date fields of a titleblock (via the drawing's iProperties)
Saves a copy of the drawing as a PDF file, with some of the PDF options set
This code also contains some error checks to alert the user when the PDF or XLS already exist and can't be
replaced (such as when another user has these files open).
You can just paste the code into a new rule in your drawing file to see it in action. I use this as an external rule,
and bring it into existing drawings when they are edited or updated, and also have it included in our drawing
template so that all new drawings include it. Having it as an external rule, allows me to add more functions as
needed, and to update the code (and all of the files it's included in) quickly.
I use this code daily to manage our drawing files and output a PDF and XLS file for our document management
and ERP system and have found it to work well. I've set it up to be triggered on the Save event, so that as the
user saves the drawing file, the PDF and XLS are updated or output automatically. Feel free to tear this apart
and customize it to fit your needs and/or set it up to run when your drawing is closed rather than saved, etc.
On a related note, I just finished a new chapter dealing exclusively with iLogic for the next edition of Mastering
Autodesk Inventor book (due out in June of 2011 if all goes well).
oPartsList1.Sort("PART NUMBER")
'oPartsList1.Renumber
'oPartsList1.SaveItemOverridesToBOM
'------------------------------------------------------------------------------------------------------------
'Export Parts List
path_and_name = ThisDoc.PathAndFileName(False) ' without extension
Dim oDoc As Inventor.DrawingDocument
oDoc = ThisDoc.Document
'--------------------------------------------------------------------------------------------------------------------
'set Drawn by name
iProperties.Value("Summary", "Author" ) = ThisApplication.GeneralOptions.UserName
'set date
iProperties.Value("Project", "Creation Date" ) = Now
InventorVb.DocumentUpdate()
'--------------------------------------------------------------------------------------------------------------------
'Save PDF with options
path_and_namePDF = ThisDoc.PathAndFileName(False) ' without extension
PDFAddIn = 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
'--------------------------------------------------------------------------------------------------------------------
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
If you need to sort a parts list by multiple columns you can use something like this:
This results in the parts list sorting first by the DESCRIPTION column and then the QTY column in ascending
order. You can use 0 for the sort Boolean to sort by descending order. For example:
Look for more iLogic examples on this blog or in the chapter dedicated to iLogic Basics in the next edition of
Mastering Autodesk Inventor book (due out in June of 2011 if all goes well).
You can find an example of setting the Parts List export options at this link.
Share
‹ Home ›
View web version
About Me
Curtis Waguespack
I've used Inventor daily, “in the trenches” of a real world design environment. I've also used AutoCAD and
Inventor to design a wide range of manufactured products in the past. In addition to this real world experience
I’ve written and co written multiple editions of the Mastering Autodesk Inventor series and have taught Inventor
to professionals in the classroom. I hope to share some of the useful tips and tricks I've learned in the past and stumble
across in the future on this blog.
View my complete profile
Powered by Blogger.