Center and align dimensions

Center and align dimensions

ch_giacomo
Enthusiast Enthusiast
1,078 Views
4 Replies
Message 1 of 5

Center and align dimensions

ch_giacomo
Enthusiast
Enthusiast

Hello everyone, I have a little problem with this rule.
the rule itself works well to align and center the dimensions.

I did some tweaking to get the result but I have very little coding knowledge.

I would like to implement an InputRadioBox that allows me to choose between:
- Center
-Align
-Center and align.

I managed to do all of this by splitting into 3 different rules.

Thank you

'ZOOM IN
ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute


'--------------------------------------------------------------------------------------------------------------------	
'Center Dimension Code
'--------------------------------------------------------------------------------------------------------------------	

    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument

    ' a reference to the active sheet & dimension
    Dim oSheet As Sheet 
    oSheet = oDoc.ActiveSheet
    Dim oDrawingDim As DrawingDimension

    ' Iterate over all dimensions in the drawing and center them if they are linear or angular.
    For Each oDrawingDim In oSheet.DrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
            Call oDrawingDim.CenterText 'x1
            Call oDrawingDim.CenterText 'x2
        End If
    Next


'--------------------------------------------------------------------------------------------------------------------
'Arrange Dimension Code
'--------------------------------------------------------------------------------------------------------------------

 		'Get the active document, assuming it Is a drawing.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

 	   ' Get the collection of dimensions on the active sheet.
    Dim oDimensions As DrawingDimensions
    oDimensions = oDrawDoc.ActiveSheet.DrawingDimensions
	
	    ' Get a reference to the select set and clear it.
    Dim oSelectSet As SelectSet
    oSelectSet = oDrawDoc.SelectSet
    oSelectSet.Clear

  	  ' Add each dimension to the select set to select them.
    Dim oDrawDim As DrawingDimension
    For Each oDrawDim In oDimensions
        oSelectSet.Select(oDrawDim)
    Next
    	
	Call ThisApplication.CommandManager.ControlDefinitions.Item("DrawingArrangeDimensionsCmd").Execute
0 Likes
Accepted solutions (1)
1,079 Views
4 Replies
Replies (4)
Message 2 of 5

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @ch_giacomo . I hope this is what you wanted. Please try if this code works as you wanted.

Sub main
	Dim oDoc As Document = ThisApplication.ActiveDocument
	Dim oTM As TransactionManager = ThisApplication.TransactionManager
	If TypeOf oDoc Is DrawingDocument Then
		Dim oDDoc As DrawingDocument = oDoc
		ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomallCmd").Execute
		Dim bCenter As Boolean = True
		Dim bAlign As Boolean = True
		Dim dlgResult As DialogResult = MessageBox.Show("Do you want center and align dimensions?", "Center and align dimensions", _
														MessageBoxButtons.YesNo, MessageBoxIcon.Question)
		If dlgResult.ToString = "No" Then
			If InputRadioBox("What do you want to do with the dimensions?", "Center", "Align", True, "Center or align.") Then
				bAlign = False
			Else
				bCenter = False
			End If
		End If
		Dim oSheet As Sheet = oDoc.ActiveSheet
		Dim oDrawingDim As DrawingDimension 
		Dim oSelectSet As SelectSet = oDDoc.SelectSet
	    oSelectSet.Clear()
		Dim newTM As Transaction = oTM.StartTransaction(oDDoc, "CenterAndAlignDimensions")
		If bCenter Then
		    For Each oDrawingDim In oSheet.DrawingDimensions
		        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
		            Call oDrawingDim.CenterText
		        End If
		    Next
		End If
		If bAlign Then
		    For Each oDrawingDim In oSheet.DrawingDimensions
		        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
					oSelectSet.Select(oDrawingDim)
		        End If
		    Next
		End If
		Call ThisApplication.CommandManager.ControlDefinitions.Item("DrawingArrangeDimensionsCmd").Execute
		oSelectSet.Clear()
		newTM.End()
	End If		
End Sub

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 5

ch_giacomo
Enthusiast
Enthusiast

Thank you very much, I will try this Monday morning at the office.

There are many changes to the code and I thank you for taking the time.

0 Likes
Message 4 of 5

ch_giacomo
Enthusiast
Enthusiast

Exactly what I had thought.

Thank you for the time you have taken and I hope that this rule can help other people's work.

Message 5 of 5

kerem.izmirli
Contributor
Contributor

Hi @Andrii_Humeniuk, excellent code works great, I was just wondering if it's possible to modify this code to centre and align only the dimensions selected. Either prompt to select dimensions after running the rule, or select the dimensions first and then run the rule perhaps. Thank you in advance! 

0 Likes