Looking For an auto arrange dimensions macro

I'm looking for a macro that will grab all dimension and use Auto arrange.

Ive found the below two snip its of code, is it as simple as take the line from one and replace the center dimension line?

from I've got this line

status = swModelDocExt.AlignDimensions(swAlignDimensionType_e.swAlignDimensionType_AutoArrange, 0.001)

and the select all dims from this post  

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swDispDim As SldWorks.DisplayDimension
Dim swView As SldWorks.View
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swDwg = swDoc
Set swView = swDwg.GetFirstView
While Not swView Is Nothing
Set swDispDim = swView.GetFirstDisplayDimension5
While Not swDispDim Is Nothing
swDispDim.CenterText = True

insert my line here? status = swModelDocExt.AlignDimensions(swAlignDimensionType_e.swAlignDimensionType_AutoArrange, 0.001)
Set swDispDim = swDispDim.GetNext5
Wend
Set swView = swView.GetNextView
Wend

End Sub

Thanks for your time!

SolidworksApi/macros
Answers 4
FR
FR 2021-04-09 Best Answer

Hello, try this:

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swDispDim As SldWorks.DisplayDimension
Dim swView As SldWorks.View
Dim swAnn As SldWorks.Annotation
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDwg = swModel
swModel.ClearSelection2 True
Set swView = swDwg.GetFirstView
While Not swView Is Nothing
Set swDispDim = swView.GetFirstDisplayDimension5
While Not swDispDim Is Nothing
Set swAnn = swDispDim.GetAnnotation
boolstatus = swAnn.Select3(True, Nothing)
Set swDispDim = swDispDim.GetNext5
Wend
boolstatus = swModel.Extension.AlignDimensions(swAlignDimensionType_e.swAlignDimensionType_AutoArrange, 0.001)
Set swView = swView.GetNextView
Wend
swModel.ClearSelection2 True
End Sub

JP
JP 2021-04-09

Thanks again Fifi!

FR
FR 2021-04-09

I think the Auto Arrange function moves the dimensions at the edge of the view. That's why the 3/16" moves away.

JP
JP 2021-04-09

That worked pretty darn well! As is that's a vast improvement, there is one dim that actually moved further away and I suspect that's a limitation of the Auto Arrange feature not the macro. Am I correct?

Before

and after

And I see that the code wasn't as simple as I thought, no cut and paste haha.

comment imagecomment imagecomment imagecomment image