LineSegment2d.IntersectWithCurve with drawing dimensions

LineSegment2d.IntersectWithCurve with drawing dimensions

tfrohe_LSI
Advocate Advocate
539 Views
5 Replies
Message 1 of 6

LineSegment2d.IntersectWithCurve with drawing dimensions

tfrohe_LSI
Advocate
Advocate

I am trying to identify dimensions in my Inventor Drawing that have crossing dimension lines or extension lines.

 

crossed_dims.png

 

I am getting the dimension line and extension lines with

 

 

Dim oFirstDimLine As LineSegment2d = oFirstDimension.DimensionLine
Dim oFirstExtLine1 As LineSegment2d = oFirstDimension.ExtensionLineOne
Dim oFirstExtLine2 As LineSegment2d = oFirstDimension.ExtensionLineTwo

 

 

and

 

Dim oSecondDimLine As LineSegment2d = oSecondDimension.DimensionLine

 

 

When attempting to get the intersection, I get no results even though I can see that they are crossing on the drawing.

 

If oFirstDimLine.IntersectWithCurve(oSecondDimLine) IsNot Nothing And oFirstExtLine1.IntersectWithCurve(oSecondDimLine) IsNot Nothing And oFirstExtLine2.IntersectWithCurve(oSecondDimLine) IsNot Nothing Then
    ' If the extension lines are crossed, display a message box
    MsgBox("Dimension " & oFisrtDimension.Text.Text & " & Dimension " & oSecondDimension.Text.Text & " have crossed extension lines.",,"Crossed")
    oSelectSet.Select(oFirstDimension)
    oSelectSet.Select(oSecondDimension)
End If

 

 

LineSegment2d.IntersectWithCurve takes a curve as input that can be another LineSegment2d so why isn't this working for me?

 

LineSegment2d.IntersectWithCurve( Curve As Object, [Tolerance] As Double ) As ObjectsEnumerator

CurveObjectInput object. This can be a Line2d, LineSegment2d, Arc2d, EllipticalArc2d, Circle2d, EllipseFull2d, or a BSplineCurve2d.

 

Thank you.

0 Likes
Accepted solutions (2)
540 Views
5 Replies
Replies (5)
Message 2 of 6

richterBKSAC
Advocate
Advocate

Hi,

 

the first thing that's not clear to me is which dimension is "one" and which is "two" in your example?

I assume you're using two nested for-loops to test every dimension against the others?

As far as I can tell your code works, but the mistake is in your if-statement because it is always false.

If oFirstDimLine.IntersectWithCurve(oSecondDimLine) IsNot Nothing And oFirstExtLine1.IntersectWithCurve(oSecondDimLine) IsNot Nothing And oFirstExtLine2.IntersectWithCurve(oSecondDimLine) IsNot Nothing Then

The IntersectWithCurve method "Returns Nothing if the curves overlap or are parallel.". In this case both dimensionlines are parallel and the method will return Nothing.

 

If oFirstExtLine1.IntersectWithCurve(oSecondDimLine) IsNot Nothing And oFirstExtLine2.IntersectWithCurve(oSecondDimLine) IsNot Nothing Then
    ' If the extension lines are crossed, display a message box
    MsgBox("Dimension " & oFisrtDimension.Text.Text & " & Dimension " & oSecondDimension.Text.Text & " have crossed extension lines.",,"Crossed")
    oSelectSet.Select(oFirstDimension)
    oSelectSet.Select(oSecondDimension)
End If

This code works but only in the special case when both extensionlines cross the dimensionline. 

 

best regards,

Matthias

0 Likes
Message 3 of 6

tfrohe_LSI
Advocate
Advocate

Thank you Matthias, this helps. 

0 Likes
Message 4 of 6

J-Camper
Advisor
Advisor
Accepted solution

@tfrohe_LSI,

 

Here is a quick Function i wrote to tell you if 2 input linear dimensions intersect.  It you need to know which entities are intersection, that would be different. Here is the sample:

 

Sub Main
	Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
	If IsNothing(dDoc) Then Logger.Debug("Not Run In Drawing Document") : Exit Sub
		
	Dim PickThis1 As LinearGeneralDimension = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select Linear Dimension")
	If IsNothing(PickThis1) Then Exit Sub ' If nothing gets selected then we're done
		
	Dim PickThis2 As LinearGeneralDimension = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select Linear Dimension")
	If IsNothing(PickThis2) Then Exit Sub ' If nothing gets selected then we're done
		
	Logger.Trace("Do they intersect? " & AreDimensionsInterseting(PickThis1, PickThis2))
	
End Sub

Function AreDimensionsInterseting(oFirstDimension As LinearGeneralDimension, oSecondDimension As LinearGeneralDimension) As Boolean
	
	Dim FirstLineSegmentList, SecondLineSegmentList As New List(Of LineSegment2d)
	FirstLineSegmentList.Add(oFirstDimension.DimensionLine)
	FirstLineSegmentList.Add(oFirstDimension.ExtensionLineOne)
	FirstLineSegmentList.Add(oFirstDimension.ExtensionLineTwo)

	SecondLineSegmentList.Add(oSecondDimension.DimensionLine)
	SecondLineSegmentList.Add(oSecondDimension.ExtensionLineOne)
	SecondLineSegmentList.Add(oSecondDimension.ExtensionLineTwo)

	For Each TestLineSegment As LineSegment2d In FirstLineSegmentList
		For Each innerTestLineSegment As LineSegment2d In SecondLineSegmentList
			If IsNothing(TestLineSegment.IntersectWithCurve(innerTestLineSegment)) Then Continue For
			Return True
		Next
	Next
	
	Return False
End Function
0 Likes
Message 5 of 6

tfrohe_LSI
Advocate
Advocate
Accepted solution

