- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ilogic Center and Arrange dimensions but exclude dimensions under an angle
Hello,
I have following code for centering and arranging my dimensions.
Sub Main Dim oDoc As DrawingDocument oDoc = ThisDoc.Document ' Set a reference to the active sheet Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oDrawingDim As DrawingDimension Dim oDrawingDims As DrawingDimensions Dim oDimsToBeArranged As ObjectCollection ' Iterate over all dimensions in the drawing and ' center them if they are linear or angular. ' Add them to the ObjectCollection to be arranged oDrawingDimensions = oSheet.DrawingDimensions oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection For Each oDrawingDim In oDrawingDimensions If TypeOf oDrawingDim Is LinearGeneralDimension Then oDrawingDim.CenterText oDimsToBeArranged.Add(oDrawingDim) End If Next If oDimsToBeArranged.Count > 0 Then oDrawingDimensions.Arrange(oDimsToBeArranged) End If End Sub
I have 2 things i want to add:
1) i want to be able to center an ordinate set also?
2) i have some dimensions under an angle and i want to exclude these angles. Is this possible? (see picture)
Hope some of you can help me out with this one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @Charlies_3D_T , here's a version of your rule that will arrange only horizontal and vertical dimensions.
I'm not sure what you mean by "center an ordinate set". Can you provide some screenshots? Before and after would be helpful.
This rule will arrange ordinate dimensions that are not in a set.
Option Explicit On
Sub Main
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
' Set a reference to the active sheet
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oDrawingDim As DrawingDimension
Dim oDimsToBeArranged As ObjectCollection
'Dim oOrdinateDimsToBeArranged As ObjectCollection
' Iterate over all dimensions in the drawing and
' center them if they are linear or angular.
' Add them to the ObjectCollection to be arranged
Dim oDrawingDimensions = oSheet.DrawingDimensions
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oDrawingDim In oDrawingDimensions
If TypeOf oDrawingDim Is LinearGeneralDimension Then
oDrawingDim.CenterText
Dim oLinDim As LinearGeneralDimension = oDrawingDim
If oLinDim.DimensionType = DimensionTypeEnum.kHorizontalDimensionType Or oLinDim.DimensionType = DimensionTypeEnum.kVerticalDimensionType Then
If Not (oLinDim.IsBaselineSetMember Or oLinDim.IsChainSetMember) Then
oDimsToBeArranged.Add(oDrawingDim)
End If
End If
ElseIf TypeOf oDrawingDim Is OrdinateDimension Then
Dim ordDim As OrdinateDimension = oDrawingDim
If Not ordDim.IsOrdinateSetMember Then
oDimsToBeArranged.Add(oDrawingDim)
End If
End If
Next
If oDimsToBeArranged.Count > 0 Then
oDrawingDimensions.Arrange(oDimsToBeArranged)
End If
End Sub

Mike Deck
Software Developer
Autodesk, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you!
It's working perfect almost!
See pictures below.
1 is what it needs to be but 2 is what i get with your rule on horizontal and vertical dimensions...
This is the rule i had before:
Sub Main
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
' Set a reference to the active sheet
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oDrawingDim As DrawingDimension
Dim oDrawingDims As DrawingDimensions
Dim oDimsToBeArranged As ObjectCollection
' Iterate over all dimensions in the drawing and
' center them if they are linear or angular.
' Add them to the ObjectCollection to be arranged
oDrawingDimensions = oSheet.DrawingDimensions
oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection
For Each oDrawingDim In oDrawingDimensions
If TypeOf oDrawingDim Is LinearGeneralDimension Then
oDrawingDim.CenterText
oDimsToBeArranged.Add(oDrawingDim)
End If
Next
If oDimsToBeArranged.Count > 0 Then
oDrawingDimensions.Arrange(oDimsToBeArranged)
End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Charlies_3D_T , are you saying that your original rule worked better for this particular drawing? What happens if you run your original rule again?
I just did a test with a drawing that looks something like yours. I don't see dimensions arranged on top of each other (like the 1255 over 1005 that you show), but I also don't see an arrangement that is as good as what I can get with the Arrange command in the UI. Unfortunately, it looks like the API method is not as good as the UI command.

Mike Deck
Software Developer
Autodesk, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this rule inside an rule to add this to event triggers. But now i get a lot of errors. I'm missing something i think:
This is the full rule:
Sub Main Dim oDoc As DrawingDocument oDoc = ThisDoc.Document ' Set a reference to the active sheet Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oDrawingDim As DrawingDimension Dim oDrawingDims As DrawingDimensions 'Dim oDimsToBeArranged As ObjectCollection ' Iterate over all dimensions in the drawing and ' center them if they are linear or angular. ' Add them to the ObjectCollection to be arranged Dim oDrawingDimensions = oSheet.DrawingDimensions oDimsToBeArranged = ThisApplication.TransientObjects.CreateObjectCollection For Each oDrawingDim In oDrawingDimensions If TypeOf oDrawingDim Is LinearGeneralDimension Then oDrawingDim.CenterText Dim oLinDim As LinearGeneralDimension = oDrawingDim If oLinDim.DimensionType = DimensionTypeEnum.kHorizontalDimensionType Or oLinDim.DimensionType = DimensionTypeEnum.kVerticalDimensionType Then If Not (oLinDim.IsBaselineSetMember Or oLinDim.IsChainSetMember) Then oDimsToBeArranged.Add(oDrawingDim) End If End If ElseIf TypeOf oDrawingDim Is OrdinateDimension Then Dim ordDim As OrdinateDimension = oDrawingDim If Not ordDim.IsOrdinateSetMember Then oDimsToBeArranged.Add(oDrawingDim) End If End If Next If oDimsToBeArranged.Count > 0 Then oDrawingDimensions.Arrange(oDimsToBeArranged) End If Events End Sub Sub Events On Error Resume Next Dim EventPropSet As Inventor.PropertySet EventPropSet = GetiLogicEventPropSet(ThisApplication.ActiveDocument) ' To make sure that the document has an iLogic DocumentInterest, add a temporary rule Dim tempRule = iLogicVb.Automation.AddRule(ThisDoc.Document, "TemporaryRule_392856A2", "") EventPropSet.Add("file://Drawing - Center_and_Arrange_Dimensions", "BeforeDocSave", 701) iLogicVb.Automation.DeleteRule(ThisDoc.Document, tempRule.Name) 'After Open Document : AfterDocOpen : 400 'Close(Document) : DocClose : 500 'Before Save Document : BeforeDocSave : 700 'After Save Document : AfterDocSave : 800 'Any Model Parameter Change : AfterAnyParamChange : 1000 'Part Geometry Change** : PartBodyChanged : 1200 'Material Change** : AfterMaterialChange : 1400 'Drawing View Change*** : AfterDrawingViewsUpdate : 1500 'iProperty(Change) : AfterAnyiPropertyChange : 1600 'Feature Suppression Change** : AfterFeatureSuppressionChange : 2000 'Component Suppression Change* : AfterComponentSuppressionChange : 2200 'iPart / iAssembly Change Component* : AfterComponentReplace : 2400 'New Document : AfterDocNew : 2600 iLogicVb.UpdateWhenDone = True InventorVb.DocumentUpdate() End Sub Function GetiLogicEventPropSet(cDocument As Document) As Inventor.PropertySet On Error Resume Next iLogicEventPropSet = cDocument.PropertySets.Item("iLogicEventsRules") If iLogicEventPropSet Is Nothing Then iLogicEventPropSet = cDocument.PropertySets.Item("_iLogicEventsRules") End If If iLogicEventPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then Call iLogicEventPropSet.Delete iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") End If If iLogicEventPropSet Is Nothing Then iLogicEventPropSet = cDocument.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") End If If iLogicEventPropSet Is Nothing Then MsgBox ("Unable to create the Event Triggers property for this file!", , "Event Triggers Not Set") Err.Raise(1) Exit Function End If On Error GoTo 0 Return iLogicEventPropSet End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you want the rule to run on all drawings before save, I would recommend adding it in the Drawings tab in the Event Triggers dialog. If you do that, then you don't need to run a rule to add it to individual drawings.
But if the rule isn't working well, is it really a good idea to add it to an event trigger?
There is a way to run the UI command from a rule. Please look at this post:
https://clintbrown.co.uk/2020/07/11/ilogic-centre-arrange-dimensions/
The only problem with that is that the rule will only run on full Inventor. If you ever want to upload your model to the cloud and have your rule run on the cloud, then you will have to disable that rule.

Mike Deck
Software Developer
Autodesk, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Do you have the Center dimension text... option selected in the Drawings tab of the Tools > Application Options dialog:

Mike Deck
Software Developer
Autodesk, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes now i have. But on my system its not working fine the center and arrange.
Can you tell me if i can check if a dimension has a color and if it has that color i can proceed the code otherwise not? Is it just with the color command?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You can't check for the color directly on a dimension. The color is stored on either the Style or the Layer of the dimension. Do you want to use Style or Layer? I think Layer might be better, if you just want a different color and don't want to change anything else.

Mike Deck
Software Developer
Autodesk, Inc.