Hi all,
I am trying to get the North and Earth value of the Spot Coordinate. But when I used Revit Lookup to snoop through all the parameter, I cannot find these information.
So please help me, if you have some experience with this:
Thank you :).
Best Regards,
Ninh Truong
Solved! Go to Solution.
Solved by cherrytruongmyhoa. Go to Solution.
Solved by jeremytammik. Go to Solution.
Have you looked at the Revit API documentation for the SpotDimension class?
https://www.revitapidocs.com/2020/f3c633ac-1595-cb8d-5c1b-66eb3eefb433.htm
It includes a snippet of sample code defining a method called Getinfo_SpotDimension that may just be doing exactly what you ask for by listing the spot dimension location.
By the way, just for the sake of completeness, here is an old article by The Building Coder showing how to create a spot elevation on the top of a beam:
https://thebuildingcoder.typepad.com/blog/2010/01/spot-elevation-creation-on-top-of-beam.html
Hi @jeremytammik ,
Thank you for your response. I have checked the location point of the Spot coordinate, but actually this one is reflect the position compare to origin point of Revit not the Coordinate information as the Spot coordinate show :(.
All lengths stored in the Revit database use imperial feet as units.
Furthermore, you need to take the project transformation into account, e.g., project north, etc.
Please research the topic a little bit yourself!
It has been discussed frequently in the past.
I think the SetoutPoints addin includes code that does that:
https://github.com/jeremytammik/SetoutPoints
GetProjectLocationTransform:
https://github.com/jeremytammik/SetoutPoints/blob/master/SetoutPoints/CmdGeomVertices.cs#L273-L312
Applying it:
https://github.com/jeremytammik/SetoutPoints/blob/master/SetoutPoints/CmdGeomVertices.cs#L550-L558
Hi @jeremytammik ,
Thank you for your suggestion. I will try to dig in a bit more to find the solution :).
Best Regards,
Ninh Truong
Did you succeed?
What does your final solution look like, please?
Thank you!
Dear @jeremytammik ,
Thanks for your great tutorial. I have success with the code as following image:
For the code, first I made the reference code from your guide:
static public Transform GetProjectLocationTransform(Document doc) { // Retrieve the active project location position. ProjectPosition projectPosition = doc.ActiveProjectLocation.GetProjectPosition( XYZ.Zero); // Create a translation vector for the offsets XYZ translationVector = new XYZ( projectPosition.EastWest, projectPosition.NorthSouth, projectPosition.Elevation); Transform translationTransform = Transform.CreateTranslation( translationVector); // Create a rotation for the angle about true north //Transform rotationTransform // = Transform.get_Rotation( XYZ.Zero, // XYZ.BasisZ, projectPosition.Angle ); Transform rotationTransform = Transform.CreateRotation( XYZ.BasisZ, projectPosition.Angle); // Combine the transforms Transform finalTransform = translationTransform.Multiply( rotationTransform); return finalTransform; } static public bool GetBasePoint( Document doc, out XYZ basePoint, out double north) { BuiltInParameter[] bip = new[] { BuiltInParameter.BASEPOINT_EASTWEST_PARAM, BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM, BuiltInParameter.BASEPOINT_ELEVATION_PARAM, BuiltInParameter.BASEPOINT_ANGLETON_PARAM }; FilteredElementCollector col = new FilteredElementCollector(doc) .OfClass(typeof(BasePoint)); Parameter p = null; basePoint = null; north = 0; foreach (BasePoint bp in col) { basePoint = new XYZ( bp.get_Parameter(bip[0]).AsDouble(), bp.get_Parameter(bip[1]).AsDouble(), bp.get_Parameter(bip[2]).AsDouble()); p = bp.get_Parameter(bip[3]); if (null != p) { north = p.AsDouble(); Debug.Print("north {0}", north); break; } } return null != p; }
And then the main Code:
string PileFamilyName = "SelectedFamily"; string XCoordinateParaName = "X_Coordinate"; string YCoordinateParaName = "Y_Coordinate"; int unit = "SelectedUnit"; int precesion = "SelectedPrecesion"; FilteredElementCollector FamilyInstanceCollector = new FilteredElementCollector(document, currentview.Id); List<FamilyInstance> AllPilesInstance = FamilyInstanceCollector.OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>().ToList() .Where(a => a.Category.Name + "_" + a.Symbol.FamilyName == PileFamilyName).ToList(); if (AllPilesInstance.Count > 0) { XYZ basePoint; double north; refcode.GetBasePoint(document, out basePoint, out north); Transform projectLocationTransform = refcode.GetProjectLocationTransform(document); using (Transaction t = new Transaction(document, "Write Coordinate")) { t.Start(); foreach (FamilyInstance singlePile in AllPilesInstance) { LocationPoint point = singlePile.Location as LocationPoint; XYZ r2 = projectLocationTransform.OfPoint(point.Point); double Xcoordinate = 0; double Ycoordinate = 0; if(unit==0) { Xcoordinate = Math.Round( UnitUtils.ConvertFromInternalUnits(r2.X, DisplayUnitType.DUT_METERS),precesion); Ycoordinate = Math.Round( UnitUtils.ConvertFromInternalUnits(r2.Y, DisplayUnitType.DUT_METERS),precesion); } if(unit==1) { Xcoordinate = Math.Round(UnitUtils.ConvertFromInternalUnits(r2.X, DisplayUnitType.DUT_MILLIMETERS),precesion); Ycoordinate = Math.Round( UnitUtils.ConvertFromInternalUnits(r2.Y, DisplayUnitType.DUT_MILLIMETERS),precesion); } Parameter XcoordinatePara = singlePile.Parameters.Cast<Parameter>().ToList().Where(a => a.Definition.Name == XCoordinateParaName).First(); Parameter YcoordinatePara = singlePile.Parameters.Cast<Parameter>().ToList().Where(a => a.Definition.Name == YCoordinateParaName).First(); if (XcoordinatePara.StorageType == StorageType.Double) { XcoordinatePara.Set(Xcoordinate); } else { if (XcoordinatePara.StorageType == StorageType.String) { XcoordinatePara.Set(Xcoordinate.ToString()); } } if (YcoordinatePara.StorageType == StorageType.Double) { YcoordinatePara.Set(Ycoordinate); } else { if (YcoordinatePara.StorageType == StorageType.String) { YcoordinatePara.Set(Ycoordinate.ToString()); } } } t.Commit(); } TaskDialog.Show("Congrats", "Task is accomplished");
I hope that this will help other user to save times for this insance task (if manually do it) :D.
Thanks again @jeremytammik