Here is what I have come up with after @richterBKSAC's comments. This works for my purposes but is a little clunky.

 

Sub Main()

    ' Get the active document
    Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
	    
	' Setup a SelectSet to highlight any crossed dimensions
	Dim oSelectSet As SelectSet = oDoc.SelectSet
	oSelectSet.Clear
	
	'Setup boolean for crossed dim
	Dim crossed As Boolean = False

    ' Get all the dimensions in the document
    Dim oDims As Inventor.DrawingDimensions = oDoc.ActiveSheet.DrawingDimensions
	    
    ' Loop through each dimension and check if it's an aligned or vertical dimension
    For Each oFirstDimension As DrawingDimension In oDims
		'Exclude dimensiosn that may not have 2 extension lines (ExtensionLineOne, ExtensionLineTwo) or DimensionType Property
		'Will be added later
		If oFirstDimension.Type = kOrdinateDimensionObject Or oFirstDimension.Type = kRadiusGeneralDimensionObject Or oFirstDimension.Type = kDiameterGeneralDimensionObject Or oFirstDimension.Type = kAngularGeneralDimensionObject Then Continue For
		'MsgBox(oFirstDimension.Type,,"test")
		Try
	        'MsgBox("First Dimension Type is: " & oFirstDimension.Type,,"iLogic")
	        ' Check if it's an aligned, horizontal or vertical dimension
	        If oFirstDimension.DimensionType = DimensionTypeEnum.kAlignedDimensionType Or oFirstDimension.DimensionType = DimensionTypeEnum.kVerticalDimensionType Or oFirstDimension.DimensionType = DimensionTypeEnum.kHorizontalDimensionType Then
	            
	            ' Get the dimension and extension lines for the first dimension
				Dim oFirstDimLine As LineSegment2d = oFirstDimension.DimensionLine
	            Dim oFirstExtLine1 As LineSegment2d = oFirstDimension.ExtensionLineOne
	            Dim oFirstExtLine2 As LineSegment2d = oFirstDimension.ExtensionLineTwo
	            
				' Loop through all drawing dimensions to compare if any lines are crossed
				For Each oSecondDimension As DrawingDimension In oDims
					'MsgBox("Second Dimension Type is: " & oSecondDimension.Type,,"iLogic")
					
					'Do not check the dimensions if they are the same
		            If oSecondDimension Is oFirstDimension Then Continue For
						
					'Exclude dimensiosn that may not have 2 extension lines (ExtensionLineOne, ExtensionLineTwo) or DimensionType Property
					'Will be added later
					If oSecondDimension.Type = kOrdinateDimensionObject Or oSecondDimension.Type = kRadiusGeneralDimensionObject Or oSecondDimension.Type = kDiameterGeneralDimensionObject Or oSecondDimension.Type = kAngularGeneralDimensionObject Then Continue For
						
						' Check if it's an aligned, horizonal or vertical dimension
	        			If oSecondDimension.DimensionType = DimensionTypeEnum.kAlignedDimensionType Or oSecondDimension.DimensionType = DimensionTypeEnum.kVerticalDimensionType Or oSecondDimension.DimensionType = DimensionTypeEnum.kHorizontalDimensionType Then
							
							' Get the dimnesion line for the dimension
							Dim oSecondDimLine As LineSegment2d = oSecondDimension.DimensionLine
							
							' Check if the dimension lines are crossing
							Dim oDimLineIntersect As ObjectsEnumerator  = oFirstDimLine.IntersectWithCurve(oSecondDimLine)
							Dim oExtLine1Intersect As ObjectsEnumerator  = oFirstExtLine1.IntersectWithCurve(oSecondDimLine)
							Dim oExtLine2Intersect As ObjectsEnumerator = oFirstExtLine2.IntersectWithCurve(oSecondDimLine)
														
							'For our purposes, if crossing points are at the StartPoint or EndPoint of a dimension line, they are not counted as crossing							
		            		If oDimLineIntersect IsNot Nothing Then
								For Each oPoint As Point2d In oDimLineIntersect
									If Not (oPoint.IsEqualTo(oSecondDimLine.StartPoint) Or oPoint.IsEqualTo(oSecondDimLine.EndPoint)) Then
										crossed = True
									End If
								Next							
							End If
							
							If oExtLine1Intersect IsNot Nothing Then
								For Each oPoint As Point2d In oExtLine1Intersect
									If Not (oPoint.IsEqualTo(oSecondDimLine.StartPoint) Or oPoint.IsEqualTo(oSecondDimLine.EndPoint)) Then
										crossed = True
									End If
								Next
							End If
							
							If oExtLine2Intersect IsNot Nothing Then
								For Each oPoint As Point2d In oExtLine2Intersect
									If Not (oPoint.IsEqualTo(oSecondDimLine.StartPoint) Or oPoint.IsEqualTo(oSecondDimLine.EndPoint)) Then
										crossed = True
									End If
								Next
							End If

							' If the dimension/extension lines are crossed, display a message box and add them to the selection set
							If crossed Then
		                		MsgBox("Dimension " & oFirstDimension.Text.Text & " & Dimension " & oSecondDimension.Text.Text & " have crossed extension lines.",,"Crossed")
								oSelectSet.Select(oFirstDimension)
								oSelectSet.Select(oSecondDimension)
								crossed = False
							End If
		            	End If
	            Next
	        End If
    	Catch ex As Exception
			MsgBox(ex.Message)
		End Try

	Next
    
End Sub

 

I plan to revise this to add additional dimension types in the future.

 

@J-Camper I did try your code and it works fine. I have marked it as a solution although I have not used it in my script. Thank you.

0 Likes
Message 6 of 6

ashik_rahmanPXGR8
Explorer
Explorer

Did you get a chance to work on this further to add more dimension type?

0 Likes