get element from XYZ

get element from XYZ

ahmed.errazak
Enthusiast Enthusiast
1,598 Views
8 Replies
Message 1 of 9

get element from XYZ

ahmed.errazak
Enthusiast
Enthusiast

Hello,

Is it possible to retrieve the element when selecting with this method ?


Dim StartPoint As XYZ = Sel.PickPoint (ObjectSnapTypes.Endpoints, "Insert Point")


Because the StartPoint is on an element !

 

thanks

0 Likes
1,599 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

You can use PickObject. That will give you both the point and the element.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

RPTHOMAS108
Mentor
Mentor

No an XYZ (the only thing returned from that method) does not uniquely define an element e.g. two beams can connect at an end point. 

 

You should use Selection.PickObject(Selection.ObjectType.PointOnElement), this returns a Reference.

0 Likes
Message 4 of 9

boostyourbim
Advocate
Advocate

As others have noted, if the point being selected is always going to be a point on an element, use PickObject instead of PickPoint. 

But maybe you want to let the user pick anywhere and then determine if there is an object at that point. In this case, PickObject is no good because it will not let you pick in empty space. So if this is your goal, use PickPoint, create a little spherical solid at that point (see code below), and then use an ElementIntersectsSolidFilter to see if there is an element that intersects that sphere.

 

                double radius = 0.2;
                Arc arc = Arc.Create(
                  xyz - radius * XYZ.BasisZ,
                  xyz + radius * XYZ.BasisZ,
                  xyz + radius * XYZ.BasisX);

                Line line = Line.CreateBound(
                  arc.GetEndPoint(1),
                  arc.GetEndPoint(0));

                CurveLoop halfCircle = new CurveLoop();
                halfCircle.Append(arc);
                halfCircle.Append(line);

                List<CurveLoop> loops = new List<CurveLoop>
                {
                    halfCircle
                };

                Frame frame = new Frame(xyz, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);
                Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, loops, 0, 2 * Math.PI);

 

0 Likes
Message 5 of 9

ahmed.errazak
Enthusiast
Enthusiast

Sorry, it's my fault, I wasn't very concrete in my explanation

the point is that I must define the insertion angle of my valve in advance
so I can predict the orientation of my valve and my motor

 

I tried to explain it below with a sketch

Orientation-Angle.PNG

 

0 Likes
Message 6 of 9

boostyourbim
Advocate
Advocate

With PickObject you can get the XYZ location where the mouse was clicked. Get the reference from the pick and the GlobalPoint property.

 

		public void point()
		{
			UIDocument uidoc = this.ActiveUIDocument;
			Document doc = this.ActiveUIDocument.Document;
			Reference r = uidoc.Selection.PickObject(ObjectType.Element);
			TaskDialog.Show("point", r.GlobalPoint.ToString());
		}

0 Likes
Message 7 of 9

RPTHOMAS108
Mentor
Mentor

Is the pipe there already before you add your fitting?

 

If this is the case why do you need to pick two points? By picking the pipe element intersecting the wall you have two end points one near the wall and one further away from the wall. So get the distance of both from the Face.Project(XYZ) and then order them as such for direction. Do you really want a user to be picking two points when they can pick one pipe? Test that pipe end is within distance of wall to decide if it is a valid candidate for selection i.e. pipe stops at wall. Probably also you could select system and automatically add all outlets if you pick also the wall(s) they end at (going one step further). 

 

If the pipe isn't there then the orientation is any direction you want. From a structural preference standpoint the shortest distance through a wall is perpendicular (face normal).

0 Likes
Message 8 of 9

jeremytammik
Autodesk
Autodesk

It may be easier to place the fittings first, exactly where you want them, and then add the pipes afterwards.

 

Please study the series of different approaches I tried out to implement a rolling offset:

 

http://thebuildingcoder.typepad.com/blog/2014/01/final-rolling-offset-using-pipecreate.html

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 9

ahmed.errazak
Enthusiast
Enthusiast

Yes the Global Point would be a solution, but only for part of the problem!
see sketch
that would be for the upper part (from 0 ° to 180 °)
but I would be stuck for the lower part (from 180 ° to 360 °)

Angle and Orientation.PNG

 

0 Likes