Ejemplo n.º 1
0
        public void When_I_Scan_with_a_FamilyFilter_I_get_the_expected_results()
        {
            // B is in Column family 2
            var expectedRecords = (from r in _allExpectedRecords select r.WithBValue(null)).ToList();

            var client  = new HBaseClient(RequestOptionsFactory.GetDefaultOptions());
            var scanner = new Scanner();
            var filter  = new FamilyFilter(CompareFilter.CompareOp.Equal, new BinaryComparator(Encoding.UTF8.GetBytes(ColumnFamilyName1)));

            scanner.Filter = filter.ToEncodedString();


            ScannerInformation scanInfo = null;

            try
            {
                scanInfo = client.CreateScannerAsync(_tableName, scanner).Result;
                var actualRecords = RetrieveResults(scanInfo).ToList();

                actualRecords.ShouldContainOnly(expectedRecords);
            }
            finally
            {
                if (scanInfo != null)
                {
                    client.DeleteScannerAsync(_tableName, scanInfo).Wait();
                }
            }
        }
Ejemplo n.º 2
0
        public void When_I_Scan_with_a_FamilyFilter_I_get_the_expected_results()
        {
            // B is in column family 2
            List <FilterTestRecord> expectedRecords = (from r in _allExpectedRecords select r.WithBValue(null)).ToList();

            var client  = new HBaseClient(_credentials);
            var scanner = new Scanner();
            var filter  = new FamilyFilter(CompareFilter.CompareOp.Equal, new BinaryComparator(Encoding.UTF8.GetBytes(ColumnFamilyName1)));

            scanner.filter = filter.ToEncodedString();

            ScannerInformation      scanInfo      = client.CreateScanner(_tableName, scanner);
            List <FilterTestRecord> actualRecords = RetrieveResults(scanInfo).ToList();

            actualRecords.ShouldContainOnly(expectedRecords);
        }
Ejemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Create a new feature collections object, beacons will be represented by features
            FeatureCollection features = new FeatureCollection();

            UIDocument        uidoc = commandData.Application.ActiveUIDocument;
            Document          doc   = uidoc.Document;
            FamilyFilter      ff    = new FamilyFilter();
            IList <Reference> sel   = uidoc.Selection.PickObjects(ObjectType.Element, ff);
            //store the output data on desktop
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                          + "\\"
                          + doc.Title.Remove(doc.Title.Length - 4)
                          + ".json";

            //Overwrite the original file if action is duplicated
            using (StreamWriter sw = new StreamWriter(path, false))
            {
                foreach (Reference r in sel)
                {
                    try
                    {
                        Element        e  = doc.GetElement(r);
                        FamilyInstance fi = e as FamilyInstance;
                        LocationPoint  lp = fi.Location as LocationPoint;

                        // Create a new beacon and add it to the feature collection as a feature
                        Beacon beacon = new Beacon(fi, lp);
                        features.Features.Add(beacon.toGeoJSONFeature());
                    }
                    catch (Exception e)
                    {
                        TaskDialog.Show("Revit", e.ToString());
                    }
                }
                // Convert the features collection to GeoJSON and output to external file
                sw.WriteLine(JsonConvert.SerializeObject(features));
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            FamilyFilter      ff       = new FamilyFilter();
            IList <Reference> sel      = uidoc.Selection.PickObjects(ObjectType.Element, ff);
            List <LBeacon>    LBeacons = new List <LBeacon>();

            try
            {
                foreach (Reference r in sel)
                {
                    Element beacon  = doc.GetElement(r);
                    LBeacon lBeacon = new LBeacon();
                    lBeacon.Mark      = beacon.LookupParameter("Mark");
                    lBeacon.Neighbor  = beacon.LookupParameter("Neighbor");
                    lBeacon.Neighbors = lBeacon.Neighbor.AsString().Split('/');
                    LocationPoint locationPoint = beacon.Location as LocationPoint;
                    lBeacon.Point = locationPoint.Point;
                    LBeacons.Add(lBeacon);
                }

                using (Transaction t = new Transaction(doc, "connect"))
                {
                    t.Start("connect");
                    bool isExisted;
                    for (int i = 0; i < LBeacons.Count; i++)
                    {
                        for (int j = i + 1; j < LBeacons.Count; j++)
                        {
                            isExisted = false;
                            foreach (string neighbor in LBeacons[i].Neighbors)
                            {
                                if (neighbor == LBeacons[j].Mark.AsString())
                                {
                                    isExisted = true;
                                }
                            }

                            if (!isExisted)
                            {
                                LBeacons[i].Neighbor.Set(
                                    LBeacons[i].Neighbor.AsString() + LBeacons[j].Mark.AsString() + '/');
                                LBeacons[j].Neighbor.Set(
                                    LBeacons[j].Neighbor.AsString() + LBeacons[i].Mark.AsString() + '/');
                                Line line = Line.CreateBound(LBeacons[i].Point, LBeacons[j].Point);
                                doc.Create.NewDetailCurve(uidoc.ActiveView, line);
                            }
                        }
                    }
                    t.Commit();
                }
            }
            catch (Exception e)
            {
                TaskDialog.Show("Error", e.ToString());
            }

            return(Result.Succeeded);
        }
Ejemplo n.º 5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Create a new feature collections object, beacons will be represented by features
            FeatureCollection features = new FeatureCollection();

            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            FamilyFilter ff = new FamilyFilter();
            IList<Reference> sel = uidoc.Selection.PickObjects(ObjectType.Element, ff);
            //store the output data on desktop
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                + "\\"
                + doc.Title.Remove(doc.Title.Length - 4)
                + ".json";

            //Overwrite the original file if action is duplicated
            using (StreamWriter sw = new StreamWriter(path, false))
            {
                foreach (Reference r in sel)
                {
                    try
                    {
                        Element e = doc.GetElement(r);
                        FamilyInstance fi = e as FamilyInstance;
                        LocationPoint lp = fi.Location as LocationPoint;

                        // Create a new beacon and add it to the feature collection as a feature
                        Beacon beacon = new Beacon(fi, lp);
                        features.Features.Add(beacon.toGeoJSONFeature());
                    }
                    catch (Exception e)
                    {
                        TaskDialog.Show("Revit", e.ToString());

                    }
                }
                // Convert the features collection to GeoJSON and output to external file
                sw.WriteLine(JsonConvert.SerializeObject(features));
            }
            return Result.Succeeded;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }