iLogic code to change selected dimensions to fractional

iLogic code to change selected dimensions to fractional

harvey_craig2RCUH
Advocate Advocate
187 Views
1 Reply
Message 1 of 2

iLogic code to change selected dimensions to fractional

harvey_craig2RCUH
Advocate
Advocate

I patched together an iLogic script to change selected dimensions on a drawing to fractional. It works sometimes, but occasionally it changes all of the drawing dimensions rather than the selected. I don't have a decent understanding on how styles work so if someone could point out the flaw in my script that would be great.

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Determine if there are any dimensions in the select set.
Dim oSelectSet As SelectSet
oSelectSet = oDrawDoc.SelectSet
Dim colDimensions As New Collection
Dim i As Long
For i = 1 To oSelectSet.Count
  If TypeOf oSelectSet.Item(i) Is DrawingDimension Then
     ' Add any dimensions to the collection. We need to save them
     ' in something besides the selection set because once we start
     ' manipulating them the select set will be cleared.
     colDimensions.Add(oSelectSet.Item(i))
  End If
Next

If colDimensions.Count < 1 Then
  MsgBox ("You must select at least 1 dimension for this operation.")
  Exit Sub
End If


Dim oDimension As DrawingDimension
Dim oDimStyle As DimensionStyle
For i = 1 To colDimensions.Count
	oDimension = colDimensions.Item(i)
	
	oDimStyle = oDimension.Style
	oDimStyle.LinearUnits = 11272
	oDimStyle.DisplayFormat = 78337
	oDimStyle.LinearPrecision = 41744
Next

 

Thanks,

Harvey

0 Likes
188 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @harvey_craig2RCUH.  Your code is essentially getting the style of selected dimensions, then changing that style.  So afterwards, all other dimensions that were set to that same style, and any new dimensions you create using that style, will be using those same style settings.  And on top of that, that style you are messing with is likely the default style for all of your dimensions.

 

It sounds like what you would really want to do here, is have an already existing dimension style that is all set-up the way you want it first, then apply that style to the selected dimensions, by setting their Style property's value to that other DimensionStyle object, directly.  Then all the other dimensions will stay the way they were, without disturbing anything else.  The preferred way would be to create that special DimensionStyle manually, within your Styles & Standards Editor dialog, ahead of time.  And if needed, that style can be saved up into the styles library, so that it will be available to other drawings.  However, you could also try to either find, or create that special style within your code, before you start to iterate through the selected dimensions, then just set that property value within the loop.  If you try to create a style with the same name as one that already exists in that drawing document, it will throw an error though, so it would be best to try to find an existing one first, by its name.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes