Avoid writing annotations on top of shown geometry - DrawingView/FindUsingRay

Avoid writing annotations on top of shown geometry - DrawingView/FindUsingRay

Skadborg.NTI
Advocate Advocate
761 Views
3 Replies
Message 1 of 4

Avoid writing annotations on top of shown geometry - DrawingView/FindUsingRay

Skadborg.NTI
Advocate
Advocate

I would like to add some leaders to a drawingview. I don't want to put them on top of my part. So I would like to test if a given point on the sheet conflicts with any shown geometry. I use FindUsing Ray for that. But my problem is to define the sheet as a clipping plane. My current code also finds intersections "behind my back":

 

Clip.png

 

'For Each Leader In ActiveSheet.Sheet.DrawingNotes.LeaderNotes
'	Leader.delete
'Next
Dim view As DrawingView
view=ActiveSheet.View("A").View
Dim modelDoc As PartDocument = ThisDrawing.ModelDocument
Dim compo As PartComponentDefinition
compo = modelDoc.ComponentDefinition

For Each dc As DrawingCurve In view.DrawingCurves
	Dim oLeaderPoints As ObjectCollection
	oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
	
	Dim txtPt2D = ThisApplication.TransientGeometry.CreatePoint2d(dc.MidPoint.X -1, dc.MidPoint.Y -1)
	Dim Line3D As Line = view.SheetToModelSpace(txtPt2D)
	Dim FoundEntities As ObjectsEnumerator
	Dim LocationPoints As ObjectsEnumerator
	Call compo.FindUsingRay(Line3D.RootPoint,Line3D.Direction ,0.0001,FoundEntities, LocationPoints)
	
	Dim txt As String
	If FoundEntities.Count>0 Then
		txt="Leader/solid conflict"
	Else
		txt ="Leader ok"
	End If
	oLeaderPoints.Add(txtPt2D)
	Call oLeaderPoints.Add(dc.MidPoint)
	Dim oLeaderNote As LeaderNote
	oLeaderNote =  ActiveSheet.Sheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, txt)
Next

Can I in any better way see if a point on the sheet is on top of shown geometry?

 

0 Likes
762 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@Skadborg.NTI,

 

In the above code, txtPt2D should be verified whether it is inside solid body or not. There is a algorithm to check a point whether inside a polygon or not.

 

public bool IsPointInPolygon( Point p, Point[] polygon )
{
    double minX = polygon[ 0 ].X;
    double maxX = polygon[ 0 ].X;
    double minY = polygon[ 0 ].Y;
    double maxY = polygon[ 0 ].Y;
    for ( int i = 1 ; i < polygon.Length ; i++ )
    {
        Point q = polygon[ i ];
        minX = Math.Min( q.X, minX );
        maxX = Math.Max( q.X, maxX );
        minY = Math.Min( q.Y, minY );
        maxY = Math.Max( q.Y, maxY );
    }

    if ( p.X < minX || p.X > maxX || p.Y < minY || p.Y > maxY )
    {
        return false;
    }

    // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
    bool inside = false;
    for ( int i = 0, j = polygon.Length - 1 ; i < polygon.Length ; j = i++ )
    {
        if ( ( polygon[ i ].Y > p.Y ) != ( polygon[ j ].Y > p.Y ) &&
             p.X < ( polygon[ j ].X - polygon[ i ].X ) * ( p.Y - polygon[ i ].Y ) / ( polygon[ j ].Y - polygon[ i ].Y ) + polygon[ i ].X )
        {
            inside = !inside;
        }
    }

    return inside;
}

 In above C# code, 2 parameters are required to find inside or not. First parameter is Point p, which is nothing but txtPt2D in your case.

 

large.png

 

Second parameter Point[] Polygon would be collection of points (P1, P2, P3 and P4) as shown in above image.

 

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 4

Skadborg.NTI
Advocate
Advocate

Thank you for this, Chandra. But the main problem still persist. The geometry in my example is very simple. But my real geometry is an assembly with many parts. So I can't establish the polygon needed for your solution - in fact this is the core problem: To figure out what is solid and what is "blank paper".

 

Regards

Poul Skadborg Petersen

0 Likes
Message 4 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@Skadborg.NTI

 

For Complex assembly drawing file also, points can be collected from DrawingCurves of DrawingViews.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes