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
Solved! Go to Solution.
Solved by danvang. Go to Solution.
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
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!
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
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.
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
I am not so familiar with VBA, but have you tried:
Call oDrawingDimensions.Arrange(oDimsToBeArranged)
I am happy it worked!
Remeber giving a Kudos or Accept As Solution is a good way to say thank you
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?
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
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.
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!
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