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

            try
            {
                #region 2.4 Retrieve all doors, move them and widen them:
                FilteredElementCollector doors = LabUtils.GetFamilyInstances(
                    doc, BuiltInCategory.OST_Doors);

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Move Doors Up");

                    // move doors up 0.2 feet:

                    XYZ v = 0.2 * XYZ.BasisZ;

                    foreach (FamilyInstance door in doors)
                    {
                        //doc.Move( door, v ); // 2011
                        ElementTransformUtils.MoveElement(doc, door.Id, v); // 2012

                        // widen doors by one foot by changing parameter value:

                        Parameter p = door.Symbol.get_Parameter(
                            BuiltInParameter.WINDOW_WIDTH);

                        if (null != p)
                        {
                            double width = p.AsDouble();
                            width += 1.0;
                            p.Set(width);
                        }
                    }
                    tx.Commit();
                }
                return(Result.Succeeded);

                #endregion // 2.4 Retrieve all doors, move them and widen them
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }