Esempio n. 1
0
        public static string ToUUID(LBeacon beacon)
        {
            byte[] lonBytes  = BitConverter.GetBytes(beacon.XLocation);
            byte[] latBytes  = BitConverter.GetBytes(beacon.YLocation);
            byte[] floorByte = BitConverter.GetBytes(beacon.ZLocation);

            string[] buffer = new string[4];

            for (int i = 0; i < 2; i++)
            {
                string lonHex = Convert.ToString(lonBytes[i * 2], 16).PadLeft(2, '0') + Convert.ToString(lonBytes[i * 2 + 1], 16).PadLeft(2, '0');
                string latHex = Convert.ToString(latBytes[i * 2], 16).PadLeft(2, '0') + Convert.ToString(latBytes[i * 2 + 1], 16).PadLeft(2, '0');
                buffer[i + 2] = lonHex;
                buffer[i]     = latHex;
            }

            string floorHex = Convert.ToString(floorByte[0], 16).PadLeft(2, '0') +
                              Convert.ToString(floorByte[1], 16).PadLeft(2, '0') +
                              Convert.ToString(floorByte[2], 16).PadLeft(2, '0') +
                              Convert.ToString(floorByte[3], 16).PadLeft(2, '0');

            return(floorHex + "-0000-" + buffer[0] + "-" + buffer[1] + "-0000" + buffer[2] + buffer[3]);
        }
Esempio n. 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument   uidoc = commandData.Application.ActiveUIDocument;
            Document     doc   = uidoc.Document;
            FamilyFilter ff    = new FamilyFilter();

            IList <Reference> sel = uidoc.Selection.PickObjects(ObjectType.Element, ff);

            SiteLocation site = doc.SiteLocation;

            // Angles are in radians when coming from Revit API, so we
            // convert to degrees for display
            const double angleRatio = Math.PI / 180;   // angle conversion factor

            // Get real-word coordinates of the building
            double projectLongitude = site.Longitude / angleRatio;
            double projectLatitude  = site.Latitude / angleRatio;

            // Store the output data on desktop
            string pathLBeacon = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                                 + "\\"
                                 + doc.Title.Remove(doc.Title.Length - 4)
                                 + "_ForLBeacon"
                                 + ".json";

            // Store the output data on desktop
            string pathLaserPointer = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                                      + "\\"
                                      + doc.Title.Remove(doc.Title.Length - 4)
                                      + "_ForLaserPointer"
                                      + ".json";

            // Create a new feature collections object, beacons will be represented by features
            FeatureCollection featuresForLBeacon = new FeatureCollection();

            // Create a new feature collections object, beacons and laser pointers will be represented by features
            FeatureCollection featuresForLaserPointer = new FeatureCollection();

            // Set origin point for Laser pointer
            // Origin point also known as Reference Point or Startup Location,
            // which is the internal project origin and fixed on the plate.
            featuresForLaserPointer.Features.Add(LBeacon.setOriginPointToGeoJSON(0, 0, 0));

            foreach (Reference r in sel)
            {
                try
                {
                    Element        e     = doc.GetElement(r);
                    FamilyInstance fi    = e as FamilyInstance;
                    LocationPoint  lp    = fi.Location as LocationPoint;
                    Level          level = e.Document.GetElement(e.LevelId) as Level;

                    // Create a new XYZ for Laser Pointer using in Revit coordinate system
                    XYZ revitXYZ = new XYZ(lp.Point.X, lp.Point.Y, lp.Point.Z);

                    // Create a new beacon and add it to the feature collection as a feature
                    featuresForLaserPointer.Features.Add(new LBeacon(fi, revitXYZ, level).ToGeoJSONFeature());

                    if (fi.Name != "LaserPointer")
                    {
                        // Translate the Revit coordinate to Real World coordinate
                        Transform TrueNorthTransform   = GetTrueNorthTransform(doc);
                        XYZ       TrueNorthCoordinates = TrueNorthTransform.OfPoint(lp.Point);

                        // Convert feet to meter(Revit coordinate system unit is feet.)
                        double xMeter = Utilities.feetToMeters(TrueNorthCoordinates.X);
                        double yMeter = Utilities.feetToMeters(TrueNorthCoordinates.Y);
                        double zMeter = Utilities.feetToMeters(TrueNorthCoordinates.Z);

                        // Create new latitude/longitude
                        double newLatitude  = projectLatitude + Utilities.MeterToDecimalDegress(yMeter);
                        double newLongitude = projectLongitude + Utilities.MeterToDecimalDegress(xMeter);

                        // Create a new XYZ for LBeacon using in real-world map
                        XYZ geoXYZ = new XYZ(newLongitude, newLatitude, zMeter);

                        // Create a new beacon and add it to the feature collection as a feature
                        featuresForLBeacon.Features.Add(new LBeacon(fi, geoXYZ, level).ToGeoJSONFeature());
                    }
                }
                catch (Exception e)
                {
                    TaskDialog.Show("Revit", e.ToString());
                }
            }

            //Overwrite the original file if action is duplicated
            using (StreamWriter sw = new StreamWriter(pathLBeacon, false))
            {
                // Convert the features collection to GeoJSON and output to external file
                sw.WriteLine(JsonConvert.SerializeObject(featuresForLBeacon));
            }

            //Overwrite the original file if action is duplicated
            using (StreamWriter sw = new StreamWriter(pathLaserPointer, false))
            {
                // Convert the features collection to GeoJSON and output to external file
                sw.WriteLine(JsonConvert.SerializeObject(featuresForLaserPointer));
            }
            return(Result.Succeeded);
        }
