Is there any good method for get destination's XYZ?

Is there any good method for get destination's XYZ?

holyhuman1
Contributor Contributor
971 Views
7 Replies
Message 1 of 8

Is there any good method for get destination's XYZ?

holyhuman1
Contributor
Contributor

I know my Origin(XYZ), direction(maybe Basis.Z) and  how far from destination(distance). please let me know how to get the destination XYZ in this case.. Is there any good method in Revit API for this?

 

Thank you 4 reading this.

0 Likes
Accepted solutions (2)
972 Views
7 Replies
Replies (7)
Message 2 of 8

jeremy_tammik
Alumni
Alumni
Accepted solution

Reading your question, I assume you are pretty new to both the Revit API and programming in general.

 

I would strongly recommend getting some basic grounding in both programming in general and the .NET API specifically before trying to do anything at all in Revit.

 

Once you have some fundamental grounding, please work through the Revit API getting started material:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

It also makes some suggestions on what to learn before getting into the Revit API proper.

 

The answer to your question is simple: 

  

      XYZ origin = new XYZ( 123, 456, 789 );
      XYZ distance = new XYZ( 1.1, 2.2, 3.3 );
      XYZ destination = origin + distance;

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 8

holyhuman1
Contributor
Contributor

It is honor to get the answer from you, jeremy! I will try to do your advise, thank you.

but am.. the distance i have is feet( or mm). are there way to change feet to XYZ?  because of below comment.

====

 XYZ distance = new XYZ( 1.1, 2.2, 3.3 );  

====

 

As you mentioned, Im pretty new in REVIT API. I will try to learn it very hard.  lol

 

Thank you .

0 Likes
Message 4 of 8

jeremy_tammik
Alumni
Alumni

Thank you for your appreciation!

 

1 foot equals 12 inches.

 

1 inch equals 25.4 millimetres.

 

All internal Revit database length measurements are in feet.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 8

holyhuman1
Contributor
Contributor

I finally found the solution how to change distance to XYZ. thank you jeremy.

For others, I would to like to write it here. as you know, it is newbie's way. lol

 

=============

int distance = 10000;

 

double dis_feet = UnitUtils.ConvertToInternalUnits(distance, DisplayUnitType.DUT_MILLIMETERS);

 

double vec_x = Convert.ToDouble((MY_DIRECTION).BasisZ.X);
double vec_y = Convert.ToDouble((MY_DIRECTION).BasisZ.Y);
double vec_z = Convert.ToDouble((MY_DIRECTION).BasisZ.Z);

 

double vecsize = Math.Sqrt((vec_x*vec_x) + (vec_y * vec_y) + (vec_z * vec_z));

 

double disx = (dis_feet / vecsize) * vec_x;
double disy = (dis_feet / vecsize) * vec_y;
double disz = (dis_feet / vecsize) * vec_z;

 

XYZ destina_point = new XYZ(Convert.ToDouble((MY_LOCATION).Origin.X) + disx, Convert.ToDouble((MY_LOCATION).Origin.Y) + disy, Convert.ToDouble((MY_LOCATION).Origin.Z) + disz);

 

============

Message 6 of 8

jeremy_tammik
Alumni
Alumni

Thank you for sharing your current solution.

 

I would encourage you to explore further how to use point and vector operations to achieve the same thing with much less code, and much more readably, e.g., like this:

  

      int distance_in_mm = 10000;
      double one_inch = 25.4;
      double one_foot = 12 * one_inch;
      double distance_in_foot = distance_in_mm / one_foot;

      XYZ myDirection = new XYZ( 1, 2, 3 ); // or whatever
      double vecsize2 = myDirection.GetLength();
      XYZ disXyz = (distance_in_foot / vecsize2) * myDirection;

      XYZ myLocation = new XYZ( 5, 6, 7 ); // or whatever
      XYZ destPoint = myLocation + disXyz;

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 7 of 8

jeremy_tammik
Alumni
Alumni
Accepted solution

Actually, this would be the standard approach to solve your task:

  

      int distance_in_mm = 10000;
      double one_inch = 25.4;
      double one_foot = 12 * one_inch;
      double distance_in_feet = distance_in_mm / one_foot;
      XYZ myDirection = new XYZ( 1, 2, 3 ); // or whatever
      XYZ myLocation = new XYZ( 5, 6, 7 ); // or whatever
      XYZ destPoint = myLocation 
        + distance_in_feet * myDirection.Normalize();

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 8

holyhuman1
Contributor
Contributor

it was big help! thank you! lol

0 Likes