예제 #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application and documnet objects
            UIApplication uiapp = commandData.Application;
            Document      doc   = uiapp.ActiveUIDocument.Document;

            try
            {
                //Define a reference Object to accept the pick result
                Reference pickedref = null;

                //Pick a group
                Selection       sel       = uiapp.ActiveUIDocument.Selection;
                GroupPickFilter selFilter = new GroupPickFilter();
                pickedref = sel.PickObject(ObjectType.Element, selFilter, "Please select a group");

                Element elem = doc.GetElement(pickedref);

                Group group = elem as Group;

                // Get the group center point
                XYZ origin = GetElementCenter(group);

                // Get the room that the picked group is located in
                Room room = GetRoomOfGroup(doc, origin);

                XYZ sourceCenter = GetRoomCenter(room);

                string coords =
                    "X = " + sourceCenter.X + "\r\n" +
                    "Y = " + sourceCenter.Y + "\r\n" +
                    "Z = " + sourceCenter.Z + "\r\n";

                TaskDialog.Show("Source room Center", coords);

                //Pick point
                //XYZ point = sel.PickPoint("Please pick a point to place group");

                //Place the group
                Transaction trans = new Transaction(doc);
                trans.Start("Lab");

                //doc.Create.PlaceGroup(point, group.GroupType);

                // Calculate the new Group position
                XYZ groupLocation = sourceCenter + new XYZ(20, 0, 0);
                doc.Create.PlaceGroup(groupLocation, group.GroupType);

                trans.Commit();
            } catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }

            return(Result.Succeeded);
        }
예제 #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application and documnet objects
            UIApplication uiapp = commandData.Application;
            Document      doc   = uiapp.ActiveUIDocument.Document;

            try
            {
                //Define a reference Object to accept the pick result
                Reference pickedRef = null;

                //Pick a group
                Selection sel = uiapp.ActiveUIDocument.Selection;

                //pickedref = sel.PickObject(ObjectType.Element, "Please select a group");
                GroupPickFilter selFilter = new GroupPickFilter();

                pickedRef = sel.PickObject(ObjectType.Element, selFilter,
                                           "Please select a group");

                Element elem = doc.GetElement(pickedRef);

                Group group = elem as Group;

                // Get the group's center point
                XYZ origin = GetElementCenter(group);

                // Get the room that the picked group is located in
                Room room = GetRoomOfGroup(doc, origin);

                // Get the room's center point
                XYZ sourceCenter = GetRoomCenter(room);
                //string coords =
                //  "X = " + sourceCenter.X.ToString() + "\r\n" +
                //  "Y = " + sourceCenter.Y.ToString() + "\r\n" +
                //  "Z = " + sourceCenter.Z.ToString();
                //TaskDialog.Show("Source room Center", coords);

                // Ask the user to pick target rooms
                RoomPickFilter    roomPickFilter = new RoomPickFilter();
                IList <Reference> rooms          =
                    sel.PickObjects(
                        ObjectType.Element,
                        roomPickFilter,
                        "Select target rooms for duplicate furniture group");

                ////Pick point
                //XYZ point = sel.PickPoint("Please pick a point to place group");

                //Place the group
                Transaction trans = new Transaction(doc);

                trans.Start("Lab");

                PlaceFurnitureInRooms(doc, rooms, sourceCenter, group.GroupType, origin);

                trans.Commit();

                return(Result.Succeeded);
            }
            //If the user right-clicks or presses Esc, handle the exception
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            //Catch other errors
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }