Thursday, January 19, 2012

Set Your Drawing View Labels to Use the Model Part Number

Issue:
You'd prefer your view labels to use the model part number (or some other file property) rather than the default "View1", "View2", and so on. Re-naming the view labels manually is tedious and error prone. 



Solution:
You can change the view label default to use an iProperty from the model using these steps:
  • Open a drawing file
  • Go to the Manage tab
  • Click the Styles and Standards button
  • Click the Standard to work with from the top of the tree on the left pane
  • Activate the View Preferences tab in the right pane
  • Click the Edit button for Display field
  • Set the Type drop down to Properties-Model
  • Set the Properties drop down to Part Number (or something else)
  • Click the Add Text Parameter button to add this property to your view label

You can click the image below to enlarge it and see the picks and clicks.

Click to Enlarge



Here is a bit of iLogic Code to set the view name and browser node to the model part number also:


'start of ilogic code
Dim oApp As Application: oApp = ThisApplication
Dim oDoc As DrawingDocument:  oDoc = oApp.ActiveDocument

Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
                For Each oView In oViews
                oModelName = _
                oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
                oPartNumber = iProperties.Value(oModelName, "Project", "Part Number")
            oView.Name = oPartNumber
                Next
Next
'end of ilogic code



Update:
By request here is a rule that adds a custom iProperty to the view label with a dash separator.



'start of ilogic code
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document

Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
                For Each oView In oViews
                'capture the current view label
                ViewLabel = oView.Name
                oModelName = _
                oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
                Try
            o_iProp = iProperties.Value(oModelName, "Custom", "My_iProp")        
            'add the the iProperty to the current view label, with a dash separator
                oView.Name = ViewLabel & " - " & o_iProp
            Catch
            'do nothing if error
                End Try
            Next
Next

'end of ilogic code


Thursday, January 5, 2012

Creating a Basic iLogic Rule with an Event Trigger



Issue:
You've found some iLogic code online, but you're not sure how to create a simple rule or have it trigger on a save event. You've found the iLogic tutorials on line, but don't have the time to go through them right now. You really just want to know how to create a simple rule and get it working.

Solution:
Here are some basics to get you going, using some simple example code to update the creation date and author iProperties, as described at this link.

Here is the iLogic Code you'll use:

'set Author iproperty to match the system user name
iProperties.Value("Summary", "Author" ) = ThisApplication.GeneralOptions.UserName
'set the Creattion Date iproperty to the current date
iProperties.Value("Project", "Creation Date" ) = Now
'update the file
iLogicVb.UpdateWhenDone = True



To use this code first create an iLogic Rule:
  1. On the ribbon, click Manage tab > iLogic panel > Add Rule button.
  2. Name the new rule Name-Date.
  3. In the rule text area of the Edit Rule dialog box, simply paste in the code from above.
  4. Click OK to save this new rule.
Next you need to have a couple of text fields that read the iProperties (you'd likely create these text objects in your title block, but for now just create some simple text on your drawing to test this first).
  1. On the ribbon, click Annotate tab > Text panel > Text button.
  2. Click on screen to place the text
  3. In the Format Text dialog box select the Type pull down and choose Properties - Model from the list.
  4. Then select the Property pull down and choose Creation Date from the list.
  5. Then click the Add Text Parameter button (looks like and X with an arrow) to "push" the field to the text box.  
  6. Click OK to create the text.
  7. Repeat these steps for the Author iProperty
Next set the rule to trigger when the file is saved.
  1. On the ribbon, click Manage tab > iLogic panel > Event Triggers button. A dialog box displays the list of available events.
  2. Click the Before Save Document event in the list.
  3. Click Select Rules, or right-click and choose Select Rules from the context menu.
  4. Place a check mark next to the Name-Date rule.
  5. Click OK.
  6. Click OK to close the event list.
Now whenever this file is saved the date and name text fields are updated.
 
Note:
You might also be interested in this post from the guys at the Being Inventive blog:
http://beinginventive.typepad.com/being-inventive/2011/07/plot-date-stamp-in-title-block.html

And this article from Paul Munford:
http://www.augi.com/library/playing-by-the-ilogic-rules 


And this article from Steve Bedder:
http://autodeskmfg.typepad.com/blog/2012/01/working-with-external-ilogic-rules.html

 

Wednesday, January 4, 2012

Autodesk Inventor iLogic: Sort Browser, Collapse Browser, Return Home, and Zoom All



Issue:
You wish that you had a way to automatically do the following list of general house keeping chores for your assembly files:
  • sort the browser tree in descending order so that part numbers are easier to index and find
  • collapse any browser nodes that have been left expanded in the browser tree
  • return the view to the Home view
  • zoom all
Solution:
Here is an iLogic rule to do these things. You can set this rule up to run anytime a file is closed using the iLogic event triggers.


'-----start of ilogic-----
'sort components in the browser
ThisApplication.CommandManager.ControlDefinitions.Item _
("AssemblyBonusTools_AlphaSortComponentsCmd").Execute

'set a reference to the document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode

For Each oNode In oTopNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = True Then
oNode.Expanded = False
End If
Next

'Return view to Home view
ThisApplication.CommandManager.ControlDefinitions.Item _
("AppViewCubeHomeCmd").Execute

'zoom all
ThisApplication.ActiveView.Fit
'-----end of ilogic-----





****Edit****


I originally had:

'Return view to Home view
ThisApplication.CommandManager.ControlDefinitions.Item _
("AppForceIsoCmd").Execute



which works in older versions, but I have amended it as follows, based on some feedback from "prachu" on the Inventor forums.

'Return view to Home view
ThisApplication.CommandManager.ControlDefinitions.Item _
("AppViewCubeHomeCmd").Execute


you can also use:


'Return view to Home view
ThisApplication.CommandManager.ControlDefinitions.Item _
("AppIsometricViewCmd").Execute