/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData , ref string message, ElementSet elements) { // Get the document from external command data. UIDocument activeDoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.DB.Document doc = activeDoc.Document; if (null == doc) { return(Result.Failed); } try { // Start detailed steel modeling transaction using (FabricationTransaction trans = new FabricationTransaction(doc, false, "Create corner cut")) { // for more details, please consult http://www.autodesk.com/adv-steel-api-walkthroughs-2019-enu Reference eRef = activeDoc.Selection.PickObject(ObjectType.Element, "Pick a plate"); FilerObject filerObj = Utilities.Functions.GetFilerObject(doc, eRef); if (null == filerObj) { return(Result.Failed); } if (!(filerObj is Plate)) { return(Result.Failed); } // Point of reference for the corner cut feature. We use GlobalPoint. GlobalPoint is the point where the plate is being hit when selected. Point3d p1 = new Point3d(eRef.GlobalPoint.X, eRef.GlobalPoint.Y, eRef.GlobalPoint.Z); Plate plate = filerObj as Plate; // Adding the corner cut feature to the plate. Coordinates are scaled from [ft] to [mm] int edgeIndex, vertexIndex; plate.GetEdgeAndVertex(p1 * Utilities.Functions.FEET_TO_MM, out edgeIndex, out vertexIndex); double radius = 35.0; PlateFeatVertFillet plateFillet = new PlateFeatVertFillet(0, (short)vertexIndex, radius); plate.AddFeature(plateFillet); trans.Commit(); } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } return(Result.Succeeded); }
internal PlateVertexCut(AdvanceSteel.Nodes.SteelDbObject element, int vertexFeatureType, List <Property> plateFeatureProperties) { lock (access_obj) { using (var ctx = new SteelServices.DocContext()) { List <Property> defaultData = plateFeatureProperties.Where(x => x.Level == ".").ToList <Property>(); List <Property> postWriteDBData = plateFeatureProperties.Where(x => x.Level == "Z_PostWriteDB").ToList <Property>(); double length1 = 0; double length2 = 0; double radius = 0; if (defaultData.FirstOrDefault <Property>(x => x.Name == "Length1") != null) { length1 = (double)defaultData.FirstOrDefault <Property>(x => x.Name == "Length1").InternalValue; } if (defaultData.FirstOrDefault <Property>(x => x.Name == "Length2") != null) { length2 = (double)defaultData.FirstOrDefault <Property>(x => x.Name == "Length2").InternalValue; } if (defaultData.FirstOrDefault <Property>(x => x.Name == "Radius") != null) { radius = (double)defaultData.FirstOrDefault <Property>(x => x.Name == "Radius").InternalValue; } string existingFeatureHandle = SteelServices.ElementBinder.GetHandleFromTrace(); string elementHandle = element.Handle; FilerObject obj = Utils.GetObject(elementHandle); PlateFeatVertFillet plateFeat = null; if (obj != null && (obj.IsKindOf(FilerObject.eObjectType.kPlate) || obj.IsKindOf(FilerObject.eObjectType.kFoldedPlate))) { if (string.IsNullOrEmpty(existingFeatureHandle) || Utils.GetObject(existingFeatureHandle) == null) { plateFeat = new PlateFeatVertFillet(); plateFeat.FilletType = (FilerObject.eFilletTypes)vertexFeatureType; AtomicElement atomic = obj as AtomicElement; if (defaultData != null) { Utils.SetParameters(plateFeat, defaultData); } atomic.AddFeature(plateFeat); if (postWriteDBData != null) { Utils.SetParameters(plateFeat, postWriteDBData); } } else { plateFeat = Utils.GetObject(existingFeatureHandle) as PlateFeatVertFillet; if (plateFeat != null && plateFeat.IsKindOf(FilerObject.eObjectType.kPlateFeatVertFillet)) { if (defaultData != null) { Utils.SetParameters(plateFeat, defaultData); } if (postWriteDBData != null) { Utils.SetParameters(plateFeat, postWriteDBData); } } else { throw new System.Exception("Not a Plate Feature"); } } } else { throw new System.Exception("No Input Element found"); } Handle = plateFeat.Handle; SteelServices.ElementBinder.CleanupAndSetElementForTrace(plateFeat); } } }