Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

convert to survey points

4 REPLIES 4
Reply
Message 1 of 5
sanjaymann
474 Views, 4 Replies

convert to survey points

Dear Members,

 

Help me out with this one:

 

I am extracting four corners of a rectangular column with the following code:

 

ProjectPosition projectPosition = Command.activeDoc.ActiveProjectLocation.get_ProjectPosition(XYZ.Zero);
XYZ translationVector = new XYZ(projectPosition.EastWest, projectPosition.NorthSouth, projectPosition.Elevation);
Transform translationTransform = Transform.get_Translation(translationVector);
Transform rotationTransform = Transform.get_Rotation(XYZ.Zero, XYZ.BasisZ, projectPosition.Angle);
Transform finalTransform = translationTransform.Multiply(rotationTransform);

double xul = 0;
double yul = 0;
double xur = 0;
double yur = 0;
double xll = 0;
double yll = 0;
double xlr = 0;
double ylr = 0;

LocationPoint lp = fi.Location as LocationPoint;
XYZ gotpoint1 = finalTransform.OfPoint(lp.Point);
XYZ gotpoint = new XYZ(lp.Point.X * 304.8, lp.Point.Y * 304.8, 0);

FamilySymbol FmlySmbl = fi.Symbol;
Family Fmly = FmlySmbl.Family;
Document familyDoc = Command.activeDoc.EditFamily(Fmly);
FamilyManager familyManager = familyDoc.FamilyManager;
FamilyParameter familyParamb = familyManager.get_Parameter("b");
FamilyParameter familyParamh = familyManager.get_Parameter("h");
FamilyType type = familyManager.CurrentType;
double b = type.AsDouble(familyParamb).Value * 304.8;
double h = type.AsDouble(familyParamh).Value * 304.8;
double halfb = 0;
double halfh = 0;
halfb = b / 2;
halfh = h / 2;
double angle = Math.Round(lp.Rotation * 180 / Math.PI, 0);

xul = gotpoint.X + (halfb) * Math.Cos(angle * Math.PI / 180) - (halfh) * Math.Sin(angle * Math.PI / 180);
yul = gotpoint.Y + (halfh) * Math.Cos(angle * Math.PI / 180) + (halfb) * Math.Sin(angle * Math.PI / 180);

XYZ trfxul = finalTransform.OfPoint(new XYZ(xul ,yul ,0));
xul = trfxul.X;
yul = trfxul.Y;

xur = gotpoint.X - (halfb) * Math.Cos(angle * Math.PI / 180) - (halfh) * Math.Sin(angle * Math.PI / 180);
yur = gotpoint.Y + (halfh) * Math.Cos(angle * Math.PI / 180) - (halfb) * Math.Sin(angle * Math.PI / 180);

trfxul = finalTransform.OfPoint(new XYZ(xur, yur, 0));
xur = trfxul.X;
yur = trfxul.Y;

xll = gotpoint.X + (halfb) * Math.Cos(angle * Math.PI / 180) + (halfh) * Math.Sin(angle * Math.PI / 180);
yll = gotpoint.Y - (halfh) * Math.Cos(angle * Math.PI / 180) + (halfb) * Math.Sin(angle * Math.PI / 180);

trfxul = finalTransform.OfPoint(new XYZ(xll, yll, 0));
xll = trfxul.X;
yll = trfxul.Y;

xlr = gotpoint.X - (halfb) * Math.Cos(angle * Math.PI / 180) + (halfh) * Math.Sin(angle * Math.PI / 180);
ylr = gotpoint.Y - (halfh) * Math.Cos(angle * Math.PI / 180) - (halfb) * Math.Sin(angle * Math.PI / 180);

trfxul = finalTransform.OfPoint(new XYZ(xlr, ylr, 0));
xlr = trfxul.X;
ylr = trfxul.Y;

 

The above code works perfectly in one project but not in other. The project in which it works perfectly has the following properties as shown in the below image followed by the image showing the properties of the project in which it doesn;t work The only difference between the two that I noticed is that in the first both project point and survey points are same whereas in the second one there is a difference between project point and survey point.

 

first image

 

2.png

 

 

 

second image

 1.png

 

 

 Thanks & Regards

4 REPLIES 4
Message 2 of 5
Scott_Wilson
in reply to: sanjaymann

From a quick look through the code, it looks like you might be mixing your dimensional units. Are the points out by a multiple of 304.8 by chance?

 

Half-way through you are converting from feet to millimetres (parameter values h & b) and then you later apply a transform (with its translation values in feet) to points created using these metric values. I suspect that the error is masked in your first project due to the translation from project to survey points being zero.

 

I'd suggest leaving all dimensions in feet until you need to display / export them.

Message 3 of 5
sanjaymann
in reply to: Scott_Wilson

Yes I am multiplying by 304.8 as revit returns the values in feet but the project is in millimeters.

 

What should I do to resolve the issue.

 

Thanks & Regards

Message 4 of 5
Scott_Wilson
in reply to: sanjaymann

Why do you need to convert into metric during the calculation?

 

I can't see anywhere in the code snippet where you are displaying or exporting the interim values, so just leave them all in feet and let Revit work in its native units. If you need the output values in metric, convert them as the last step.

 

I also just noticed that you are converting the location point rotation into degrees and then round that to the nearest degree. You then convert this rounded value back into radians to perform some trig calcs. This is going to be quite innaccurate and inconsistent, just leave angles in raw radians without rounding.

 

Don't convert / mix units or perform rounding mid-way through a calculation, you are just asking for trouble. If you are uncomfortable working in feet and radians, I'd suggest making the effort to embrace them.

 

 

 

 

 

 

 

 

 

Message 5 of 5
jeremytammik
in reply to: Scott_Wilson

Dear Scott,

 

Thank you for your valuable advice.

 

I fully agree that is really important for all Revit add-in developers to understand, so I added it to the blog as well:

 

http://thebuildingcoder.typepad.com/blog/2014/10/berlin-hackathon-results-3d-viewer-and-web-news.htm...

 

Cheers,

 

Jeremy



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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community