Esempio n. 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument   uidoc = commandData.Application.ActiveUIDocument;
            Document     doc   = uidoc.Document;
            FamilyFilter ff    = new FamilyFilter();

            IList <Reference> sel = uidoc.Selection.PickObjects(ObjectType.Element, ff);

            SiteLocation site = doc.SiteLocation;

            // Angles are in radians when coming from Revit API, so we
            // convert to degrees for display
            const double angleRatio = Math.PI / 180;   // angle conversion factor

            // Get real-word coordinates of the building
            double projectLongitude = site.Longitude / angleRatio;
            double projectLatitude  = site.Latitude / angleRatio;

            // Store the output data
            string pathLBeacon = doc.PathName.Remove(doc.PathName.Length - 4) + ".xml";

            // Create a new list of LBeacons
            LBeacons = new List <LBeacon>();

            foreach (Reference r in sel)
            {
                try
                {
                    Element        e     = doc.GetElement(r);
                    FamilyInstance fi    = e as FamilyInstance;
                    LocationPoint  lp    = fi.Location as LocationPoint;
                    Level          level = e.Document.GetElement(e.LevelId) as Level;

                    // Create a new XYZ for Laser Pointer using in Revit coordinate system
                    XYZ revitXYZ = new XYZ(lp.Point.X, lp.Point.Y, lp.Point.Z);

                    // Create a new beacon and add it to the feature collection as a feature
                    LBeacon beacon = new LBeacon(fi, revitXYZ, level);

                    using (Transaction t = new Transaction(doc, "TextNote"))
                    {
                        t.Start("Create");
                        TextNote.Create(doc, uidoc.ActiveView.Id, revitXYZ, beacon.Mark, doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType));
                        t.Commit();
                    }

                    // Translate the Revit coordinate to Real World coordinate
                    Transform TrueNorthTransform   = GetTrueNorthTransform(doc);
                    XYZ       TrueNorthCoordinates = TrueNorthTransform.OfPoint(lp.Point);

                    // Convert feet to meter(Revit coordinate system unit is feet.)
                    double xMeter = Utilities.feetToMeters(TrueNorthCoordinates.X);
                    double yMeter = Utilities.feetToMeters(TrueNorthCoordinates.Y);
                    double zMeter = Utilities.feetToMeters(TrueNorthCoordinates.Z);

                    // Create new latitude/longitude
                    double newLatitude  = projectLatitude + Utilities.MeterToDecimalDegress(yMeter);
                    double newLongitude = projectLongitude + Utilities.MeterToDecimalDegress(xMeter);

                    // Create a new XYZ for LBeacon using in real-world map
                    XYZ geoXYZ = new XYZ(newLongitude, newLatitude, zMeter);

                    // Create a new beacon and add it to the feature collection as a feature
                    LBeacons.Add(new LBeacon(fi, geoXYZ, level));
                    ReNameNeighbor();
                    LBeacons.Sort((x, y) => { return(x.ZLocation.CompareTo(y.ZLocation)); });

                    WriteXml(pathLBeacon, doc.Title);
                }
                catch (Exception e)
                {
                    TaskDialog.Show("Revit", e.ToString());
                }
            }

            return(Result.Succeeded);
        }