简体   繁体   中英

How can I take into consideration Revit Project Base Point location when placing instances using Revit API

无需手动移动的位置

[![Correct location when moved from base point location to survey point][2]][2]

基点距测量点的尺寸

I'm in the process of writing a program to show navisworks clash points in Revit, however, i'm finding it difficult to place them at the exact location when the Base point is not (0,0,0). When i manually add the difference in location to the code, it works. How do I solve this programmatically? I understand there is probably a simple calculation to solve but i can't seem to figure it out. I go some ideas from googling around to be no avail. Any ideas how to go about this?

public static XYZ WorldToLocal(Document document, XYZ coordinate, bool millimeters)
        {
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_ProjectBasePoint);
            FilteredElementCollector collector = new FilteredElementCollector(document);
            IList<Element> oProjectBasePoints = collector.WherePasses(filter).ToElements();

            Element oProjectBasePoint = null;

            foreach (Element bp in oProjectBasePoints)
            {
                oProjectBasePoint = bp;
                break;
            }

            double x = oProjectBasePoint.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble();
            double y = oProjectBasePoint.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble();
            double z = oProjectBasePoint.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble();
            double r = oProjectBasePoint.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsDouble();

            XYZ result = new XYZ(
             coordinate.X * Math.Cos(r) - coordinate.Y * Math.Sin(r) ,
             coordinate.X * Math.Sin(r) + coordinate.Y * Math.Cos(r),
             coordinate.Z);

//Code that makes it work
            XYZ newpostion = new XYZ(result.X - 21.943, result.Y +13.410, result.Z);
//ends here
            if (millimeters)
            {
                return newpostion * 304.8;
            }
            return newpostion; 

        }

This returns the location of the survey point to the base point. Solving my question.

   IEnumerable<BasePoint> points = new FilteredElementCollector(document)
                .OfClass(typeof(BasePoint))
                .Cast<BasePoint>();

            XYZ surveypointXYZ = new XYZ();
            foreach (BasePoint bp in points)
            {
                if (bp.IsShared)
                {
                    BoundingBoxXYZ bb = bp.get_BoundingBox(null);
                    surveypointXYZ = bb.Min;

                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM