How to select Subassembly marker point programmatically?

How to select Subassembly marker point programmatically?

varshaauti27
Advocate Advocate
1,699 Views
5 Replies
Message 1 of 6

How to select Subassembly marker point programmatically?

varshaauti27
Advocate
Advocate

When trying to add subassembly to assembly using AddSubassembly(ObjectId subassemblyId, Point pointHookTo); method, the “pointHookTo” fiedls, which governs marker point for subassembly. Is it possible to select that marker point(Autodesk.Civil.DatabaseServices.Point) like other objects selections?

 

varshaaERKZR_1-1656076685262.png

 

OR

Is it possible to convert Autodesk.AutoCAD.Geometry.Point3d to Autodesk.Civil.DatabaseServices.Point vice-versa.

 

OR

If I have Autodesk.AutoCAD.Geometry.Point3d is there any way to find nearest marker point to that selected Autodesk.AutoCAD.Geometry.Point3d with API

0 Likes
Accepted solutions (1)
1,700 Views
5 Replies
Replies (5)
Message 2 of 6

hosneyalaa
Advisor
Advisor
0 Likes
Message 3 of 6

varshaauti27
Advocate
Advocate

This is Autodesk.Civil.DatabaseServices.Point collection, which give us all marker points of subassembly.

Through my addin I want user to select marker point then I can use that point to hook subassembly using AddSubassembly method which requires Autodesk.Civil.DatabaseServices.Point. 

 

I am using ed.GetPoint method to select point which returns Autodesk.AutoCAD.Geometry.Point3d point so I can not pass this to AddSubassembly method as it needs Autodesk.Civil.DatabaseServices.Point. 

 

varshaauti27_0-1656087594205.png

In short, I want user to select Marker point at index: 2, then I will attached Subassembly there using AddSubassembly method

0 Likes
Message 4 of 6

hosneyalaa
Advisor
Advisor

Using looping

Subassembly.points 

If x1 ==xi  and y1 == yi

Hank.point = Subassembly.points[i]

 

0 Likes
Message 5 of 6

gleeuwdrent
Advocate
Advocate
Accepted solution

Use the PickedPoint property of your PromptEntityResult and loop trough all points of the subassembly to determine the nearest point:

int indexHookTo = -1;
Point3d basePoint = subassembly.Origin;
Point3d pickedPoint = promptEntityResult.PickedPoint;

double distance = 10000000;
foreach (var point in subassembly.Points)
{
	Point3d point3d = new Point3d(basePoint.X + point.Offset, basePoint.Y + point.Elevation, 0.0);
	if (point3d.DistanceTo(pickedPoint) < distance)
	{
		distance = point3d.DistanceTo(pickedPoint);
		indexHookTo = point.Index;
	}
}
Message 6 of 6

varshaauti27
Advocate
Advocate

It works as expected, Thanks a lot!

0 Likes