/// <summary> /// Command Entry Point /// </summary> /// <param name="commandData">Input argument providing access to the Revit application and documents</param> /// <param name="message">Return message to the user in case of error or cancel</param> /// <param name="elements">Return argument to highlight elements on the graphics screen if Result is not Succeeded.</param> /// <returns>Cancelled, Failed or Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; try { bool succeeded = AddParameters(); if (succeeded) { MessageBox.Show("Done. Binding Shared Parameters Succeeded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return Autodesk.Revit.UI.Result.Succeeded; } else { MessageBox.Show("Failed", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); return Autodesk.Revit.UI.Result.Failed; } } catch (Exception ex) { // Failure Message message = ex.Message; return Result.Failed; } }
GraphicsStream(UIApplication app) { m_app = app; m_xformStack = new Stack <Transform>(); m_geomOptionsStack = new Stack <Options>(); m_viewStack = new Stack <View>(); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.doc = this.uiapp.ActiveUIDocument.Document; ModifyScene(uiapp, "Automatic Door Renumber Handler"); }
public static ElementSet CreatedWalls = new ElementSet(); //restore all the walls created by API. #region IExternalCommand Members Implementation public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "CreateWall"); trans.Start(); Autodesk.Revit.UI.UIApplication app = revit.Application; WallType newWallType = GetNewWallType(app); //get WallType from RadioButtonGroup - WallTypeSelector Level newWallLevel = GetNewWallLevel(app); //get Level from Combobox - LevelsSelector List <Curve> newWallShape = GetNewWallShape(app); //get wall Curve from Combobox - WallShapeComboBox String newWallMark = GetNewWallMark(app); //get mark of new wall from Text box - WallMark Wall newWall = null; if ("CreateStructureWall" == this.GetType().Name) //decided by SplitButton { newWall = Wall.Create(app.ActiveUIDocument.Document, newWallShape, newWallType.Id, newWallLevel.Id, true); } else { newWall = Wall.Create(app.ActiveUIDocument.Document, newWallShape, newWallType.Id, newWallLevel.Id, false); } if (null != newWall) { newWall.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).Set(newWallMark); //set new wall's mark CreatedWalls.Insert(newWall); } trans.Commit(); return(Autodesk.Revit.UI.Result.Succeeded); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.doc = this.uiapp.ActiveUIDocument.Document; ModifyScene(uiapp, "Remove Dwg Imports Handler", RemoveDwgImports); }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { // should have a line style "bounce" created in the document before running this m_app = commandData.Application; Get3DView(); if (m_view == null) { TaskDialog.Show("Revit", "A default 3D view (named {3D}) must exist before running this command"); return(Autodesk.Revit.UI.Result.Cancelled); } else { RayTraceBounceForm form = new RayTraceBounceForm(commandData, m_view); form.ShowDialog(); } return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception e) { message = e.ToString(); return(Autodesk.Revit.UI.Result.Failed); } }
protected WallType GetNewWallType(Autodesk.Revit.UI.UIApplication app) { //RibbonPanel myPanel = app.GetRibbonPanels()[0]; RibbonPanel myPanel = app.GetRibbonPanels(Define.RevitToolRibbonTab)[0]; if (!(GetRibbonItemByName(myPanel, "WallTypeSelector") is RadioButtonGroup radioGroupTypeSelector)) { throw new InvalidCastException("Cannot get Wall Type selector!"); } String wallTypeName = radioGroupTypeSelector.Current.ItemText; WallType newWallType = null; FilteredElementCollector collector = new FilteredElementCollector(app.ActiveUIDocument.Document); ICollection <Element> founds = collector.OfClass(typeof(WallType)).ToElements(); foreach (Element elem in founds) { WallType wallType = elem as WallType; if (wallType.Name.StartsWith(wallTypeName)) { newWallType = wallType; break; } } return(newWallType); }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; MessageManager.MessageBuff = new StringBuilder(); try { bool succeeded = AddParameters(); if (succeeded) { MessageBox.Show("Done. Binding Shared Parameters Succeeded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return(Autodesk.Revit.UI.Result.Succeeded); } else { message = MessageManager.MessageBuff.ToString(); return(Autodesk.Revit.UI.Result.Failed); } } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
/// <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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements) { try { Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document"); documentTransaction.Start(); // Get the application of revit Autodesk.Revit.UI.UIApplication revit = commandData.Application; // New a real operation class. ModelLines deal = new ModelLines(revit); // The main deal operation deal.Run(); documentTransaction.Commit(); // if everything goes well, return succeeded. return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception ex) { // If any error, give error information and return failed message = ex.Message; return(Autodesk.Revit.UI.Result.Failed); } }
/// <summary> /// Pick Faces in the current Revit Document. Don't forget to hit the Finished button in the options bar. /// </summary> /// <param name="message">A message to be displayed in the status bar.</param> /// <param name="reset">Resets the node so one can pick new objects.</param> /// <returns name="Faces">List of the selected faces.</returns> public static List <DynElem> Faces( [DefaultArgument("Select elements")] string message, [DefaultArgument("true")] bool reset) { Autodesk.Revit.UI.UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; RevitDoc doc = DocumentManager.Instance.CurrentDBDocument; List <DynElem> elems = new List <DynElem>(); revitSelect.Selection selection = uiapp.ActiveUIDocument.Selection; try { IList <Reference> references = selection.PickObjects(revitSelect.ObjectType.Face, message); foreach (Reference r in references) { DynElem elem = doc.GetElement(r.ElementId).ToDSType(true); elems.Add(elem); } } catch (Autodesk.Revit.Exceptions.OperationCanceledException e) { return(null); } return(elems); }
/// <summary> /// Command Entry Point /// </summary> /// <param name="commandData">Input argument providing access to the Revit application and documents</param> /// <param name="message">Return message to the user in case of error or cancel</param> /// <param name="elements">Return argument to highlight elements on the graphics screen if Result is not Succeeded.</param> /// <returns>Cancelled, Failed or Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; try { bool succeeded = AddParameters(); if (succeeded) { MessageBox.Show("Done. Binding Shared Parameters Succeeded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return(Autodesk.Revit.UI.Result.Succeeded); } else { MessageBox.Show("Failed", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); return(Autodesk.Revit.UI.Result.Failed); } } catch (Exception ex) { // Failure Message message = ex.Message; return(Result.Failed); } }
public Form_DataTransfer(UIApplication uiapp) { m_app = uiapp; m_doc = uiapp.ActiveUIDocument.Document; InitializeComponent(); FindMassInstance(); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.curCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); ModifyScene(uiapp, "Create Design Options", CreateDesignOptions); }
int m_numberOfLayers; // number of Structure Layers #endregion #region Interface implementation /// <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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIApplication revit = commandData.Application; try { // function initialization and find out a slab's Level, Type name, and set the Span Direction properties. bool isInitialization = this.Initialize(revit); if (false == isInitialization) { return(Autodesk.Revit.UI.Result.Failed); } // show a displayForm to display the properties of the slab SlabPropertiesForm slabForm = new SlabPropertiesForm(this); if (DialogResult.OK != slabForm.ShowDialog()) { return(Autodesk.Revit.UI.Result.Cancelled); } } catch (Exception displayProblem) { TaskDialog.Show("Revit", displayProblem.ToString()); return(Autodesk.Revit.UI.Result.Failed); } return(Autodesk.Revit.UI.Result.Succeeded); }
protected CurveArray GetNewWallShape(Autodesk.Revit.UI.UIApplication app) { RibbonPanel myPanel = app.GetRibbonPanels()[0]; Autodesk.Revit.UI.ComboBox comboboxWallShape = GetRibbonItemByName(myPanel, "WallShapeComboBox") as Autodesk.Revit.UI.ComboBox; if (null == comboboxWallShape) { throw new InvalidCastException("Cannot get Wall Shape Gallery!"); } String wallShape = comboboxWallShape.Current.ItemText; if ("SquareWall" == wallShape) { return(GetSquareWallShape(app.Application.Create)); } else if ("CircleWall" == wallShape) { return(GetCircleWallShape(app.Application.Create)); } else if ("TriangleWall" == wallShape) { return(GetTriangleWallShape(app.Application.Create)); } else { return(GetRectangleWallShape(app.Application.Create)); } }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; MessageManager.MessageBuff = new StringBuilder(); try { bool succeeded = AddParameters(); if (succeeded) { return(Autodesk.Revit.UI.Result.Succeeded); } else { message = MessageManager.MessageBuff.ToString(); return(Autodesk.Revit.UI.Result.Failed); } } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
protected Level GetNewWallLevel(Autodesk.Revit.UI.UIApplication app) { //RibbonPanel myPanel = app.GetRibbonPanels()[0]; RibbonPanel myPanel = app.GetRibbonPanels(Define.RevitToolRibbonTab)[0]; if (!(GetRibbonItemByName(myPanel, "LevelsSelector") is Autodesk.Revit.UI.ComboBox comboboxLevel)) { throw new InvalidCastException("Cannot get Level selector!"); } String wallLevel = comboboxLevel.Current.ItemText; //find wall type in document Level newWallLevel = null; FilteredElementCollector collector = new FilteredElementCollector(app.ActiveUIDocument.Document); ICollection <Element> founds = collector.OfClass(typeof(Level)).ToElements(); foreach (Element elem in founds) { Level level = elem as Level; if (level.Name.StartsWith(wallLevel)) { newWallLevel = level; break; } } return(newWallLevel); }
public AllDetailsImportsHandler(UIApplication uiapp, Document toDocument, Document fromDocument, List <View> fromSelectedViews) { this.uiapp = uiapp; this.toDocument = toDocument; this.fromDocument = fromDocument; this.fromSelectedViews = fromSelectedViews; }
public GraphicsStream(UIApplication app) { m_app = app; m_xformStack = new Stack<Transform>(); m_geomOptionsStack = new Stack<Options>(); m_viewStack = new Stack<View>(); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.curCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); ModifyScene(uiapp, "Page Alignment Tool", PageAlignmentTool); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.doc = this.uiapp.ActiveUIDocument.Document; ModifyScene(uiapp, "Set Door Offset", SetDoorOffset); }
/// <summary> /// Construction of the main export dialog. /// </summary> /// <param name="app">The UIApplication that contains a list of all documents.</param> /// <param name="configurationsMap">The configurations to show in the dialog.</param> /// <param name="selectedConfigName">The current selected configuration name.</param> public IFCExport(Autodesk.Revit.UI.UIApplication app, IFCExportConfigurationsMap configurationsMap, String selectedConfigName) { m_configMap = configurationsMap; SetParent(app.MainWindowHandle); InitializeComponent(); RestorePreviousWindow(); currentSelectedSetup.SelectionChanged -= currentSelectedSetup_SelectionChanged; UpdateCurrentSelectedSetupCombo(selectedConfigName); UpdateOpenedProjectsListView(app); #if IFC_OPENSOURCE Title = Properties.Resources.ExportIFC + " (" + IFCUISettings.GetAssemblyVersionForUI() + ")"; #else Title = Properties.Resources.ExportIFC; #endif TheDocument = UpdateOpenedProject(app); int docToExport = GetDocumentExportCount(); updateFileName(); }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIApplication revit = commandData.Application; m_revit = revit; if (!Init()) { // there must be exactly one beam, column or brace selected TaskDialog.Show("Revit", "You should select only one beam, structural column or brace."); return(Autodesk.Revit.UI.Result.Failed); } Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document"); documentTransaction.Start(); MaterialPropertiesForm displayForm = new MaterialPropertiesForm(this); try { displayForm.ShowDialog(); } catch { TaskDialog.Show("Revit", "Sorry that your command failed."); return(Autodesk.Revit.UI.Result.Failed); } documentTransaction.Commit(); return(Autodesk.Revit.UI.Result.Succeeded); }
/// <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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIApplication application = commandData.Application; m_docment = application.ActiveUIDocument.Document; try { // user should select one slab firstly. if (application.ActiveUIDocument.Selection.Elements.Size == 0) { TaskDialog.Show("Revit", "Please select one slab firstly.", TaskDialogCommonButtons.Ok); return(Autodesk.Revit.UI.Result.Cancelled); } // get the selected slab and show its span direction ElementSet elementSet = application.ActiveUIDocument.Selection.Elements; ElementSetIterator elemIter = elementSet.ForwardIterator(); elemIter.Reset(); while (elemIter.MoveNext()) { Floor floor = elemIter.Current as Floor; if (floor != null) { GetSpanDirectionAndSymobls(floor); } } } catch (Exception ex) { message = ex.ToString(); return(Autodesk.Revit.UI.Result.Failed); } return(Autodesk.Revit.UI.Result.Succeeded); }
public FloorCreator(UIApplication application, List <LinkedRoomProperties> selectedLinkedElements) { m_app = application; m_doc = m_app.ActiveUIDocument.Document; selectedLinkedRooms = selectedLinkedElements; }
protected List <Curve> GetNewWallShape(Autodesk.Revit.UI.UIApplication app) { //RibbonPanel myPanel = app.GetRibbonPanels()[0]; RibbonPanel myPanel = app.GetRibbonPanels(Define.RevitToolRibbonTab)[0]; if (!(GetRibbonItemByName(myPanel, "WallShapeComboBox") is Autodesk.Revit.UI.ComboBox comboboxWallShape)) { throw new InvalidCastException("Cannot get Wall Shape Gallery!"); } String wallShape = comboboxWallShape.Current.ItemText; if ("SquareWall" == wallShape) { return(GetSquareWallShape(app.Application.Create)); } else if ("CircleWall" == wallShape) { return(GetCircleWallShape(app.Application.Create)); } else if ("TriangleWall" == wallShape) { return(GetTriangleWallShape(app.Application.Create)); } else { return(GetRectangleWallShape(app.Application.Create)); } }
public void fuckFace(Autodesk.Revit.UI.UIApplication revit) { m_Revit = revit; // Create data generator m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView); FolderBrowserDialog folderDialog = new FolderBrowserDialog(); // Set file name of exported stl string fileName; if (folderDialog.ShowDialog() == DialogResult.OK) { fileName = folderDialog.SelectedPath + "\\buildingPrint.stl"; } else { return; } // Set binary save format SaveFormat saveFormat = SaveFormat.Binary; // Set export range ElementsExportRange exportRange = ElementsExportRange.OnlyVisibleOnes; // Include linked cbIncludeLinked = true; // Export in color cbExportColor = false; // Export in shared coordinates cbExportSharedCoordinates = false; // Set dup to 2 for millimeters dup = DisplayUnitType.DUT_MILLIMETERS; // scan for categories and add each of them to selectedCategories m_CategoryList = m_Generator.ScanCategories(true); List <Category> selectedCategories = m_CategoryList.Values.ToList(); // create settings object to save setting information BIM.STLExport.Settings aSetting = new BIM.STLExport.Settings(saveFormat, exportRange, cbIncludeLinked, cbExportColor, cbExportSharedCoordinates, selectedCategories, dup); // save Revit document's triangular data in a temporary file m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView); // Save STL file DataGenerator.GeneratorStatus succeed = m_Generator.SaveSTLFile(fileName, aSetting); }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIApplication revit = commandData.Application; UIDocument project = revit.ActiveUIDocument; // Find the selection of beams in Revit ElementSet selection = project.Selection.Elements; foreach (Autodesk.Revit.DB.Element e in selection) { FamilyInstance m = e as FamilyInstance; if (null != m) { if (StructuralType.Beam == m.StructuralType) { // Store all the beams the user selected in Revit m_beamCollection.Add(e); } } } if (0 == m_beamCollection.Count) { message = "Can not find any beams."; return(Autodesk.Revit.UI.Result.Failed); } // Make sure all the beams have horizontal analytical line if (!CheckBeamHorizontal()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Search all the wall types in the Revit FilteredElementCollector filteredElementCollector = new FilteredElementCollector(project.Document); filteredElementCollector.OfClass(typeof(WallType)); m_wallTypeCollection = filteredElementCollector.Cast <WallType>().ToList <WallType>(); // Show the dialog for the user select the wall style using (CreateWallsUnderBeamsForm displayForm = new CreateWallsUnderBeamsForm(this)) { if (DialogResult.OK != displayForm.ShowDialog()) { return(Autodesk.Revit.UI.Result.Failed); } } // Create the walls which along and under the path of the beams. if (!BeginCreate(project.Document)) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // If everything goes right, return succeeded. return(Autodesk.Revit.UI.Result.Succeeded); }
/// <summary> /// Initialization and find out a slab's Level, Type name, and set the Span Direction properties. /// </summary> /// <param name="revit">The revit object for the active instance of Autodesk Revit.</param> /// <returns>A value that signifies if your initialization was successful for true or failed for false.</returns> private bool Initialize(Autodesk.Revit.UI.UIApplication revit) { m_slabComponent = new ElementSet(); foreach (ElementId elementId in revit.ActiveUIDocument.Selection.GetElementIds()) { m_slabComponent.Insert(revit.ActiveUIDocument.Document.GetElement(elementId)); } m_document = revit.ActiveUIDocument.Document; // There must be exactly one slab selected if (m_slabComponent.IsEmpty) { // nothing selected TaskDialog.Show("Revit", "Please select a slab."); return(false); } else if (1 != m_slabComponent.Size) { // too many things selected TaskDialog.Show("Revit", "Please select only one slab."); return(false); } foreach (Element e in m_slabComponent) { // If the element isn't a slab, give the message and return failure. // Else find out its Level, Type name, and set the Span Direction properties. if ("Autodesk.Revit.DB.Floor" != e.GetType().ToString()) { TaskDialog.Show("Revit", "A slab should be selected."); return(false); } // Change the element type to floor type m_slabFloor = e as Floor; // Get the layer information from the type object by using the CompoundStructure property // The Layers property is then used to retrieve all the layers m_slabLayerCollection = m_slabFloor.FloorType.GetCompoundStructure().GetLayers(); m_numberOfLayers = m_slabLayerCollection.Count; // Get the Level property by the floor's Level property m_level = (m_document.GetElement(m_slabFloor.LevelId) as Level).Name; // Get the Type name property by the floor's FloorType property m_typeName = m_slabFloor.FloorType.Name; // The span direction can be found using generic parameter access // using the built in parameter FLOOR_PARAM_SPAN_DIRECTION Parameter spanDirectionAttribute; spanDirectionAttribute = m_slabFloor.get_Parameter(BuiltInParameter.FLOOR_PARAM_SPAN_DIRECTION); if (null != spanDirectionAttribute) { // Set the Span Direction property this.SetSpanDirection(spanDirectionAttribute.AsDouble()); } } return(true); }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { m_uiApp = commandData.Application; m_uiDoc = m_uiApp.ActiveUIDocument; // get the target element to be used for the Distance computation ElementSet collection = m_uiDoc.Selection.Elements; Parameter param = null; Autodesk.Revit.DB.XYZ targetPoint = getTargetPoint(m_uiDoc.Selection.Elements); // get all the divided surfaces in the Revit document List <DividedSurface> dsList = GetElements <DividedSurface>(); foreach (DividedSurface ds in dsList) { GridNode gn = new GridNode(); int u = 0; while (u < ds.NumberOfUGridlines) { gn.UIndex = u; int v = 0; while (v < ds.NumberOfVGridlines) { gn.VIndex = v; if (ds.IsSeedNode(gn)) { FamilyInstance familyinstance = ds.GetTileFamilyInstance(gn, 0); if (familyinstance != null) { param = familyinstance.get_Parameter("Distance"); if (param == null) { throw new Exception("Panel family must have a Distance instance parameter"); } else { LocationPoint loc = familyinstance.Location as LocationPoint; XYZ panelPoint = loc.Point; double d = Math.Sqrt(Math.Pow((targetPoint.X - panelPoint.X), 2) + Math.Pow((targetPoint.Y - panelPoint.Y), 2) + Math.Pow((targetPoint.Z - panelPoint.Z), 2)); param.Set(d); // uncomment the following lines to create points and lines showing where the distance measurement is made //ReferencePoint rp = m_doc.FamilyCreate.NewReferencePoint(panelPoint); //Line line = m_app.Create.NewLine(targetPoint, panelPoint, true); //Plane plane = m_app.Create.NewPlane(targetPoint.Cross(panelPoint), panelPoint); //SketchPlane skplane = m_doc.FamilyCreate.NewSketchPlane(plane); //ModelCurve modelcurve = m_doc.FamilyCreate.NewModelCurve(line, skplane); } } } v = v + 1; } u = u + 1; } } return(Autodesk.Revit.UI.Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Autodesk.Revit.UI.UIApplication app = commandData.Application; ThisApplication.thisApp.SetWindowAvibilable(app); return(Result.Succeeded); }
public Levels(Autodesk.Revit.UI.UIApplication app) { InitializeComponent(); m_app = app; InitializeListView(); }
/// <summary> /// Constructor. /// </summary> /// <param name="revit">An application object that contains data related to revit command.</param> public SlabData(UIApplication revit) { m_revit = revit; CreApp = m_revit.Application.Create; // Find out all useful elements. FindElements(); // Get all base slabs. If no slab be found, throw an exception and return cancel. if (!GetAllBaseSlabs()) throw new NullReferenceException("No planar slabs at the base of the building."); }
List<RoomTag> m_roomTags = new List<RoomTag>(); // a list to store all room tags #endregion Fields #region Constructors /// <summary> ///constructor /// </summary> public RoomsData(ExternalCommandData commandData) { m_revit = commandData.Application; // get all the rooms and room tags in the project GetAllRoomsAndTags(); // find out the rooms that without room tag ClassifyRooms(); }
/// <summary> /// constructor. /// </summary> /// <param name="app"> Revit application</param> public DoorSwingData(Autodesk.Revit.UI.UIApplication app) { m_app = app; // store door families in m_doorFamilies. PrepareDoorFamilies(); // add needed shared parameters // if the parameters already added will not add again. DoorSharedParameters.AddSharedParameters(app); }
Autodesk.Revit.UI.UIApplication m_revit; // application of Revit #endregion Fields #region Methods /// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="revit">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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements) { // Set currently executable application to private variable m_revit m_revit = revit.Application; m_elements = elements; Transaction tran = new Transaction(m_revit.ActiveUIDocument.Document, "BeamAndSlabNewParameter"); tran.Start(); // Show UI using (BeamAndSlabParametersForm displayForm = new BeamAndSlabParametersForm(this)) { displayForm.ShowDialog(); } tran.Commit(); return Autodesk.Revit.UI.Result.Succeeded; }
/// <summary> /// Command Entry Point /// </summary> /// <param name="commandData">Input argument providing access to the Revit application and documents</param> /// <param name="message">Return message to the user in case of error or cancel</param> /// <param name="elements">Return argument to highlight elements on the graphics screen if Result is not Succeeded.</param> /// <returns>Cancelled, Failed or Succeeded</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; Document doc = m_app.ActiveUIDocument.Document; if (null == doc) { MessageBox.Show("There's no available document."); return Result.Cancelled; } if (!doc.IsFamilyDocument) { MessageBox.Show("The active document is not a family document."); return Result.Cancelled; } try { bool succeeded = AddParameters(); if (succeeded) { MessageBox.Show("Done. Binding Shared Parameters Succeeded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return Autodesk.Revit.UI.Result.Succeeded; } else { //MessageBox.Show("Failed", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); return Autodesk.Revit.UI.Result.Failed; } } catch (Exception ex) { // Failure Message message = ex.Message; return Result.Failed; } }
public Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { m_uiApp = revit.Application; m_app = m_uiApp.Application; m_uiDoc = m_uiApp.ActiveUIDocument; m_doc = m_uiDoc.Document; TaskDialog.Show( "Test application", "Revit version: " + m_app.VersionBuild ); m_writer = new StreamWriter( @"C:\SRD201483.txt" ); WriteDimensionReferences( 161908 ); WriteElementGeometry( 161900 ); m_writer.Close(); return Result.Succeeded; }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; MessageManager.MessageBuff = new StringBuilder(); try { bool succeeded = AddParameters(); if (succeeded) { return Autodesk.Revit.UI.Result.Succeeded; } else { message = MessageManager.MessageBuff.ToString(); return Autodesk.Revit.UI.Result.Failed; } } catch (Exception e) { message = e.Message; return Autodesk.Revit.UI.Result.Failed; } }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { m_app = commandData.Application; MessageManager.MessageBuff = new StringBuilder(); try { bool succeeded = AddParameters(); if (succeeded) { MessageBox.Show("Done. Binding Shared Parameters Succeeded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return Autodesk.Revit.UI.Result.Succeeded; } else { message = MessageManager.MessageBuff.ToString(); return Autodesk.Revit.UI.Result.Failed; } } catch (Exception e) { message = e.Message; return Autodesk.Revit.UI.Result.Failed; } }
/// <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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIApplication revit = commandData.Application; m_revit = revit; RotateFramingObjectsForm displayForm = new RotateFramingObjectsForm(this); displayForm.StartPosition = FormStartPosition.CenterParent; ElementSet selection = revit.ActiveUIDocument.Selection.Elements; bool isSingle = true; //selection is single object bool isAllFamilyInstance = true; //all is not familyInstance // There must be beams, braces or columns selected if (selection.IsEmpty) { // nothing selected message = "Please select some beams, braces or columns."; return Autodesk.Revit.UI.Result.Failed; } else if (1 != selection.Size) { isSingle = false; try { if (DialogResult.OK != displayForm.ShowDialog()) { return Autodesk.Revit.UI.Result.Cancelled; } } catch (Exception) { return Autodesk.Revit.UI.Result.Failed; } // return Autodesk.Revit.UI.Result.Succeeded; // more than one object selected } // if the selected elements are familyInstances, try to get their existing rotation foreach (Autodesk.Revit.DB.Element e in selection) { FamilyInstance familyComponent = e as FamilyInstance; if (familyComponent != null) { if (StructuralType.Beam == familyComponent.StructuralType || StructuralType.Brace == familyComponent.StructuralType) { // selection is a beam or brace string returnValue = this.FindParameter(AngleDefinitionName, familyComponent); displayForm.rotationTextBox.Text = returnValue.ToString(); } else if (StructuralType.Column == familyComponent.StructuralType) { // selection is a column Location columnLocation = familyComponent.Location; LocationPoint pointLocation = columnLocation as LocationPoint; double temp = pointLocation.Rotation; string output = (Math.Round(temp * 180 / (Math.PI), 3)).ToString(); displayForm.rotationTextBox.Text = output; } else { // other familyInstance can not be rotated message = "It is not a beam, brace or column."; elements.Insert(familyComponent); return Autodesk.Revit.UI.Result.Failed; } } else { if (isSingle) { message = "It is not a FamilyInstance."; elements.Insert(e); return Autodesk.Revit.UI.Result.Failed; } // there is some objects is not familyInstance message = "They are not FamilyInstances"; elements.Insert(e); isAllFamilyInstance = false; } } if (isSingle) { try { if (DialogResult.OK != displayForm.ShowDialog()) { return Autodesk.Revit.UI.Result.Cancelled; } } catch (Exception) { return Autodesk.Revit.UI.Result.Failed; } } if (isAllFamilyInstance) { return Autodesk.Revit.UI.Result.Succeeded; } else { //output error information return Autodesk.Revit.UI.Result.Failed; } }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { // should have a line style "bounce" created in the document before running this m_app = commandData.Application; Get3DView(); if (m_view == null) { MessageBox.Show("A default 3D view (named {3D}) must exist before running this command"); return Autodesk.Revit.UI.Result.Cancelled; } else { RayTraceBounceForm form = new RayTraceBounceForm(commandData, m_view); form.ShowDialog(); } return Autodesk.Revit.UI.Result.Succeeded; } catch (Exception e) { message = e.ToString(); return Autodesk.Revit.UI.Result.Failed; } }
/// <summary> /// Constructor /// </summary> /// <param name="commandData">Revit application</param> /// <param name="v">3D View</param> public RayTraceBounceForm(ExternalCommandData commandData, Autodesk.Revit.DB.View3D v) { InitializeComponent(); string logFile = AssemblyName.Replace(".dll", DateTime.Now.ToString("yyyyMMddhhmmss") + ".log"); if (File.Exists(logFile)) File.Delete(logFile); m_txtListener = new TextWriterTraceListener(logFile); Trace.Listeners.Add(m_txtListener); m_app = commandData.Application; m_doc = commandData.Application.ActiveUIDocument.Document; m_view = v; UpdateData(true); // Delete lines it created DeleteLines(); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="revit">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 Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, Autodesk.Revit.DB.ElementSet elements) { m_revit = revit.Application; Transaction tran = new Transaction(m_revit.ActiveUIDocument.Document, "CreateBeamsColumnsBraces"); tran.Start(); try { //if initialize failed return Result.Failed bool initializeOK = Initialize(); if (!initializeOK) { tran.RollBack(); return Autodesk.Revit.UI.Result.Failed; } using (CreateBeamsColumnsBracesForm displayForm = new CreateBeamsColumnsBracesForm(this)) { if (displayForm.ShowDialog() != DialogResult.OK) { tran.RollBack(); return Autodesk.Revit.UI.Result.Cancelled; } } tran.Commit(); return Autodesk.Revit.UI.Result.Succeeded; } catch(Exception ex) { message = ex.Message; tran.RollBack(); return Autodesk.Revit.UI.Result.Failed; } }
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements) { if (dynamoBench != null) { dynamoBench.Focus(); return Result.Succeeded; } //SplashScreen splashScreen = null Window splashScreen = null; try { //create a log file string tempPath = System.IO.Path.GetTempPath(); string logPath = Path.Combine(tempPath, "dynamoLog.txt"); if (File.Exists(logPath)) File.Delete(logPath); tw = new StreamWriter(logPath); tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString()); m_revit = revit.Application; m_doc = m_revit.ActiveUIDocument; #region default level Level defaultLevel = null; FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document); fecLevel.OfClass(typeof(Level)); defaultLevel = fecLevel.ToElements()[0] as Level; #endregion dynRevitSettings.Revit = m_revit; dynRevitSettings.Doc = m_doc; dynRevitSettings.DefaultLevel = defaultLevel; dynSettings.Writer = tw; IdlePromise.ExecuteOnIdle(new Action( delegate { try{ //get window handle IntPtr mwHandle = Process.GetCurrentProcess().MainWindowHandle; //prepare and show splash //splashScreen = new SplashScreen(Assembly.GetExecutingAssembly(), "splash.png"); splashScreen = new DynamoSplash(); //splashScreen.Show(false, true); //show the window var dynamoController = new DynamoController_Revit(DynamoRevitApp.updater); dynamoBench = dynamoController.Bench; //set window handle and show dynamo new System.Windows.Interop.WindowInteropHelper(dynamoBench).Owner = mwHandle; if (System.Windows.Forms.SystemInformation.MonitorCount > 1) { dynamoBench.WindowStartupLocation = WindowStartupLocation.Manual; System.Drawing.Rectangle bounds = System.Windows.Forms.Screen.AllScreens[1].Bounds; dynamoBench.Left = bounds.X; dynamoBench.Top = bounds.Y; dynamoBench.Loaded += new RoutedEventHandler(dynamoForm_Loaded); } else { //System.Drawing.Rectangle bounds = System.Windows.Forms.Screen.AllScreens[0].Bounds; //dynamoForm.Left = bounds.X; //dynamoForm.Top = bounds.Y; dynamoBench.WindowStartupLocation = WindowStartupLocation.CenterOwner; } dynamoBench.Show(); dynamoBench.Closed += new EventHandler(dynamoForm_Closed); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } } )); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); if (tw != null) { tw.WriteLine(ex.Message); tw.WriteLine(ex.StackTrace); tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString()); tw.Close(); } return Result.Failed; } return Autodesk.Revit.UI.Result.Succeeded; }
public dynElementSettings(Autodesk.Revit.UI.UIApplication app, Autodesk.Revit.UI.UIDocument doc, Element dynVolatile, Element dynPersistent, Element dynX, Element dynY, Element dynZ, FamilySymbol defaultFraming, Level defaultLevel, DynamoWarningSwallower warningSwallower, Transaction t) { this.dynX = dynX; this.dynY = dynY; this.dynZ = dynZ; this.dynPersistent = dynPersistent; this.dynVolatile = dynVolatile; this.revit = app; this.doc = doc; this.defaultFraming = defaultFraming; this.defaultLevel = defaultLevel; this.warningSwallower = warningSwallower; this.trans = t; }
///<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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { m_revit = commandData.Application; Transaction tran = new Transaction(m_revit.ActiveUIDocument.Document, "CurvedBeam"); tran.Start(); // if initialize failed return Result.Failed bool initializeOK = Initialize(); if (!initializeOK) { return Autodesk.Revit.UI.Result.Failed; } // pop up new beam form CurvedBeamForm displayForm = new CurvedBeamForm(this); displayForm.ShowDialog(); tran.Commit(); return Autodesk.Revit.UI.Result.Succeeded; }
double m_northSouth; //North to South offset #endregion Fields #region Constructors /// <summary> /// constructor /// </summary> /// <param name="commandData">the ExternalCommandData reference</param> public CoordinateSystemData(ExternalCommandData commandData) { m_command = commandData; m_application = m_command.Application; }
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements) { try { //create a log file string tempPath = System.IO.Path.GetTempPath(); string logPath = Path.Combine(tempPath, "dynamoLog.txt"); if (File.Exists(logPath)) File.Delete(logPath); tw = new StreamWriter(logPath); tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString()); m_revit = revit.Application; m_doc = m_revit.ActiveUIDocument; trans = new Transaction(m_doc.Document, "Dynamo"); trans.Start(); FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions(); failOpt.SetFailuresPreprocessor(new DynamoWarningSwallower()); trans.SetFailureHandlingOptions(failOpt); m_revit.Idling += new EventHandler<IdlingEventArgs>(OnIdling); #region default level Level defaultLevel = null; FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document); fecLevel.OfClass(typeof(Level)); for (int i = 0; i < fecLevel.ToElements().Count; i++) { defaultLevel = fecLevel.ToElements()[i] as Level; break; } #endregion DynamoWarningSwallower swallow = new DynamoWarningSwallower(); dynElementSettings.SharedInstance.Revit = m_revit; dynElementSettings.SharedInstance.Doc = m_doc; dynElementSettings.SharedInstance.DefaultLevel = defaultLevel; dynElementSettings.SharedInstance.WarningSwallower = swallow; dynElementSettings.SharedInstance.MainTransaction = trans; dynElementSettings.SharedInstance.Writer = tw; //dynElementSettings settings = new dynElementSettings(m_revit, m_doc, //defaultLevel, swallow, trans); //show the log dynamoForm = new dynBench(); //get the window handle Process process = Process.GetCurrentProcess(); new System.Windows.Interop.WindowInteropHelper(dynamoForm).Owner = process.MainWindowHandle; dynamoForm.Show(); if (dynamoForm.DialogResult.HasValue && dynamoForm.DialogResult.Value == false) //the WPF false is "cancel" { tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString()); tw.Close(); return Autodesk.Revit.UI.Result.Cancelled; } } catch (Exception e) { trans.Dispose(); Debug.WriteLine(e.Message + ":" + e.StackTrace); Debug.WriteLine(e.InnerException); message = e.Message + " : " + e.StackTrace; if (tw != null) { tw.WriteLine(e.Message); tw.WriteLine(e.StackTrace); tw.Close(); } return Autodesk.Revit.UI.Result.Failed; } trans.Commit(); return Autodesk.Revit.UI.Result.Succeeded; }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_app = commandData.Application; m_doc = commandData.Application.ActiveUIDocument.Document; if (null == m_doc) { message = "There is no active document."; return Autodesk.Revit.UI.Result.Failed; } if (!m_doc.IsFamilyDocument) { message = "Current document is not a family document."; return Autodesk.Revit.UI.Result.Failed; } // Get the view where the dwg file will be imported View view = GetView(); if (null == view) { message = "Opened wrong template file, please use the provided family template file."; return Autodesk.Revit.UI.Result.Failed; } // The dwg file which will be imported string AssemblyDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string DWGFile = "Desk.dwg"; string DWGFullPath = Path.Combine(AssemblyDirectory, DWGFile); Transaction transaction = new Transaction(m_doc, "DWGFamilyCreation"); transaction.Start(); // Import the dwg file into current family document DWGImportOptions options = new DWGImportOptions(); options.Placement = Autodesk.Revit.DB.ImportPlacement.Origin; options.OrientToView = true; ElementId elementId = null; m_doc.Import(DWGFullPath, options, view, out elementId); // Add type parameters to the family AddParameters(DWGFile); transaction.Commit(); } catch (Exception ex) { message = ex.ToString(); return Autodesk.Revit.UI.Result.Failed; } return Autodesk.Revit.UI.Result.Succeeded; }
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Autodesk.Revit.UI.UIApplication revit = commandData.Application; m_revit = revit; if (!Init()) { // there must be exactly one beam, column or brace selected MessageBox.Show("You should select only one beam, structural column or brace."); return Autodesk.Revit.UI.Result.Failed; } Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document"); documentTransaction.Start(); MaterialPropertiesForm displayForm = new MaterialPropertiesForm(this); try { displayForm.ShowDialog(); } catch { MessageBox.Show("Sorry that your command failed."); return Autodesk.Revit.UI.Result.Failed; } documentTransaction.Commit(); return Autodesk.Revit.UI.Result.Succeeded; }
public Autodesk.Revit.UI.Result Execute( Autodesk.Revit.UI.ExternalCommandData cmdData, ref string msg, ElementSet elems ) { m_app = cmdData.Application; Snoop.CollectorExts.CollectorExt.m_app = cmdData.Application; Snoop.CollectorExts.CollectorExt.m_activeDoc = cmdData.Application.ActiveUIDocument.Document; // TBD: see note in CollectorExt.cs Autodesk.Revit.UI.Result result; try { // Since we dont have an "App" as such, there is no // app-wide data - so just create tests for the duration // of the cmd and then destroy them CreateAndAddTests(); Test.TestForm form = new Test.TestForm( RevitLookupTestFuncs.RegisteredTestFuncs() ); if( form.ShowDialog() == DialogResult.OK ) form.DoTest(); result = Autodesk.Revit.UI.Result.Succeeded; } catch( System.Exception e ) { // we want to catch it so we can see the problem, otherwise it just silently bails out /*System.Exception innerException = e.InnerException; while (innerException != null) { innerException = innerException.InnerException; } msg = innerException.Message;*/ msg = e.Message; MessageBox.Show( msg ); result = Autodesk.Revit.UI.Result.Failed; } finally { // if an exception happens anywhere, clean up before quitting RemoveAndFreeTestFuncs(); } return result; }
/// <summary> /// The top level command. /// </summary> /// <param name="revit">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 Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, Autodesk.Revit.DB.ElementSet elements) { // Initialization m_app = revit.Application; m_doc = revit.Application.ActiveUIDocument.Document; // Find a 3D view to use for the ray tracing operation Get3DView(); Selection selection = revit.Application.ActiveUIDocument.Selection; List<Wall> wallsToCheck = new List<Wall>(); // If wall(s) are selected, process them. if (selection.Elements.Size > 0) { foreach (Autodesk.Revit.DB.Element e in selection.Elements) { if (e is Wall) { wallsToCheck.Add((Wall)e); } } if (wallsToCheck.Count <= 0) { message = "No walls were found in the active document selection"; return Result.Cancelled; } } // Find all walls in the document and process them. else { FilteredElementCollector collector = new FilteredElementCollector(m_doc); FilteredElementIterator iter = collector.OfClass(typeof(Wall)).GetElementIterator(); iter.Reset(); while (iter.MoveNext()) { wallsToCheck.Add((Wall)iter.Current); } } // Execute the check for embedded columns CheckWallsForEmbeddedColumns(wallsToCheck); // Process the results, in this case set the active selection to contain all embedded columns if (m_allColumnsOnWalls.Count > 0) { foreach (ElementId id in m_allColumnsOnWalls) { ElementId familyInstanceId = id; Autodesk.Revit.DB.Element familyInstance = m_doc.get_Element(familyInstanceId); selection.Elements.Add(familyInstance); } } return Result.Succeeded; }