How to check if a DrawingDimension is in a Selected set?

How to check if a DrawingDimension is in a Selected set?

inulobo
Advocate Advocate
1,449 Views
8 Replies
Message 1 of 9

How to check if a DrawingDimension is in a Selected set?

inulobo
Advocate
Advocate

I am trying to sort out dimensions that are selected from non selected. Please see the loops below.

 

    For Each oDrawingDim In oDrawingDimensions
        If oDoc.SelectSet Then
            oDrawingDim.CenterText
            Call oDimsToBeArrangedVertical.Add(oDrawingDim)
        Else
            oDrawingDim.CenterText
            Call oDimsToBeArrangedHorizontal.Add(oDrawingDim)
        End If
    Next

 

 

 

 

0 Likes
Accepted solutions (2)
1,450 Views
8 Replies
Replies (8)
Message 2 of 9

dba78
Advocate
Advocate

maybe this works for your scenario. VBa is very limited on collection comparision, therefore the nested loops...

 

'VBA

Sub dimensions()
Dim doc As DrawingDocument
Set doc = ThisApplication.ActiveDocument
Dim d As DrawingDimension
Dim coll As New Collection

For Each obj In doc.SelectSet
If TypeOf obj Is DrawingDimension Then
    coll.Add obj
    End If
Next

For Each d In doc.ActiveSheet.DrawingDimensions
    For i = 1 To coll.count
        If d Is coll.item(i) Then
            'Do your code on selected ones
            GoTo nextD
        End If
    Next
    'do your code on unselected ones
    
nextD:
Next
End Sub

 

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

It looks like your code is trying to do something very similar to what is being discussed within another post right now.  Check out some of the iLogic code being shown here:

https://forums.autodesk.com/t5/inventor-customization/is-it-possible-to-automatically-arrange-chain-... 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

inulobo
Advocate
Advocate

Thanks for the reply. It's nice but not exactly what I am looking for. Inventor Drawings have a difficult time labeling dimensions as vertical or horizontal. A lot of my vertical and horizontal dims were set as aligned dimensions. So in order to deal with this situation, I planned to select all dimensions that were vertical and change their specific display spacing/gap parameters and the remainder would also have their own display spacing/gap parameters. It's my workaround for the situation. Use the function below to see what I mean.

 

Public Function Get_DimTypeDesc(DimType As DrawingDimension) As String
    
    Dim sType As String
    
    Select Case DimType.DimensionType
        Case kAlignedDimensionType:
            sType = ("kAlignedDimensionType")
        Case kAngularDimensionType:
            sType = ("kAngularDimensionType")
        Case kAngularForeshortenedDimensionType:
            sType = ("kAngularForeshortenedDimensionType")
        Case kArcLengthDimensionType:
            sType = ("kArcLengthDimensionType")
        Case kArcLengthForeshortenedDimensionType:
            sType = ("kArcLengthForeshortenedDimensionType")
        Case kDiametricDimensionType:
            sType = ("kDiametricDimensionType")
        Case kHorizontalDimensionType:
            sType = ("kHorizontalDimensionType")
        Case kLinearForeshortenedDimensionType:
            sType = ("kLinearForeshortenedDimensionType")
        Case kSymmetricDimensionType:
            sType = ("kSymmetricDimensionType")
        Case kVerticalDimensionType:
            sType = ("kVerticalDimensionType")
    Case Else

    End Select
    
    Get_DimTypeDesc = sType
End Function

 

0 Likes
Message 5 of 9

WCrihfield
Mentor
Mentor

I see.  And you do you want to get all dimensions that are oriented vertically on you drawing, or just the ones that evaluate to kVerticalDiminsionType?

   Also, I don't know if you have already considered this yet, but perhaps you could set up two different DimensionStyles to use for this scenario (one for vertical dims and one for horizontal dims).  Then instead of attempting to manipulate many aspects of each dim, you could just set its Style to one of the two that fits the situation.  Hopefully a Style can contain all needed specifications for these two scenarios, because that would make the job much easier.

   If you need also need to inspect all other types of dimensions (besides the kVerticalDimensionType), we'll just have to look into getting the DimensionLine or similar object within each, then hopefully its 'Geometry', then maybe its Evaluator, so we can check the orientation that way.  It may get kind of complicated, but may not be impossible.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 9

inulobo
Advocate
Advocate

