Ilogic Center and Arrange dimensions but exclude dimensions under an angle

Ilogic Center and Arrange dimensions but exclude dimensions under an angle

Charlies_3D_T
Advocate Advocate
1,560 Views
10 Replies
Message 1 of 11

Ilogic Center and Arrange dimensions but exclude dimensions under an angle

Charlies_3D_T
Advocate
Advocate

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. 

0 Likes
1,561 Views
10 Replies
Replies (10)
Message 2 of 11

Charlies_3D_T
Advocate
Advocate

@MjDeck  Can i ask if you could help me?

 

If not possible i maybe can change the color of the dimension and filter my center and arrange rule on the color of the dimension. But im also not succesfull in fixing this. Could you help me out on this one? 

0 Likes
Message 3 of 11

MjDeck
Autodesk
Autodesk

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.

0 Likes
Message 4 of 11

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

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

0 Likes
Message 5 of 11

MjDeck
Autodesk
Autodesk

@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.

0 Likes
Message 6 of 11

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

Hello i did a test. If i have existing dimensions it's not working but when i place new then its working. This is strange i think... 

0 Likes
Message 7 of 11

Charlies_3D_T
Advocate
Advocate

@MjDeck 

 

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
0 Likes
Message 8 of 11

MjDeck
Autodesk
Autodesk

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.

0 Likes
Message 9 of 11

MjDeck
Autodesk
Autodesk

Do you have the Center dimension text... option selected in the Drawings tab of the Tools > Application Options dialog:
Center dimension text.png


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 10 of 11

Charlies_3D_T
Advocate
Advocate

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? 

0 Likes
Message 11 of 11

MjDeck
Autodesk
Autodesk

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.

0 Likes