Exemple #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            #region Determine true north rotation

            Element projectInfoElement
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ProjectBasePoint)
                  .FirstElement();

            BuiltInParameter bipAtn
                = BuiltInParameter.BASEPOINT_ANGLETON_PARAM;

            Parameter patn = projectInfoElement.get_Parameter(
                bipAtn);

            double atn = patn.AsDouble();

            Debug.Print(
                "Angle to north from project info: {0}",
                Util.AngleString(atn));

            #endregion // Determine true north rotation

            //ElementSet els = uidoc.Selection.Elements; // 2014

            ICollection <ElementId> ids = uidoc.Selection.GetElementIds(); // 2015

            if (1 != ids.Count)
            {
                message = "Please select a single element.";
            }
            else
            {
                //ElementSetIterator it = els.ForwardIterator();
                //it.MoveNext();
                //Element e = it.Current as Element; // 2014

                Element e = doc.GetElement(ids.First()); // 2015

                XYZ p;
                if (!Util.GetElementLocation(out p, e))
                {
                    message
                        = "Selected element has no location defined.";

                    Debug.Print(message);
                }
                else
                {
                    string msg
                        = "Selected element location: "
                          + Util.PointString(p);

                    XYZ    pnp;
                    double x, y, pna;

                    foreach (ProjectLocation location
                             in doc.ProjectLocations)
                    {
                        //ProjectPosition projectPosition
                        //  = location.get_ProjectPosition( XYZ.Zero ); // 2017

                        ProjectPosition projectPosition
                            = location.GetProjectPosition(XYZ.Zero); // 2018

                        x   = projectPosition.EastWest;
                        y   = projectPosition.NorthSouth;
                        pnp = new XYZ(x, y, 0.0);
                        pna = projectPosition.Angle;

                        msg +=
                            "\nAngle between project north and true north: "
                            + Util.AngleString(pna);

                        // Transform tr = Transform.get_Rotation( XYZ.Zero, XYZ.BasisZ, pna ); // 2013
                        Transform tr = Transform.CreateRotation(XYZ.BasisZ, pna); // 2014

                        //Transform tt = Transform.get_Translation( pnp ); // 2013
                        Transform tt = Transform.CreateTranslation(pnp); // 2014

                        Transform t = tt.Multiply(tr);

                        msg +=
                            "\nUnrotated element location: "
                            + Util.PointString(tr.OfPoint(p)) + " "
                            + Util.PointString(tt.OfPoint(p)) + " "
                            + Util.PointString(t.OfPoint(p));

                        Util.InfoMsg(msg);
                    }
                }
            }
            return(Result.Failed);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref String message,
            ElementSet elements)
        {
            //Util.ListForgeTypeIds();

            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            Element e = Util.SelectSingleElement(
                uidoc, "a line or wall");

            LocationCurve curve = null;

            if (null == e)
            {
                message = "No element selected";
            }
            else
            {
                curve = e.Location as LocationCurve;
            }

            if (null == curve)
            {
                message = "No curve available";
            }
            else
            {
                XYZ p = curve.Curve.GetEndPoint(0);
                XYZ q = curve.Curve.GetEndPoint(1);

                Debug.WriteLine("Start point "
                                + Util.PointString(p));

                Debug.WriteLine("End point "
                                + Util.PointString(q));

                // the angle between the vectors from the project origin
                // to the start and end points of the wall is pretty irrelevant:

                double a = p.AngleTo(q);
                Debug.WriteLine(
                    "Angle between start and end point vectors = "
                    + Util.AngleString(a));

                XYZ v  = q - p;
                XYZ vx = XYZ.BasisX;
                a = vx.AngleTo(v);
                Debug.WriteLine(
                    "Angle between points measured from X axis = "
                    + Util.AngleString(a));

                XYZ z = XYZ.BasisZ;
                a = vx.AngleOnPlaneTo(v, z);
                Debug.WriteLine(
                    "Angle around measured from X axis = "
                    + Util.AngleString(a));

                if (e is Wall)
                {
                    Wall wall = e as Wall;
                    XYZ  w    = z.CrossProduct(v).Normalize();
                    if (wall.Flipped)
                    {
                        w = -w;
                    }
                    a = vx.AngleOnPlaneTo(w, z);
                    Debug.WriteLine(
                        "Angle pointing out of wall = "
                        + Util.AngleString(a));
                }
            }

            foreach (ProjectLocation location
                     in doc.ProjectLocations)
            {
                //ProjectPosition projectPosition
                //  = location.get_ProjectPosition( XYZ.Zero ); // 2017

                ProjectPosition projectPosition
                    = location.GetProjectPosition(XYZ.Zero); // 2018

                double pna = projectPosition.Angle;
                Debug.WriteLine(
                    "Angle between project north and true north "
                    + Util.AngleString(pna));
            }
            return(Result.Failed);
        }