What you said is pretty much exactly what I am doing. I have all the other code done. I just need to get the dims sorted out. As long as a dim <> kAngularDimensionType/ kAngularForeshortenedDimensionType/ kArcLengthDimensionType/ kArcLengthForeshortenedDimensionType/ kDiametricDimensionType I'll try to arrange them. Ill attach an image. The H = Horizontaltype, A = Alignedtype. The circled dims are my "Horizontal Dimensions" that ill arrange using whatever display style settings I set. The remainder will be arranged using another style setting. That way when I select I know for sure at least to me that they are my "horizontal" dimensions. 

inulobo_0-1604593974030.png

 

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

I think I may have a good starting point for you here.  This iLogic code starts off by building a series of List objects.  The first List is to hold all the different DrawingTypeEnum variations that aren't linear, so we can use this weed them out later.  Since there were 6 non-linear types and 7 linear types, it was almost a toss-up as to which way to filter them.  The next 3 List objects are to hold the dimensions, according to their orientation, as we filter through them.  One for Horizontal dims, one or Vertical dims, and one for (other) dims that are neither Horizontal nor Vertical (most likely aligned).  Then I start to loop through each sheet, then each DrawingDimension on each sheet.  The first check in the filter system checking to see if this is any of the non-linear types.  Then I check for the two simplest types Horizontal and Vertical.  Then I start checking the orientation of their DimensionLine geometry.  Then any that don't match any of these filters, get added to the last List (oODims).   After all the loops and checks are done, you should have 3 filtered lists to work with.  Now you can loop through each list applying your Style and/or any arrangement/alignment methods to them.

Here's the code:

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
'Build list of all non-linear DimensionTypeEnum variants to check against
Dim oNLTypes As New List(Of DimensionTypeEnum)
oNLTypes.Add(DimensionTypeEnum.kAngularDimensionType)
oNLTypes.Add(DimensionTypeEnum.kAngularForeshortenedDimensionType)
oNLTypes.Add(DimensionTypeEnum.kArcLengthDimensionType)
oNLTypes.Add(DimensionTypeEnum.kArcLengthForeshortenedDimensionType)
oNLTypes.Add(DimensionTypeEnum.kDiametricDimensionType)
oNLTypes.Add(DimensionTypeEnum.kParallelDiametricDimensionType)

'Build a list to hold all the Horizontally oriented dims
Dim oHDims As New List(Of DrawingDimension)
'Build a list to hold all the Vertically oriented dims
Dim oVDims As New List(Of DrawingDimension)
'Build a list to hold all the other Aligned (neither Horizontal nor Vertical) dims
Dim oODims As New List(Of DrawingDimension)

Dim oNonLinear As Boolean
For Each oSheet As Inventor.Sheet In oDDoc.Sheets
	For Each oDDim As DrawingDimension In oSheet.DrawingDimensions
		oNonLinear = False
		For Each oDType As DimensionTypeEnum In oNLTypes
			If oDDim.DimensionType = oDType Then oNonLinear = True
		Next
		If oNonLinear = False Then
			If oDDim.DimensionType = DimensionTypeEnum.kHorizontalDimensionType Then
				oHDims.Add(oDDim)
			ElseIf oDDim.DimensionType = DimensionTypeEnum.kVerticalDimensionType Then
				oVDims.Add(oDDim)
			ElseIf TypeOf oDDim.DimensionLine Is LineSegment2d Then
				Dim oLS2d As LineSegment2d = oDDim.DimensionLine
				If oLS2d.Direction.X = 1 Or _
					oLS2d.Direction.X = -1 Then
					'It's Horizontal, so add it to our oHDims list
					oHDims.Add(oDDim)
				ElseIf oLS2d.Direction.Y = 1 Or _
					oLS2d.Direction.Y = -1 Then
					'It's Vertical, so add it to our oVDims list
					oVDims.Add(oDDim)
				End If
			Else
				'It's neither Horizontal or Vertical, so it must be at an angle
				oODims.Add(oDDim)
			End If
		End If
	Next
Next
'Now you can start iterating through each List and applying which ever Styles to them
'and do whatever alignment you want with them.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 9

J-Camper
Advisor
Advisor
Accepted solution

See if this is giving you what you need [Highlight area with dimensions you want to collect then run the rule]:

Sub Main
	If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then MessageBox.Show("This rule is designed to only work in drawing documents.", "Wrong Document Type") : Exit Sub
	Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	If oDoc.SelectSet.Count < 1 Then Exit Sub
	Dim Hcol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim Vcol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	For Each Item In oDoc.SelectSet
		If Item.Type = ObjectTypeEnum.kLinearGeneralDimensionObject
			Dim drawDim As LinearGeneralDimension = Item
			If drawDim.DimensionType = DimensionTypeEnum.kHorizontalDimensionType Or TestPoints(drawDim) = "H"
				Hcol.Add(drawDim)
			Else If drawDim.DimensionType = DimensionTypeEnum.kVerticalDimensionType Or TestPoints(drawDim) = "V"
				Vcol.Add(drawDim)
			End If
		End If
	Next
	MessageBox.Show("Horizontal Count: " & Hcol.Count & vbCrLf & "Vertical Count: " & Vcol.Count, "Dims Collected:")
End Sub

Function TestPoints(oDim As LinearGeneralDimension) As String
	Dim Result As String = ""
	'test dimension line in paper space:
	Dim oLine As LineSegment2d = oDim.DimensionLine
	If oLine.EndPoint.X = oLine.StartPoint.X
		Result = "V"
	Else If oLine.EndPoint.Y = oLine.StartPoint.Y
		Result = "H"
	End If
	'Return Result
	Return Result
End Function

Let me know if you have any questions or if it is not working as intended.

0 Likes
Message 9 of 9

inulobo
Advocate
Advocate
Accepted solution

I took what you made and created a macro that will run for the sheet that you are on. You guys are awesome. The post has kind of moved away from its original intent but I have what I wanted in its entirety. The key to my problem was solved with your TestPoints Function. Everything works flawlessly. I no longer need to use selectset. I appreciate the posts above that showed me how to access the items in a selectset in any case! Please see the final code below:

 

Sub AutoA()

    If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
        MsgBox "This rule only works for Drawing Documents." & vbOKOnly & "WRONG DOCUMENT TYPE"
        Exit Sub
    End If
    
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Inventor.Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oStyle As DimensionStyle
    Set oStyle = oDoc.StylesManager.DimensionStyles.Item("MRK")
    
    Dim oScale As Double
    oScale = 2.54
    
    'If oDoc.SelectSet.Count < 1 Then Exit Sub
    
    Dim Hcol As ObjectCollection
    Set Hcol = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim Vcol As ObjectCollection
    Set Vcol = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oDimensions As DrawingDimensions
    Set oDimensions = oSheet.DrawingDimensions
    
    Dim Item As LinearGeneralDimension
    
    'For Each Item In oDoc.SelectSet
    For Each Item In oDimensions
        If Item.Type = ObjectTypeEnum.kLinearGeneralDimensionObject Then

            If Item.DimensionType = kHorizontalDimensionType Or TestPoints(Item) = "H" Then
                Call Hcol.Add(Item)
            ElseIf Item.DimensionType = kVerticalDimensionType Or TestPoints(Item) = "V" Then
                Call Vcol.Add(Item)
            End If
        End If
    Next
    
    MsgBox "Horizontal Count: " & Hcol.Count & vbNewLine & "Vertical Count: " & Vcol.Count & vbNewLine & "Dims Collected:" & (Hcol.Count + Vcol.Count)
    
    If Hcol.Count > 0 Then
        oStyle.Extension = 0.125 * oScale
        oStyle.OriginOffset = 0.063 * oScale
        oStyle.Gap = 0.031 * oScaled
        oStyle.spacing = 0.203125 * oScale
        oStyle.PartOffset = 0.125 * oScale
        Call oDimensions.Arrange(Hcol)
    End If
    
    If Vcol.Count > 0 Then
        oStyle.Extension = 0.125 * oScale
        oStyle.OriginOffset = 0.063 * oScale
        oStyle.Gap = 0.031 * oScale
        oStyle.spacing = 0.625 * oScale
        oStyle.PartOffset = 0.125 * oScale
        Call oDimensions.Arrange(Vcol)
    End If
    
End Sub

Function TestPoints(oDim As LinearGeneralDimension) As String
    Dim Result As String
    Result = ""
    'test dimension line in paper space:
    Dim oLine As LineSegment2d
    Set oLine = oDim.DimensionLine
    If oLine.EndPoint.X = oLine.StartPoint.X Then
        Result = "V"
    ElseIf oLine.EndPoint.Y = oLine.StartPoint.Y Then
        Result = "H"
    End If
    'Return Result
    TestPoints = Result
End Function

 

0 Likes