Dimension between two points

Dimension between two points

Damian_Apex
Enthusiast Enthusiast
1,087 Views
4 Replies
Message 1 of 5

Dimension between two points

Damian_Apex
Enthusiast
Enthusiast

Hello,

I would like to create dimension between two points, but I get an error that I can't fix.
This is a snippet of larger code, hopefully it is readable

 

Public Sub PlaceDimension(oDoc As Document, oSheet As Sheet, oAssem As AssemblyDocument,
ViewName As DrawingView, PositionX As Double, PositionY As Double,
AttrSetName1 As String, AttrName1 As String, AttrValue1 As String,
AttrSetName2 As String, AttrName2 As String, AttrValue2 As String) 'RULE TO ADD ONE DIMENSION

 

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

Dim aoEdge4 As Edge
Dim aoEdge3 As Edge

 

oObjs1 = oAssem.AttributeManager.FindObjects(AttrSetName1, AttrName1, AttrValue1)
oObjs2 = oAssem.AttributeManager.FindObjects(AttrSetName2, AttrName2, AttrValue2)

 

aoEdge4 = oObjs1.Item(1)
aoEdge3 = oObjs2.Item(1)

 

oDrawingViewCurves1 = ViewName.DrawingCurves(aoEdge4)
oDrawingViewCurves2 = ViewName.DrawingCurves(aoEdge3)

 

Dim aoDrawingCurve4 As DrawingCurve
Dim aoDrawingCurve3 As DrawingCurve

aoDrawingCurve4 = oDrawingViewCurves1.Item(1)
aoDrawingCurve3 = oDrawingViewCurves2.Item(1)

 

Dim oPt2 As Point2d
oPt2 = oTG.CreatePoint2d(PositionX, PositionY)

Dim GeoIntent1 As GeometryIntent
Dim GeoIntent2 As GeometryIntent

 

GeoIntent1 = oSheet.CreateGeometryIntent(aoDrawingCurve3.MidPoint)
GeoIntent2 = oSheet.CreateGeometryIntent(aoDrawingCurve4.MidPoint)

oDim2 = oGeneralDims.AddLinear(oPt2, GeoIntent1, GeoIntent2)
oDim2.CenterText


End Sub

0 Likes
Accepted solutions (1)
1,088 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @Damian_Apex.  Can you post the screen captured images of the information shown on both tabs of the error dialog when it pop's up, that way we might get a better idea about what is going wrong.  One thought I had about this code though is that it seems to me like you might be trying to identify and find 'named geometry' from the assembly.  If so, this may not work, because the normal 'named geometry' system only works with Part documents, not assembly documents.  Also in an assembly, any Edge type objects you might retrieve will be EdgeProxy objects, which represent a component's Edge within the assembly space, so the object variables would already be the wrong Type.  This type of situation can be pretty tricky to automate by code, due to the whole proxy objects issue, and lack of support for named entities support in assemblies directly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Damian_Apex
Enthusiast
Enthusiast

@WCrihfield I am using similar code to retrieve two faces from assembly and it's working. 

When it comes to edges I get them correctly and their mid points but when I am trying to use them to create dimension I get error.

 

GeoIntent1 = oSheet.CreateGeometryIntent(aoDrawingCurve3.MidPoint)
GeoIntent2 = oSheet.CreateGeometryIntent(aoDrawingCurve4.MidPoint)

oDim2 = oGeneralDims.AddLinear(oPt2, GeoIntent1, GeoIntent2)

 

This is my code for adding dimensions between two faces and it's working fine.

 

Public Sub PlaceDimension(oDoc As Document, oSheet As Sheet, oAssem As AssemblyDocument, 
								ViewName As DrawingView, PositionX As Double, PositionY As Double,
								AttrSetName1 As String, AttrName1 As String, AttrValue1 As String,
								AttrSetName2 As String, AttrName2 As String, AttrValue2 As String) 'RULE TO ADD ONE DIMENSION

	Dim oTG As TransientGeometry 
	oTG = ThisApplication.TransientGeometry	
	Dim oGeneralDims As GeneralDimensions
	oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
	
	Dim aoFace4 As Face
	Dim aoFace3 As Face

	oObjs1 = oAssem.AttributeManager.FindObjects(AttrSetName1, AttrName1, AttrValue1)
	oObjs2 = oAssem.AttributeManager.FindObjects(AttrSetName2, AttrName2, AttrValue2)

	aoFace4 = oObjs1.Item(1)
	aoFace3 = oObjs2.Item(1)
	oDrawingViewCurves1 = ViewName.DrawingCurves(aoFace4)
	oDrawingViewCurves2 = ViewName.DrawingCurves(aoFace3)
	
	Dim aoDrawingCurve4 As DrawingCurve
	Dim aoDrawingCurve3 As DrawingCurve
	
	aoDrawingCurve4 = oDrawingViewCurves1.Item(1)
	aoDrawingCurve3 = oDrawingViewCurves2.Item(1)

	Dim oPt2 As Point2d
	oPt2 = oTG.CreatePoint2d(PositionX, PositionY)

	Dim oDim2 As GeneralDimension

	oDim2 = oGeneralDims.AddLinear(oPt2, oSheet.CreateGeometryIntent(aoDrawingCurve3), oSheet.CreateGeometryIntent(aoDrawingCurve4))
	oDim2.CenterText	
End Sub

In attachment screens of error. 

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Damian_Apex 

To add a dimension between the midpoints of two drawingcurves, use the drawingcurve as the first argument and PointIntentEnum.kMidPointIntent as the second argument in the CreateGeometryIntent method.

 

I've attached a simple example that lets you pick two curves in a drawingview. The code will then add a lineardimension between them. I hope this helps 🙂

 

Dim oCurveSeg1 As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick first curve")
Dim oCurveSeg2 As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick second curve")

Dim oCurve1 As DrawingCurve = oCurveSeg1.Parent
Dim oCurve2 As DrawingCurve = oCurveSeg2.Parent

Dim oSheet As Sheet = ActiveSheet.Sheet
'Use kMidPointIntent
Dim oIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oCurve1, PointIntentEnum.kMidPointIntent)
Dim oIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oCurve2, PointIntentEnum.kMidPointIntent)

Dim oVector As Vector2d = oCurve1.MidPoint.VectorTo(oCurve2.MidPoint)
oVector.ScaleBy(0.5)
Dim oTextPoint As Point2d = oCurve1.MidPoint
oTextPoint.TranslateBy(oVector)

oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oTextPoint, oIntent1, oIntent2)
Message 5 of 5

Damian_Apex
Enthusiast
Enthusiast

@JhoelForshav thank you for help

I just need to modified this line in my code and it works as I wanted.

 

oSheet.CreateGeometryIntent(aoDrawingCurve3, PointIntentEnum.kMidPointIntent)

 

0 Likes