iLogic to change dimension style of certain dimensions

iLogic to change dimension style of certain dimensions

dcopher
Contributor Contributor
5,908 Views
8 Replies
Message 1 of 9

iLogic to change dimension style of certain dimensions

dcopher
Contributor
Contributor

I have what I think is a relatively easy request, but I am new to iLogic and VB, so I haven't had much luck doing what I would like to do.  We use architectural dimensions on most of our assemblies.  I have two different dimension styles in my IDW's, one for all general dimensions, then another style to use on dimensions that are under one inch.  This style suppresses the leading zeros so that I do not get dimensions that read somethling like 0 7/8", instead reading correctly as just 7/8".  I would like a piece of code that looks at all dimensions in my IDW and changes the style to the correct one for any dimensions less than one inch.  Any body have any insight into this or might be able to point me in the right direction.

 

 

Thanks,

 

Dave Copher

Inventor 2015
Intel 2600K @ 4.7 GHz
16 GB Ram
Quadro 4000
160GB Intel SSD
600 GB Velociraptor
0 Likes
Accepted solutions (1)
5,909 Views
8 Replies
Replies (8)
Message 2 of 9

Vladimir.Ananyev
Alumni
Alumni

Style property of the GeneralDimension object allows you to get and set the dimension style used for this dimension.  

The following iLogic sample changes the style in the first dimension on the active sheet. 

New style is referenced by its name.

 

'change dimension style

'drawing document
Dim oDrawDoc As DrawingDocument = ThisDoc.Document
'active sheet
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'reference to the first dimension
Dim oDim As GeneralDimension = oSheet.DrawingDimensions.Item(1)
'the current dimension style object
Dim oStyle As DimensionStyle = oDim.Style

'reference to the style manager
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager

'get the reference to another dimension style
Dim oNewStyle As DimensionStyle _
	= oStylesMgr.DimensionStyles.Item("Default - Method 2a (DIN)")
'change the style
oDim.Style = oNewStyle

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 9

dcopher
Contributor
Contributor

Vladimir,

 

Thank you for the reply, but I am a little confused.  Maybe I did not state my problem very well.  Is there a way to look at dimensions, say any dimensions less than 1", and automatically change them to a different style?  Your piece of code does not appear to address this issue.

 

 

Thank you,

 

Dave Copher

Inventor 2015
Intel 2600K @ 4.7 GHz
16 GB Ram
Quadro 4000
160GB Intel SSD
600 GB Velociraptor
0 Likes
Message 4 of 9

Vladimir.Ananyev
Alumni
Alumni

Hi Dave,

The following iLogic rule checks the dimension value and if this value is less than the specified threshold changes the dimension style.

'change dim style for all dims less than specified value Threshold
Dim Threshold As Double = 2.54 ' value in cm - Inventor database length units

'drawing document
Dim oDrawDoc As DrawingDocument = ThisDoc.Document
'active sheet
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'reference to the style manager
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager    

'get the reference to the target dimension style (by name)
Dim oNewStyle As DimensionStyle _
	= oStylesMgr.DimensionStyles.Item("Default - Method 2a (DIN)")

'reference to the dimension collection
Dim oDims As DrawingDimensions = oSheet.DrawingDimensions    
'replace style if dim value is less than Threshold
For Each oDim As GeneralDimension In oDims
    If oDim.ModelValue < Threshold Then
        oDim.Style = oNewStyle
    End If
Next

 You may set event triggers to run this rule based on specific events that occur in Inventor drawing document.  Look here for more information:

http://help.autodesk.com/view/INVNTOR/2015/ENU/?guid=GUID-A2B15007-7226-431F-BC14-CA080A1CE6C2


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 5 of 9

dcopher
Contributor
Contributor

Vladimir,

 

Thank you for the help so far.  I feel like an idiot, but I am still having trouble with this one.  I guess the main problem is I do not know iLogic very well at all.  I have copied and pasted this code into one of my drawings, but it does not appear to do anything.  I tried to add my information where needed, but it does not seem to work.  My standard dimension style is called "Architectural (ANSI)" and my secondary style is "Architectural (No Zeros)".  I am sure this is someting easy, but I am at a loss for what to do, plus I am so busy at work that I don't have much time to research this and try different things.  Can you take a look and let me know where I am messing up?

 

SyntaxEditor Code Snippet

'change dim style for all dims less than specified value Threshold
Dim Threshold As Double = 1 ' value in inches - Inventor database length units

'drawing document
Dim oDrawDoc As DrawingDocument = ThisDoc.Document
'active sheet
Dim oSheet As Sheet = oDrawDoc.ActiveSheet

'reference to the style manager
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager    

'get the reference to the target dimension style (by name)
Dim oNewStyle As DimensionStyle _
    = oStylesMgr.DimensionStyles.Item("Architectural (No Zeros)")

'reference to the dimension collection
Dim oDims As DrawingDimensions = oSheet.DrawingDimensions    
'replace style if dim value is less than Threshold
For Each oDim As GeneralDimension In oDims
    If oDim.ModelValue < Threshold Then
        oDim.Style = oNewStyle
    End If
Next
Inventor 2015
Intel 2600K @ 4.7 GHz
16 GB Ram
Quadro 4000
160GB Intel SSD
600 GB Velociraptor
0 Likes
Message 6 of 9

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

Hi Dave,

 

Your drawing sheet contains not only general dimensions but hole thread notes as well.

These notes are accessible via Sheet.DrawingNotes.HoleThreadNotes collection.

I’ve modified the rule to take into account both types.  In addition I added document type check that is useful if you plan to run this rule as the external rule.

Please note that Inventor API internal length unit is centimeter.

 

'external rule
 
'change dim style for all dims less than specified value Threshold
Dim Threshold As Double = 1 ' inch
'convert to centimeters - Inventor internal database length units
Threshold = Threshold * 2.54
 
If Not TypeOf ThisDoc.Document Is DrawingDocument Then
    MessageBox.Show("This rule is intended for drawing documents only.", _
        "Change Style", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
End If
 
'drawing document
Dim oDrawDoc As DrawingDocument = ThisDoc.Document
'active sheet
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
 
Dim n As Integer = 0  'counter
 
'reference to the style manager
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager
'get the reference to the target dimension style (by name)
Dim oNewStyle As DimensionStyle _
    = oStylesMgr.DimensionStyles.Item("Architectural (No Zeros)")
 
'transform general dimensions
Dim oDims As DrawingDimensions = oSheet.DrawingDimensions
For Each oDim As GeneralDimension In oDims
    'replace style if dim value is less than Threshold
    If oDim.ModelValue < Threshold Then
        oDim.Style = oNewStyle
        n += 1
    End If
Next
 
'transform Hole Thread Notes
Dim oThreadNote As HoleThreadNote
For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes
    If oThreadNote.ModelValue < Threshold Then
        'replace style if dim value is less than Threshold
        oThreadNote.Style = oNewStyle
        n += 1
    End If
Next
 
MessageBox.Show("Done" & vbNewLine & "Dimensions changed: " & n, _
    "Change Style", MessageBoxButtons.OK, MessageBoxIcon.Information)

The easiest way to discover Inventor objects is described by Adam Nagy in the following nice post

http://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html

 

 cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 9

Anonymous
Not applicable

Can someone help me adapt the code to select all dimensions?

0 Likes
Message 8 of 9

Vladimir.Ananyev
Alumni
Alumni

You may consider something like this:

Sub SelectDims()

    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oDims As DrawingDimensions
    Set oDims = oSheet.DrawingDimensions
    
    Dim sset As SelectSet
    Set sset = oDoc.SelectSet
    sset.Clear
    
    Dim oDim As GeneralDimension
    For Each oDim In oDims
        Call sset.Select(oDim)
    Next
End Sub

This code selects all general dimensions on the active sheet.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 9 of 9

Anonymous
Not applicable

Thank, but I am a bit confused on how to integrate your code (I am still new to ilogic). here is what I have so far:

 

'drawing document

Dim oDrawDoc As DrawingDocument = ThisDoc.Document

 

'active sheet

Dim oSheet As Sheet = oDrawDoc.ActiveSheet

Dim oDim As GeneralDimension = oSheet.DrawingDimensions.

Dim oStyle As DimensionStyle = oDim.Style

 

'reference to the style manager

Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager

 

'get the reference to the target dimension style (by name)

Dim oNewStyle As DimensionStyle _

= oStylesMgr.DimensionStyles.Item("Eclipse - mm [in]")

 

oDim.Style = oNewStyle

0 Likes