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: 

Get Coordinate value of Spot Coordinate

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
cherrytruongmyhoa
2212 Views, 7 Replies

Get Coordinate value of Spot Coordinate

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:

Capture.PNG

Thank you :).

 

Best Regards,

 

Ninh Truong

7 REPLIES 7
Message 2 of 8

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

 

 



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

Message 3 of 8

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 :(. 

2.PNG

Message 4 of 8

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

 

 

 



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

Message 5 of 8

Hi @jeremytammik ,

 

Thank you for your suggestion. I will try to dig in a bit more to find the solution :). 

 

Best Regards,

 

Ninh Truong

 

Message 6 of 8

Did you succeed?

 

What does your final solution look like, please?

 

Thank you!

 



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

Message 7 of 8

Dear @jeremytammik ,

 

Thanks for your great tutorial. I have success with the code as following image: 

Update Coordinate.gif

 

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 

 

Message 8 of 8

Hi @jeremytammik ,

 

I am sorry for the last gif image not correct, please check this one instead 😄

 

UpdateCoordinateinbatch.gif

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