Determine (Scale of) the DrawingDimension's Parent DrawingView

Determine (Scale of) the DrawingDimension's Parent DrawingView

Maxim-CADman77
Advisor Advisor
1,260 Views
10 Replies
Message 1 of 11

Determine (Scale of) the DrawingDimension's Parent DrawingView

Maxim-CADman77
Advisor
Advisor

I'd like to know the easiest (or at leas any) method to determine which DrawingView is parent for the given DrawingDimension.

To be more precise I need the ViewScale.

For the whole task context see https://forums.autodesk.com/t5/inventor-customization/determine-if-drawing-dimension-is-broken/td-p/...

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
1,261 Views
10 Replies
Replies (10)
Message 2 of 11

JhoelForshav
Mentor
Mentor

@Maxim-CADman77 

Drawing dimensions doesn't belong to any view, but the sheet. Their intent(s) however has a view parent.

Try this ilogic code to get the scale of the drawingview a picked drawing dimension is attached to 🙂

 

Dim oDrawDim As GeneralDimension = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select dimension")
Dim oView As DrawingView
Select Case oDrawDim.Type
Case ObjectTypeEnum.kLinearGeneralDimensionObject, ObjectTypeEnum.kAngularGeneralDimensionObject
	oView = oDrawDim.IntentOne.Geometry.Parent
Case ObjectTypeEnum.kRadiusGeneralDimensionObject, ObjectTypeEnum.kDiameterGeneralDimensionObject
	oView = oDrawDim.Intent.Geometry.Parent
End Select

If oView Is Nothing
	MsgBox("Dimension type not supported")
	Exit Sub
End If

MsgBox("Scale factor (double) = " & oView.Scale)
MsgBox("Scale string = " & oView.ScaleString)

 

Message 3 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@Maxim-CADman77,

 

Try below VBA code to select broken dimension depends on drawing view scale.

Sub Select_Broken_Dimension()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oDimension As DrawingDimension
    For Each oDimension In oSheet.DrawingDimensions
        Dim d As Double
        d = distance(oDimension.DimensionLine.StartPoint.Y, oDimension.DimensionLine.StartPoint.X, oDimension.DimensionLine.EndPoint.Y, oDimension.DimensionLine.EndPoint.X)
        Dim oScale As Double
        Dim oView As DrawingView
        
        If oDimension.Type = kLinearGeneralDimensionObject Then
            Set oView = oDimension.IntentOne.Geometry.Parent
            oScale = oView.Scale
            d = d / oScale
            If d <> oDimension.ModelValue Then
                Call oDoc.SelectSet.Select(oDimension)
            End If
        End If
        
    Next
End Sub

Function distance(ya As Double, xa As Double, yb As Double, xB As Double)
    distance = Sqr((ya - yb) ^ 2 + (xa - xB) ^ 2)
End Function

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 11

Maxim-CADman77
Advisor
Advisor

I've marked this as solution but in fact it fails with some message (I believe in English it sounds like "Object variable or With block variable not set ") if dimension is retrieved.

..so I still need some help.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@Maxim-CADman77,

 

Please provide non confidential drawing to reproduce the same error.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 11

Maxim-CADman77
Advisor
Advisor

Please find set of the sample files attached.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 7 of 11

JhoelForshav
Mentor
Mentor

Hi @Maxim-CADman77 

The retrieved dimensions wasnt easy because they have intenttype = kNoPointIntent

I found a way to get the view though. You could clean the code up a bit but I think this should work 🙂

 

Dim oView As DrawingView
Dim oDrawDim As GeneralDimension = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select dimension")
Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet

Select Case oDrawDim.Type
	Case ObjectTypeEnum.kLinearGeneralDimensionObject, ObjectTypeEnum.kAngularGeneralDimensionObject
		If oDrawDim.Retrieved
			Dim FoundObjects As ObjectsEnumerator = oSheet.FindUsingPoint(oDrawDim.IntentOne.PointOnSheet)
			If FoundObjects.Count = 0 Then FoundObjects = oSheet.FindUsingPoint(oDrawDim.IntentTwo.PointOnSheet)
			For Each oObj In FoundObjects
				If oObj.Type = ObjectTypeEnum.kDrawingCurveSegmentObject
					oView = oObj.Parent.Parent
					Exit For
				End If
			Next
		Else
			oView = oDrawDim.IntentOne.Geometry.Parent
		End If
	Case ObjectTypeEnum.kRadiusGeneralDimensionObject, ObjectTypeEnum.kDiameterGeneralDimensionObject
	If oDrawDim.Retrieved
			Dim FoundObjects As ObjectsEnumerator = oSheet.FindUsingPoint(oDrawDim.Intent.PointOnSheet)
			For Each oObj In FoundObjects
				If oObj.Type = ObjectTypeEnum.kDrawingCurveSegmentObject
					oView = oObj.Parent.Parent
					Exit For
				End If
			Next
		Else
		oView = oDrawDim.Intent.Geometry.Parent
	End If
End Select


If oView Is Nothing
	MsgBox("Dimension type not supported")
	Exit Sub
End If

MsgBox("Scale factor (double) = " & oView.Scale)
MsgBox("Scale string = " & oView.ScaleString)
0 Likes
Message 8 of 11

Maxim-CADman77
Advisor
Advisor

Please find set of sample files where failure occures on Diameter and Angular dimensions

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 9 of 11

JhoelForshav
Mentor
Mentor

@Maxim-CADman77 

Since the dimensions doesn't belong to a view it's almost impossible to cover all scenarios.

One of these dimensions were attached to a centermark that was attached to a view, the other was attached to a centerline that was attached to a centermark that was attached to a view. As you probably can tell by that, there are so many possible paths from the dimensions geometry intent to a view. It can require countless steps before a view is finally reached and every object type has its own property through which to access the object it's attached to...

 

Anyways... This rule covers the two new scenarios.

 

Dim oView As DrawingView
Dim oDrawDim As GeneralDimension = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select dimension")
Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet

Select Case oDrawDim.Type
	Case ObjectTypeEnum.kLinearGeneralDimensionObject, ObjectTypeEnum.kAngularGeneralDimensionObject
		If oDrawDim.Retrieved
			Dim FoundObjects As ObjectsEnumerator = oSheet.FindUsingPoint(oDrawDim.IntentOne.PointOnSheet)
			If FoundObjects.Count = 0 Then FoundObjects = oSheet.FindUsingPoint(oDrawDim.IntentTwo.PointOnSheet)
			For Each oObj In FoundObjects
				If oObj.Type = ObjectTypeEnum.kDrawingCurveSegmentObject
					oView = oObj.Parent.Parent
					Exit For
				End If
			Next
		Else
			Dim oIntent As GeometryIntent = oDrawDim.IntentOne
			If oIntent.Geometry.Parent.Type = ObjectTypeEnum.kSheetObject Then
				Select Case oIntent.Geometry.Type
					Case ObjectTypeEnum.kCentermarkObject
						oView = oIntent.Geometry.AttachedEntity.Geometry.Parent
					Case ObjectTypeEnum.kCenterlineObject
						 oView = oIntent.Geometry.FitPoints(1).AttachedEntity.Geometry.Parent
				End Select
			Else
				oView = oIntent.Geometry.Parent
			End If
		End If
	Case ObjectTypeEnum.kRadiusGeneralDimensionObject, ObjectTypeEnum.kDiameterGeneralDimensionObject
		If oDrawDim.Retrieved
			Dim FoundObjects As ObjectsEnumerator = oSheet.FindUsingPoint(oDrawDim.Intent.PointOnSheet)
			For Each oObj In FoundObjects
				If oObj.Type = ObjectTypeEnum.kDrawingCurveSegmentObject
					oView = oObj.Parent.Parent
					Exit For
				End If
			Next
		Else
			Dim oIntent As GeometryIntent = oDrawDim.Intent
			If oIntent.Geometry.Parent.Type = ObjectTypeEnum.kSheetObject Then
				Select Case oIntent.Geometry.Type
					Case ObjectTypeEnum.kCentermarkObject
						oView = oIntent.Geometry.AttachedEntity.Geometry.Parent
					Case ObjectTypeEnum.kCenterlineObject
						 oView = oIntent.Geometry.FitPoints(1).AttachedEntity.Geometry.Parent
				End Select
			Else
				oView = oIntent.Geometry.Parent
			End If
		End If
End Select


If oView Is Nothing
	MsgBox("Dimension type not supported")
	Exit Sub
End If

MsgBox("Scale factor (double) = " & oView.Scale)
MsgBox("Scale string = " & oView.ScaleString)

 

0 Likes
Message 10 of 11

Maxim-CADman77
Advisor
Advisor

I see. In fact attaching dimension to auxiliary geometry instead of model edge is a common practice.

Yet my task perobably can be simplified to solvable with couple assumptions/limitations ...
Let say:

1. I'm interested in analyzing only Linear dimensions (i believe there is no much sense in breaking other dimension types). 

2. Healthy drawing should not contain any view overlaping or unattached dimensions

(parent view then can be determined indirectly as the one which range box "catches" both dimension attachement points, right?)

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 11 of 11

JhoelForshav
Mentor
Mentor
Accepted solution

@Maxim-CADman77 

Even though it's common practice to attach demensions to auxiliary geometry, keep in mind that this geometry is not part of the drawingview object either. We have to work with how the API is built and what's exposed to us.

 


@Maxim-CADman77 wrote:

I see. In fact attaching dimension to auxiliary geometry instead of model edge is a common practice.

Yet my task perobably can be simplified to solvable with couple assumptions/limitations ...
Let say:

1. I'm interested in analyzing only Linear dimensions (i believe there is no much sense in breaking other dimension types). 

2. Healthy drawing should not contain any view overlaping or unattached dimensions

(parent view then can be determined indirectly as the one which range box "catches" both dimension attachement points, right?)

 


Something like this maybe?

Sub Main
Dim oView As DrawingView
Dim oDrawDim As GeneralDimension = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "Select dimension")
Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet

If oDrawDim.Type <> ObjectTypeEnum.kLinearGeneralDimensionObject
	MsgBox("Not a linear dimension")
	Exit Sub
End If


Dim oIntPos1 As Point2d = oDrawDim.IntentOne.PointOnSheet
Dim oIntPos2 As Point2d = oDrawDim.IntentTwo.PointOnSheet

For Each dW As DrawingView In oSheet.DrawingViews
	If pointInView(oIntPos1, dW) Or pointInView(oIntPos2, dW) 'Change to "And" if you want to check if both is in view.
		oView = dW
		Exit For
	End If
Next

If oView Is Nothing
	MsgBox("Dimension type not supported")
	Exit Sub
End If

MsgBox("Scale factor (double) = " & oView.Scale)
MsgBox("Scale string = " & oView.ScaleString)
End Sub

Function pointInView(ByRef pt As Point2d, ByRef oView As DrawingView) As Boolean
	If pt.X >= oView.Left AndAlso pt.X <= (oView.Left + oView.Width)
		If pt.Y <= oView.Top AndAlso pt.Y >= (oView.Top - oView.Height)
			Return True
		End If
	End If
	Return False	
End Function

I think it should be enough to check that at least one of the intent points is within the boundary of the view.

0 Likes