Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Select all dimensions and arrange

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
DanWood113
6250 Views, 15 Replies

iLogic Select all dimensions and arrange

Hi Guys,

 

I am trying to create a semi automated drawing from an ever changing assembly. 

 

My VB and iLogic knowledge prior to this was zero, but thanks to a lot of help from you guys in these forums I have something which kind of works!

 

What im trying to do now is use a piece of code to select all dimensions in the drawing and then run the Arrange command. When i do it this way manually it does what i want it to, however when i try and do it within iLogic with the code below (sorry if it messy/stupid!), it runs the command but I still have to manually select the dimensions.

 

Any help would be much appreciated!

 

Dan

 

Sub Main ()
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oDrawingDims As DrawingDimension
For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions
Next
ThisApplication.CommandManager.ControlDefinitions.Item("DrawingArrangeDimensionsCmd").Execute
End Sub
15 REPLIES 15
Message 2 of 16
danvang
in reply to: DanWood113

Here's the code that I use and it seems to work. Hope this works for you.

 

Dan

 

''-------

' Set a reference to the active drawing document
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Get the collection of dimensions on the active sheet.
Dim oDimensions As DrawingDimensions
oDimensions = oDrawDoc.ActiveSheet.DrawingDimensions

Dim oDrawDim As DrawingDimension

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

' 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.
For Each oDrawDim In oDimensions
    oSelectSet.Select(oDrawDim)   
Next

' Get the CommandManager object.
Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager

' Get control definition for the arrange dimensions command.
Dim oControlDef As ControlDefinition
 oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingArrangeDimensionsCmd")

' Execute the command.
Call oControlDef.Execute

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 3 of 16
DanWood113
in reply to: danvang

Dan,

 

Works a treat, Thanks very much!

Message 4 of 16
RodrigoEiras
in reply to: danvang

Hi danvang,

 

Your post was really helpful. I have rewritten your code, and I think it is a little less complex now.

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 7723 StartFragment: 314 EndFragment: 7691 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

'Centre and arrange dimensions


    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument

    ' 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 Or TypeOf oDrawingDim Is AngularGeneralDimension Then
           oDrawingDim.CenterText

           oDimsToBeArranged.Add(oDrawingDim)

        End If
    Next

    
    oDrawingDimensions.Arrange(oDimsToBeArranged)

 Thanks for showing the right path!

 

 

Message 5 of 16
mlkuselan
in reply to: RodrigoEiras

Hi i also need to arrange the dimension created using Api through Api 

\I went through your code and applied it

 but i am getting error in selectset.select 

the error is it does not support this property  when i am using command option

 

 

when i am using the other option of adding dimension in objectcollection a arranging using arrange method of drawingdimensions

i am getting the below error 

compiler error

Argument not optional 

 

 

 

so anyone olease help me to get rid of this eror

 

 

 

 

 

Message 6 of 16
RodrigoEiras
in reply to: mlkuselan

 

I think I would need more detailed information about the error and the code you are using to try to help you. Are you sure you are adding only "arrangeable" dimensions to the set?

 

Regarding SelectSet I have also got errors in Drawing environment. A work around is to use DoSelect, although in this case you cannot multiselect.

Message 7 of 16
mlkuselan
in reply to: RodrigoEiras

first i created the dimension in runtime by using code by vba

then i tried for arranging it using code in vba

i copied your code in this post and tried to arrange the dimension by using vba

 there i am getting error but the code is working fine i ILOGIC but getting error in vba

the code is

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 Or TypeOf oDrawingDim Is AngularGeneralDimension Then
           oDrawingDim.CenterText

           oDimsToBeArranged.Add(oDrawingDim)

        End If
    Next

    
    oDrawingDimensions.Arrange(oDimsToBeArranged)
in the line
oDrawingDimensions.Arrange(oDimsToBeArranged)
at the place of parameter that is oDimsToBeArranged i am getting compiler error  argument not optional
Can u please help me in getting rid of this issue
But before that line if i am testing is the dimensions added to the object collection using msgbox ya it is working for the count property it is displaying 2(the dimensions i created using my code)
 
so please help me

 

Message 8 of 16
RodrigoEiras
in reply to: mlkuselan

 

 

I am not so familiar with VBA, but have you tried: 

 

Call oDrawingDimensions.Arrange(oDimsToBeArranged) 

 

Message 9 of 16
mlkuselan
in reply to: RodrigoEiras

Yes we changed the code and its working fine.

 

Thanks for your support.

Message 10 of 16
RodrigoEiras
in reply to: mlkuselan

 

I am happy it worked!

 

Remeber giving a Kudos or Accept As Solution is a good way to say thank you Smiley Wink

Message 11 of 16
insomnix
in reply to: DanWood113

The iLogic code works great. I modified it slightly so I could call it as a function by sheet. However, the arrange function creates more space between the dimension and the part than I like. Is there a way to control the spacing of the dimensions?

 

 

image.png

 

Private Sub DimensionUpdates(oSheet As Sheet)
    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 Or TypeOf oDrawingDim Is AngularGeneralDimension Then
           oDrawingDim.CenterText
           oDimsToBeArranged.Add(oDrawingDim)
        End If
    Next

    oDrawingDimensions.Arrange(oDimsToBeArranged)
End Sub
Message 12 of 16
RodrigoEiras
in reply to: insomnix

 

Have you tried with the parameter in the Styles Editor?

 

Although sometimes it is related to the size of the view and for that I have no solution.

 

 

Capture.JPG

Tags (2)
Message 13 of 16
insomnix
in reply to: RodrigoEiras

Well that was simple... 🙂

 

I guess I was so focused on iLogic code that the styles editor never occurred to me. Thanks for the help.

Message 14 of 16

Hello,

 

I use your code. But i use a lot of Ordinate Set dimensions in my drawings. And when i use the code they get deleted. Do you know how i can keep these? 

 

Thank you!

Message 15 of 16

Hi Charlies_3D_T,

 

I am not familiar with the ordinate sets, but maybe you can use the property "IsOrdinateSetMember" to identify these dimensions and to avoid including them in the selection set. Something like this:

 

 

For Each oDrawingDim In oDrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or TypeOf oDrawingDim Is AngularGeneralDimension Then
           oDrawingDim.CenterText
           If oDrawingDim.IsOrdinateSetMember = False Then 
               oDimsToBeArranged.Add(oDrawingDim)
End if
End If Next

I hope it helps,

 

Best regards

 

 

Message 16 of 16
pl.sivakumar
in reply to: mlkuselan

Can Possible to share the vb code?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report