Esempio n. 1
0
        public Autodesk.Revit.UI.Result Execute
            (Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Get access to the active uidoc and doc
            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Autodesk.Revit.UI.Selection.Selection sel = uidoc.Selection;

            try {
                Reference r =
                    sel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                Element elem = doc.GetElement(r);

                IList <ElementId> elemsWithinBBox = WallJoinerCmd
                                                    .GetWallsIntersectBoundingBox(doc, elem)
                                                    .Select(e => e.Id)
                                                    .ToList();

                sel.SetElementIds(elemsWithinBBox);

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (Exception ex) {
                Autodesk.Revit.UI.TaskDialog.Show("Exception",
                                                  string.Format("Message: {0}\nStackTrace: {1}",
                                                                ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
        public static Face SelectFace(UIApplication uiapp)
        {
            Document doc = uiapp.ActiveUIDocument.Document;

            IEnumerable <Document> doc2 = GetLinkedDocuments(
                doc);

            Autodesk.Revit.UI.Selection.Selection sel
                = uiapp.ActiveUIDocument.Selection;

            Reference pickedRef = sel.PickObject(
                Autodesk.Revit.UI.Selection.ObjectType.PointOnElement,
                "Please select a Face");

            Element elem = doc.GetElement(pickedRef.ElementId);

            Type et = elem.GetType();

            if (typeof(RevitLinkType) == et ||
                typeof(RevitLinkInstance) == et ||
                typeof(Instance) == et)
            {
                foreach (Document d in doc2)
                {
                    if (elem.Name.Contains(d.Title))
                    {
                        Reference pickedRefInLink = pickedRef
                                                    .CreateReferenceInLink();

                        Element myElement = d.GetElement(
                            pickedRefInLink.ElementId);

                        Face myGeometryObject = myElement
                                                .GetGeometryObjectFromReference(
                            pickedRefInLink) as Face;

                        return(myGeometryObject);
                    }
                }
            }
            else
            {
                Element myElement = doc.GetElement(
                    pickedRef.ElementId);

                Face myGeometryObject = myElement
                                        .GetGeometryObjectFromReference(pickedRef)
                                        as Face;

                return(myGeometryObject);
            }
            return(null);
        }
Esempio n. 3
0
        public Autodesk.Revit.DB.Reference SelectElement(Document doc, UIDocument UIdoc)
        {
            Reference selectedelement = null;

            try {
                Autodesk.Revit.UI.Selection.Selection choice = UIdoc.Selection;
                selectedelement = choice.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            } catch (Exception) {
                throw;
            }

            return(selectedelement);
        }
Esempio n. 4
0
        // TBD: as of 04/10/07 - only works on App startup, not dynamically from another command (jma)

        /*public void
         * AddMenu()
         * {
         *  MenuItem rootMenu = m_revitApp.CreateTopMenu("RevitLookup Test Menu Item");
         *
         *  bool success = rootMenu.AddToExternalTools();
         *  if (success) {
         *      MenuItem subItem = rootMenu.Append(MenuItem.MenuType.BasicMenu, "Pick me to call back into RevitLookup", "RevitLookup.dll", "CmdSampleMenuItemCallback");
         *      System.Windows.Forms.MessageBox.Show("Successfully added new menu to the External Tools menu.  Pick the item to demonstrate callback.");
         *  }
         *  else
         *      System.Windows.Forms.MessageBox.Show("Could not add new menu!");
         * }
         *
         * public void
         * AddToolbar()
         * {
         *  Toolbar toolBar = m_revitApp.CreateToolbar();
         *  toolBar.Name = "Jimbo";
         *
         *  if (toolBar != null) {
         *      ToolbarItem tbItem = toolBar.AddItem("RevitLookup.dll", "CmdSampleMenuItemCallback");
         *      System.Windows.Forms.MessageBox.Show("Successfully added new toolbar.  Pick the item to demonstrate callback.");
         *  }
         *  else
         *      System.Windows.Forms.MessageBox.Show("Could not add new toolbar!");
         * }*/

        public void SelectElement()
        {
            Autodesk.Revit.UI.Selection.Selection selSet = m_revitApp.ActiveUIDocument.Selection;

            try
            {
                Autodesk.Revit.DB.Element    elem    = m_revitApp.ActiveUIDocument.Document.GetElement(selSet.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element).ElementId);
                Autodesk.Revit.DB.ElementSet elemSet = m_revitApp.Application.Create.NewElementSet();
                elemSet.Insert(elem);
                Snoop.Forms.Objects form = new Snoop.Forms.Objects(elemSet);
                form.ShowDialog();
            }
            catch (System.Exception)
            {
                System.Windows.Forms.MessageBox.Show("Didn't pick one!");
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Autodesk.Revit.UI.Selection.Selection sel = commandData.Application.ActiveUIDocument.Selection;
            Reference   reference = sel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            Transaction trans     = new Transaction(doc);
            Element     elem      = doc.GetElement(reference);

            trans.Start("Create solid");
            LocationCurve lc = elem.Location as LocationCurve;

            if (lc == null)
            {
                throw new InvalidOperationException("Current element is not a curve-dirven element");
            }
            //Create the sweep path
            var   pathCurveLoop = new CurveLoop();
            Curve curve         = lc.Curve;

            pathCurveLoop.Append(curve);
            //get the point to create a plane for the profile.
            XYZ xyzFirstPoint = curve.GetEndPoint(0);
            //Create the plane
            Transform transform    = curve.ComputeDerivatives(0, true);
            XYZ       xyzDirection = transform.BasisX;
            Plane     profilePlane = Plane.CreateByNormalAndOrigin(xyzDirection.Normalize(), transform.Origin);
            //Create a profile which is a rectangle with height and width of 2000mm and 900mm

            double    dblHeight = 2000 / 304.8;
            double    dblWidth  = 900 / 304.8;
            UV        uvPt0     = new UV(0, 0) - new UV(dblWidth / 2, 0);
            UV        uvPt1     = uvPt0 + new UV(dblWidth, 0);
            UV        uvPt2     = uvPt1 + new UV(0, dblHeight);
            UV        uvPt3     = uvPt2 - new UV(dblWidth, 0);
            XYZ       xVec      = profilePlane.XVec;
            XYZ       yVec      = profilePlane.YVec;
            XYZ       xyzPt0    = profilePlane.Origin + profilePlane.XVec.Multiply(uvPt0.U) + profilePlane.YVec.Multiply(uvPt0.V);
            XYZ       xyzPt1    = profilePlane.Origin + profilePlane.XVec.Multiply(uvPt1.U) + profilePlane.YVec.Multiply(uvPt1.V);
            XYZ       xyzPt2    = profilePlane.Origin + profilePlane.XVec.Multiply(uvPt2.U) + profilePlane.YVec.Multiply(uvPt2.V);
            XYZ       xyzPt3    = profilePlane.Origin + profilePlane.XVec.Multiply(uvPt3.U) + profilePlane.YVec.Multiply(uvPt3.V);
            Line      l1        = Line.CreateBound(xyzPt0, xyzPt1);
            Line      l2        = Line.CreateBound(xyzPt1, xyzPt2);
            Line      l3        = Line.CreateBound(xyzPt2, xyzPt3);
            Line      l4        = Line.CreateBound(xyzPt3, xyzPt0);
            CurveLoop loop      = new CurveLoop();

            loop.Append(l1);
            loop.Append(l2);
            loop.Append(l3);
            loop.Append(l4);
            List <CurveLoop> newloops = new List <CurveLoop>()
            {
                loop
            };
            //Create the swept solid
            Solid sweepSolid = GeometryCreationUtilities.CreateSweptGeometry(pathCurveLoop, 0, lc.Curve.GetEndParameter(0), newloops);
            //Create a directShape to visualize the solid
            DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));

            ds.AppendShape(new Solid[1] {
                sweepSolid
            });
            trans.Commit();
            return(Result.Succeeded);
        }