Exemple #1
2
        /// <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.Application;
             MessageManager.MessageBuff = new StringBuilder();

             try
             {
            bool succeeded = LoadFamiliesAndAddParameters();

            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;
             }
        }
Exemple #2
1
        /// <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;
              }
        }
Exemple #3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Initialize();
            CommandData = commandData;
            //Login
            using(var login = new LoginForm())
            {
                login.ShowDialog();
                if(login.DialogResult == DialogResult.OK)
                {
                    Indexer = new RevitFamilyIndexer(CommandData);
                    var path = Assembly.GetExecutingAssembly().Location;
                    const string str = "CDWKS.RevitAddon.Indexer2012.dll";
                    var str1 = path.Substring(0, path.Length - str.Length);
                    var args = InstanceId.ToString() + " 2012";
                    var oProcess = Process.Start(str1 + "CDWKS.RevitAddOn.ProgressMonitor.exe", args);

                    while (oProcess != null && !oProcess.HasExited)
                    {
                        if (CanIndex())
                        {
                            IndexNext();
                        }
                    }
                }
            }

            return Result.Succeeded;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref String message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              ViewSheet currentSheet
            = doc.ActiveView as ViewSheet;

              foreach( View v in currentSheet.Views )
              {
            // the values returned here do not seem to
            // accurately reflect the positions of the
            // views on the sheet:

            BoundingBoxUV loc = v.Outline;

            Debug.Print(
              "Coordinates of {0} view '{1}': {2}",
              v.ViewType, v.Name,
              Util.PointString( loc.Min ) );
              }

              return Result.Failed;
        }
Exemple #5
0
 public RevitScriptContext(ExternalCommandData commandData, ref string message, ElementSet elements, string scriptName)
 {
     _commandData = commandData;
     _message = message;
     _elements = elements;
     _scriptName = scriptName;
 }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;

              //PickPointsForArea( uidoc );

              XYZ point_in_3d;

              if( PickFaceSetWorkPlaneAndPickPoint(
            uidoc, out point_in_3d ) )
              {
            TaskDialog.Show( "3D Point Selected",
              "3D point picked on the plane"
              + " defined by the selected face: "
              + Util.PointString( point_in_3d ) );

            return Result.Succeeded;
              }
              else
              {
            message = "3D point selection cancelled or failed";
            return Result.Failed;
              }
        }
Exemple #7
0
   public Result Execute(
 ExternalCommandData commandData,
 ref string message,
 ElementSet elements )
   {
       return Result.Succeeded;
   }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              UIDocument uidoc = app.ActiveUIDocument;
              Document doc = uidoc.Document;

              Selection sel = uidoc.Selection;
              string msg = string.Empty;

              foreach( Element e in sel.Elements )
              {
            Wall wall = e as Wall;
            if( null != wall )
            {
              msg += ProcessWall( wall );
            }
              }
              if( 0 == msg.Length )
              {
            msg = "Please select some walls.";
              }
              Util.InfoMsg( msg );
              return Result.Succeeded;
        }
 public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
 {
     string killNameProcess = "Revit";
     Process[] processes = Process.GetProcessesByName(killNameProcess);
     processes.First().Kill();
     return Result.Succeeded;
 }
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = uiApp.ActiveUIDocument;

            try
            {
                if (!doc.IsWorkshared)
                {
                    TaskDialog.Show("Workset 3D View", "Project doesn't have any Worksets.");
                }
                else
                {
                    ViewFamilyType vft = new FilteredElementCollector(doc)
                    .OfClass(typeof(ViewFamilyType))
                    .Cast<ViewFamilyType>()
                    .FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);

                    using (Transaction t = new Transaction(doc, "Workset View Creation"))
                    {
                        t.Start();
                        int i = 0;
                        // Loop through all User Worksets only
                        foreach (Workset wst in new FilteredWorksetCollector(doc)
                            .WherePasses(new WorksetKindFilter(WorksetKind.UserWorkset)))
                        {
                            // Create a 3D View
                            View3D view = View3D.CreateIsometric(doc, vft.Id);

                            // Set the name of the view to match workset
                            view.Name = "WORKSET - " + wst.Name;

                            // Isolate elements in the view using a filter to find elements only in this workset
                            view.IsolateElementsTemporary(new FilteredElementCollector(doc)
                                .WherePasses(new ElementWorksetFilter(wst.Id))
                                .Select(q => q.Id)
                                .ToList());
                            i++;
                        }
                        t.Commit();
                        TaskDialog.Show("Workset 3D View", i.ToString() + " Views Created Successfully!");
                    }
                }
                return Result.Succeeded;
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              UIDocument uidoc = app.ActiveUIDocument;
              Document doc = uidoc.Document;

              List<Element> rooms = new List<Element>();
              if( !Util.GetSelectedElementsOrAll(
            rooms, uidoc, typeof( Room ) ) )
              {
            Selection sel = uidoc.Selection;
            message = ( 0 < sel.GetElementIds().Count )
              ? "Please select some room elements."
              : "No room elements found.";
            return Result.Failed;
              }
              foreach( Room room in rooms )
              {
            BumpOccupancy( room );
              }
              return Result.Succeeded;
        }
Exemple #12
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="commandData">Revit command data</param>
        /// <param name="exportFormat">Format to export</param>
        public ExportDWGData(ExternalCommandData commandData, ExportFormat exportFormat)
            : base(commandData, exportFormat)
        {
            m_exportOptionsData = new ExportBaseOptionsData();

            Initialize();
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              UIDocument uidoc = app.ActiveUIDocument;
              Document doc = uidoc.Document;

              List<Element> rooms = new List<Element>();
              if( !Util.GetSelectedElementsOrAll(
            rooms, uidoc, typeof( Room ) ) )
              {
            Selection sel = uidoc.Selection;
            message = ( 0 < sel.Elements.Size )
              ? "Please select some room elements."
              : "No room elements found.";
            return Result.Failed;
              }
              foreach( Room room in rooms )
              {
            DetermineAdjacentElementLengthsAndWallAreas(
              room );
              }
              return Result.Failed;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Application app = uiapp.Application;
              Document doc = uidoc.Document;

              Transaction tx = new Transaction( doc,
            "Extract Part Atom" );

              tx.Start();

              string familyFilePath
            = "C:/Documents and Settings/All Users"
            + "/Application Data/Autodesk/RAC 2011"
            + "/Metric Library/Doors/M_Double-Flush.rfa";

              string xmlPath = "C:/tmp/ExtractPartAtom.xml";

              app.ExtractPartAtomFromFamilyFile(
            familyFilePath, xmlPath );

              tx.Commit();

              return Result.Succeeded;
        }
Exemple #15
0
        public IExternalCommand.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            SelElementSet selSet = commandData.Application.ActiveDocument.Selection.Elements;
            if (selSet.Size != 1)
            {
                return IExternalCommand.Result.Cancelled;
            }
            ElementSetIterator it = selSet.ForwardIterator();
            if (it.MoveNext())
            {
                Room room = it.Current as Room;
                if (room != null)
                {
                    ParameterSetIterator paraIt = room.Parameters.ForwardIterator();
                    while (paraIt.MoveNext())
                    {
                        Parameter para = paraIt.Current as Parameter;
                        if (para == null) continue;
                        if (para.Definition.Name.Equals("名称"))
                        {
                            para.Set("My Room");
                            break;
                        }
                    }
                }
            }

            return IExternalCommand.Result.Succeeded;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Document doc = commandData.Application
            .ActiveUIDocument.Document;

              FilteredElementCollector collector
            = new FilteredElementCollector( doc );

              collector.OfClass( typeof( Level ) );
              Level level = collector.FirstElement() as Level;

              Transaction t = new Transaction( doc );

              t.Start( "Create unbounded room" );

              FailureHandlingOptions failOpt
            = t.GetFailureHandlingOptions();

              failOpt.SetFailuresPreprocessor(
            new RoomWarningSwallower() );

              t.SetFailureHandlingOptions( failOpt );

              doc.Create.NewRoom( level, new UV( 0, 0 ) );

              t.Commit();

              return Result.Succeeded;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref String message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              Document doc = app.ActiveUIDocument.Document;

              ViewSheet currentSheet
            = doc.ActiveView as ViewSheet;

              //foreach( View v in currentSheet.Views ) // 2014 warning	'Autodesk.Revit.DB.ViewSheet.Views' is obsolete.  Use GetAllPlacedViews() instead.

              foreach( ElementId id in currentSheet.GetAllPlacedViews() ) // 2015
              {
            View v = doc.GetElement( id ) as View;

            // the values returned here do not seem to
            // accurately reflect the positions of the
            // views on the sheet:

            BoundingBoxUV loc = v.Outline;

            Debug.Print(
              "Coordinates of {0} view '{1}': {2}",
              v.ViewType, v.Name,
              Util.PointString( loc.Min ) );
              }

              return Result.Failed;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              Application app = uiapp.Application;

              if( null == _handler )
              {
            _handler
              = new EventHandler<DocumentChangedEventArgs>(
            OnDocumentChanged );

            // Subscribe to DocumentChanged event

            app.DocumentChanged += _handler;
              }
              else
              {
            app.DocumentChanged -= _handler;
            _handler = null;
              }
              return Result.Succeeded;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;

              Application app = uiapp.Application;
              Document doc = uidoc.Document;

              // 'Autodesk.Revit.DB.Document.Mirror(ElementSet, Line)' is obsolete:
              // Use one of the replace methods in ElementTransformUtils.
              //
              //Line line = app.Create.NewLine(
              //  XYZ.Zero, XYZ.BasisX, true ); // 2011
              //
              //ElementSet els = uidoc.Selection.Elements; // 2011
              //
              //doc.Mirror( els, line ); // 2011

              Plane plane = new Plane( XYZ.BasisY, XYZ.Zero ); // 2012

              ICollection<ElementId> elementIds
            = uidoc.Selection.GetElementIds(); // 2012

              ElementTransformUtils.MirrorElements(
            doc, elementIds, plane ); // 2012

              return Result.Succeeded;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
              UIDocument uidoc = app.ActiveUIDocument;
              Document doc = uidoc.Document;

              string msg = string.Empty;

              //Selection sel = uidoc.Selection; // 2014
              //foreach( Element e in sel.Elements ) // 2014

              List<Element> walls = new List<Element>();

              if( Util.GetSelectedElementsOrAll( walls, uidoc, typeof( Wall ) ) )
              {
            foreach( Wall wall in walls )
            {
              msg += ProcessWall( wall );
            }
              }

              if( 0 == msg.Length )
              {
            msg = "Please select some walls.";
              }

              Util.InfoMsg( msg );

              return Result.Succeeded;
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            var dialog = new TaskDialog( "Create DirectShape" )
              {
            MainInstruction = "Select the way you want to create shape"
              };

              dialog.AddCommandLink( TaskDialogCommandLinkId.CommandLink1, "Initial shape builder" );
              dialog.AddCommandLink( TaskDialogCommandLinkId.CommandLink2, "Jeremy's shape builder" );
              dialog.AddCommandLink( TaskDialogCommandLinkId.CommandLink3, "Simple shape builder" );

              switch( dialog.Show() )
              {
            case TaskDialogResult.CommandLink1:
              CreateDirectShapeInitial.Execute1( commandData );
              break;

            case TaskDialogResult.CommandLink2:
              CreateDirectShape.Execute( commandData );
              break;

            case TaskDialogResult.CommandLink3:
              CreateDirectShapeSimple.Execute( commandData );
              break;
              }
              return Result.Succeeded;
        }
Exemple #22
0
        /// <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
            {
                // Verify active document
                if (null == commandData.Application.ActiveUIDocument.Document)
                {
                    message = "Active view is null.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                MainData mainData = new MainData(commandData);
                // Show the dialog
                using (MainForm mainForm = new MainForm(mainData))
                {
                    if (mainForm.ShowDialog() == DialogResult.Cancel)
                    {
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return Autodesk.Revit.UI.Result.Failed;
            }

            return Autodesk.Revit.UI.Result.Succeeded;
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // Find all of the runs and organize them
                doc = commandData.Application.ActiveUIDocument.Document;
                allRuns = FindExisting();
                
                if (allRuns != null && allRuns.Count > 0)
                {
                    RevitServerApp._app.ShowSelectionForm(allRuns, commandData.Application.ActiveUIDocument);
                }
                else
                {
                    TaskDialog.Show("Message", "No existing run elements found.");
                }

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error", ex.Message);
                return Result.Failed;
            }
        }
        /// <summary>
        /// Overload this method to implement and external command within Revit.
        /// </summary>
        /// <returns>
        /// The result indicates if the execution fails, succeeds, or was canceled by user. If it does not
        /// succeed, Revit will undo any changes made by the external command. 
        /// </returns>
        /// <param name="commandData">An ExternalCommandData object which contains reference to Application and View
        /// needed by external command.</param><param name="message">Error message can be returned by external command. This will be displayed only if the command status
        /// was "Failed".  There is a limit of 1023 characters for this message; strings longer than this will be truncated.</param><param name="elements">Element set indicating problem elements to display in the failure dialog.  This will be used
        /// only if the command status was "Failed".</param>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // FIXME: somehow fetch back message after script execution...
            var executor = new ScriptExecutor(commandData, message, elements);

            string source;
            using (var reader = File.OpenText(_scriptSource))
            {
                source = reader.ReadToEnd();
            }

            var result = executor.ExecuteScript(source);
            message = executor.Message;
            switch (result)
            {
                case (int)Result.Succeeded:
                    return Result.Succeeded;
                case (int)Result.Cancelled:
                    return Result.Cancelled;
                case (int)Result.Failed:
                    return Result.Failed;
                default:
                    return Result.Succeeded;
            }
        }
Exemple #25
0
        /// <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)
        {
            try
              {

            // Version
            if (!commandData.Application.Application.VersionName.Contains("2013"))
            {
              message = "This Add-In was built for Revit 2013, please contact CASE for assistance...";
              return Result.Failed;
            }

            // Construct and Display the form
            form_Main frm = new form_Main(commandData);
            frm.ShowDialog();

            // Return Success
            return Result.Succeeded;
              }
              catch (Exception ex)
              {

            // Failure Message
            message = ex.Message;
            return Result.Failed;

              }
        }
        public Result Execute(
            ExternalCommandData revit,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = revit.Application;
              UIDocument uidoc = uiapp.ActiveUIDocument;
              Document doc = uidoc.Document;

              string path = doc.PathName;

              BasicFileInfo info = BasicFileInfo.Extract(
            path );

              DocumentVersion v = info.GetDocumentVersion();

              int n = v.NumberOfSaves;

              Util.InfoMsg( string.Format(
            "Document '{0}' has GUID {1} and {2} save{3}.",
            path, v.VersionGUID, n,
            Util.PluralSuffix( n ) ) );

              return Result.Succeeded;
        }
    public Result Execute(
      ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    {
      // Get the access to the top most objects. 
      UIApplication uiApp = commandData.Application;
      UIDocument uiDoc = uiApp.ActiveUIDocument;
      _app = uiApp.Application;
      _doc = uiDoc.Document;

      // (1) In eailer lab, CommandData command, we 
      // learned how to access to the wallType. i.e., 
      // here we'll take a look at more on the topic 
      // of accessing to elements in the interal rvt 
      // project database. 

      ListFamilyTypes();

      // (2) List instances of specific object class. 
      ListInstances();

      // (3) Find a specific family type. 
      FindFamilyType();

      // (4) Find specific instances, including filtering by parameters. 
      FindInstance();

      // (5) List all elements. 
      ListAllElements();

      // We are done. 

      return Result.Succeeded;
    }
        public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
        {
            Setup(cmdData);

            var exe = new RevitTestExecutive();
            return exe.Execute(cmdData, ref message, elements);
        }
Exemple #29
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="commandData">Revit command data</param>
        /// <param name="exportFormat">Format to export</param>
        public ExportDataWithViews(ExternalCommandData commandData, ExportFormat exportFormat)
            : base(commandData, exportFormat)
        {
            m_selectViewsData = new SelectViewsData(commandData);

            Initialize();
        }
Exemple #30
0
 /// <summary>
 /// Check if the suffix is a number or not
 /// </summary>
 /// <param name="cmddata_p"></param>
 public MainForm(ExternalCommandData cmddata_p)
 {
     this.DataContext   = this;
     this.p_commanddata = cmddata_p;
     InitializeComponent();
 }
 public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
 {
     using (System.Diagnostics.Process.Start(@"https://apidocs.co/apps/revit/" + $"{Revit.ActiveDBApplication?.VersionNumber}#")) { }
     return(Result.Succeeded);
 }
Exemple #32
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            RevitListener.Listener.Deactivate();
            return(Result.Succeeded);
        }
Exemple #33
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            PageAlignmentToolProcessor processor = new PageAlignmentToolProcessor(commandData.Application);

            return(Result.Succeeded);
        }
Exemple #34
0
        Result IExternalCommand.Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // cache admin data
            _appUI = commandData.Application;
            _app   = _appUI.Application;
            _docUI = commandData.Application.ActiveUIDocument;
            _doc   = _docUI.Document;

            try // generic
            {
                // Current View must be Sheet
                ViewSheet sheet = _doc.ActiveView as ViewSheet;
                if (null == sheet)
                {
                    Util.ErrorMsg("Current View is NOT a Sheet!");
                    return(Result.Cancelled);
                }

                // There must be a Floor Plan named "Level 0"
                // which is the "master" to align to
                Viewport vpMaster = null;
                // There must be at least one more Floor Plan
                // View to align (move)
                List <Viewport> vpsSlave = new List <Viewport>();
                // Find them:
                foreach (ElementId idVp in sheet.GetAllViewports())
                {
                    Viewport vp = _doc.GetElement(idVp) as Viewport;
                    ViewRvt  v  = _doc.GetElement(vp.ViewId) as ViewRvt;
                    if (v.ViewType == ViewType.FloorPlan)
                    {
                        if (v.Name.Equals("Level 0", StringComparison
                                          .CurrentCultureIgnoreCase))
                        {
                            vpMaster = vp;
                        }
                        else
                        {
                            vpsSlave.Add(vp);
                        }
                    } //if FloorPlan
                }     //foreeach idVp

                // Check if got them all
                if (null == vpMaster)
                {
                    Util.ErrorMsg("NO 'Level 0' Floor Plan on the Sheet!");
                    return(Result.Cancelled);
                }
                else if (vpsSlave.Count == 0)
                {
                    Util.ErrorMsg("NO other Floor Plans to adjust on the Sheet!");
                    return(Result.Cancelled);
                }

                // Process Master
                // --------------

                XYZ     ptMasterVpCenter = vpMaster.GetBoxCenter();
                ViewRvt viewMaster       = _doc.GetElement(
                    vpMaster.ViewId) as ViewRvt;
                double scaleMaster = viewMaster.Scale;

                // Process Slaves
                // --------------

                foreach (Viewport vpSlave in vpsSlave)
                {
                    XYZ     ptSlaveVpCenter = vpSlave.GetBoxCenter();
                    ViewRvt viewSlave       = _doc.GetElement(
                        vpSlave.ViewId) as ViewRvt;
                    double scaleSlave = viewSlave.Scale;
                    // MUST be the same scale, otherwise can't really overlap
                    if (scaleSlave != scaleMaster)
                    {
                        continue;
                    }

                    // Work out how to move the center of Slave
                    // Viewport to coincide model-wise with Master
                    // (must use center as only Viewport.SetBoxCenter
                    // is provided in API)
                    // We can ignore View.Outline as Viewport.GetBoxOutline
                    // is ALWAYS the same dimensions enlarged by
                    // 0.01 ft in each direction.
                    // This guarantees that the center of View is
                    // also center of Viewport, BUT there is a
                    // problem when any Elevation Symbols outside
                    // the crop box are visible (can't work out why
                    // - BUG?, or how to calculate it all if BY-DESIGN)

                    BoundingBoxXYZ bbm = viewMaster.CropBox;
                    BoundingBoxXYZ bbs = viewSlave.CropBox;

                    // 0) Center points in WCS
                    XYZ wcsCenterMaster = 0.5 * bbm.Min.Add(bbm.Max);
                    XYZ wcsCenterSlave  = 0.5 * bbs.Min.Add(bbs.Max);

                    // 1) Delta (in model's feet) of the slave center w.r.t master center
                    double deltaX = wcsCenterSlave.X - wcsCenterMaster.X;
                    double deltaY = wcsCenterSlave.Y - wcsCenterMaster.Y;

                    // 1a) Scale to Delta in Sheet's paper-space feet
                    deltaX *= 1.0 / (double)scaleMaster;
                    deltaY *= 1.0 / (double)scaleMaster;

                    // 2) New center point for the slave viewport, so *models* "overlap":
                    XYZ newCenter = new XYZ(
                        ptMasterVpCenter.X + deltaX,
                        ptMasterVpCenter.Y + deltaY,
                        ptSlaveVpCenter.Z);
                    vpSlave.SetBoxCenter(newCenter);
                }
            }
            catch (Exception ex)
            {
                Util.ErrorMsg("Generic exception: " + ex.Message);
                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiapp = commandData.Application;
            _uidoc = _uiapp.ActiveUIDocument;
            _doc   = _uidoc.Document;

            _form = new LevelCreationForm();

            if (_form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Retrieve the number of levels and number of basements
                _numOfLvls      = _form.NumOfLevels;
                _numOfBasements = _form.NumOfBasements;
                _totalNumOfLvls = _numOfLvls + _numOfBasements;

                if (_totalNumOfLvls > 0)
                {
                    List <Level> newLevels = CreateNewLevels(_doc);

                    List <ViewPlan> newViewPlans = CreateNewViewPlan(_doc, newLevels);

                    // if "Niveau Ref" exists, delete it
                    Level refLevel =
                        (from lev in new FilteredElementCollector(_doc)
                         .OfClass(typeof(Level))
                         where lev.Name == Default.LEVEL_NAME_REF
                         select lev)
                        .Cast <Level>()
                        .ToList()
                        .FirstOrDefault();

                    if (refLevel != null)
                    {
                        using (Transaction t = new Transaction(_doc, "Delete ref level"))
                        {
                            t.Start();
                            _doc.Delete(refLevel.Id);
                            t.Commit();
                        }
                    }

                    // Add linear dimension to levels
                    Line           line     = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 0, 20));
                    ReferenceArray refArray = new ReferenceArray();
                    foreach (Level level in newLevels)
                    {
                        refArray.Append(level.GetPlaneReference());
                    }

                    using (Transaction t = new Transaction(_doc, "Create dimension"))
                    {
                        t.Start();
                        Dimension levelDimension = _doc.Create.NewDimension(_doc.ActiveView, line, refArray);
                        foreach (DimensionSegment ds in levelDimension.Segments)
                        {
                            ds.IsLocked = true;
                        }
                        t.Commit();
                    }
                }
                return(Result.Succeeded);
            }
            else
            {
                return(Result.Cancelled);
            }
        }
 public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
 {
     using (System.Diagnostics.Process.Start(@"https://developer.rhino3d.com/")) { }
     return(Result.Succeeded);
 }
Exemple #37
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            if (doc.IsFamilyDocument)
            {
                message = "This command can only be used in a project, not in a family file.";
                return(Result.Failed);
            }

            // get the current shared params definition file
            DefinitionFile sharedParamsFile = LabUtils.GetSharedParamsFile(app.Application);

            if (null == sharedParamsFile)
            {
                message = "Error getting the shared params file.";
                return(Result.Failed);
            }
            // get or create the shared params group
            DefinitionGroup sharedParamsGroup = LabUtils.GetOrCreateSharedParamsGroup(
                sharedParamsFile, LabConstants.ParamGroupName);

            if (null == sharedParamsGroup)
            {
                message = "Error getting the shared params group.";
                return(Result.Failed);
            }
            // visible param
            Definition docParamDefVisible = LabUtils.GetOrCreateSharedParamsDefinition(
                sharedParamsGroup, ParameterType.Integer, LabConstants.ParamNameVisible, true);

            if (null == docParamDefVisible)
            {
                message = "Error creating visible per-doc parameter.";
                return(Result.Failed);
            }
            // invisible param
            Definition docParamDefInvisible = LabUtils.GetOrCreateSharedParamsDefinition(
                sharedParamsGroup, ParameterType.Integer, LabConstants.ParamNameInvisible, false);

            if (null == docParamDefInvisible)
            {
                message = "Error creating invisible per-doc parameter.";
                return(Result.Failed);
            }
            // bind the param
            try
            {
                CategorySet catSet = app.Application.Create.NewCategorySet();

                catSet.Insert(doc.Settings.Categories.get_Item(
                                  BuiltInCategory.OST_ProjectInformation));

                Binding binding = app.Application.Create.NewInstanceBinding(catSet);
                doc.ParameterBindings.Insert(docParamDefVisible, binding);
                doc.ParameterBindings.Insert(docParamDefInvisible, binding);
            }
            catch (Exception e)
            {
                message = "Error binding shared parameter: " + e.Message;
                return(Result.Failed);
            }
            // set the initial values
            // get the singleton project info element
            Element projInfoElem = LabUtils.GetProjectInfoElem(doc);

            if (null == projInfoElem)
            {
                message = "No project info element found. Aborting command...";
                return(Result.Failed);
            }

            // For simplicity, access params by name rather than by GUID
            // and simply the first best one found under that name:

            projInfoElem.LookupParameter(LabConstants.ParamNameVisible).Set(55);
            projInfoElem.LookupParameter(LabConstants.ParamNameInvisible).Set(0);

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Debug.Assert(false, "This has not been tested since Revit 2010!");

            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            Autodesk.Revit.Creation.Application ca
                = app.Application.Create;

            Autodesk.Revit.Creation.Document cd
                = doc.Create;

            // determine line load symbol to use:

            FilteredElementCollector symbols
                = new FilteredElementCollector(doc);

            symbols.OfClass(typeof(LineLoadType));

            LineLoadType loadSymbol
                = symbols.FirstElement() as LineLoadType;

            // sketch plane and arrays of forces and moments:

            //Plane plane = ca.NewPlane( XYZ.BasisZ, XYZ.Zero ); // 2016
            Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); // 2017

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create New Line Load");

                //SketchPlane skplane = cd.NewSketchPlane( plane ); // 2013

                SketchPlane skplane = SketchPlane.Create(doc, plane); // 2014

                XYZ        forceA = new XYZ(0, 0, 5);
                XYZ        forceB = new XYZ(0, 0, 10);
                List <XYZ> forces = new List <XYZ>();
                forces.Add(forceA);
                forces.Add(forceB);

                XYZ        momentA = new XYZ(0, 0, 0);
                XYZ        momentB = new XYZ(0, 0, 0);
                List <XYZ> moments = new List <XYZ>();
                moments.Add(momentA);
                moments.Add(momentB);

                BuiltInCategory bic
                    = BuiltInCategory.OST_StructuralFraming;

                FilteredElementCollector beams = Util.GetElementsOfType(
                    doc, typeof(FamilyInstance), bic);

                XYZ p1 = new XYZ(0, 0, 0);
                XYZ p2 = new XYZ(3, 0, 0);
                //List<XYZ> points = new List<XYZ>();
                //points.Add( p1 );
                //points.Add( p2 );

                // create a new unhosted line load on points:

                //LineLoad lineLoadNoHost = cd.NewLineLoad(
                //  points, forces, moments,
                //  false, false, false,
                //  loadSymbol, skplane ); // 2015

                LineLoad lineLoadNoHost = LineLoad.Create(doc,
                                                          p1, p2, forces[0], moments[0],
                                                          loadSymbol, skplane); // 2016

                Debug.Print("Unhosted line load works.");

                // create new line loads on beam:

                foreach (Element e in beams)
                {
                    try
                    {
                        //LineLoad lineLoad = cd.NewLineLoad(
                        //  e, forces, moments,
                        //  false, false, false,
                        //  loadSymbol, skplane ); // 2015

                        AnalyticalModelSurface amsurf = e.GetAnalyticalModel()
                                                        as AnalyticalModelSurface;

                        LineLoad lineLoad = LineLoad.Create(doc,
                                                            amsurf, 0, forces[0], moments[0], loadSymbol); // 2016

                        Debug.Print("Hosted line load on beam works.");
                    }
                    catch (Exception ex)
                    {
                        Debug.Print("Hosted line load on beam fails: "
                                    + ex.Message);
                    }

                    FamilyInstance i = e as FamilyInstance;

                    AnalyticalModel am = i.GetAnalyticalModel();

                    foreach (Curve curve in
                             am.GetCurves(AnalyticalCurveType.ActiveCurves))
                    {
                        try
                        {
                            //LineLoad lineLoad = cd.NewLineLoad(
                            //  curve.Reference, forces, moments,
                            //  false, false, false,
                            //  loadSymbol, skplane ); // 2015

                            AnalyticalModelStick amstick = e.GetAnalyticalModel()
                                                           as AnalyticalModelStick;

                            LineLoad lineLoad = LineLoad.Create(doc,
                                                                amstick, forces[0], moments[0], loadSymbol); // 2016

                            Debug.Print("Hosted line load on "
                                        + "AnalyticalModelFrame curve works.");
                        }
                        catch (Exception ex)
                        {
                            Debug.Print("Hosted line load on "
                                        + "AnalyticalModelFrame curve fails: "
                                        + ex.Message);
                        }
                    }
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
Exemple #39
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("PropertiesCopy"));

            Document  doc = commandData.Application.ActiveUIDocument.Document;
            Selection sel = commandData.Application.ActiveUIDocument.Selection;
            Element   firstElem;

            List <ElementId> selIds = sel.GetElementIds().ToList();

            Debug.WriteLine("Selected elements: " + selIds.Count.ToString());
            if (selIds.Count > 0)
            {
                firstElem = doc.GetElement(selIds.First());
            }
            else
            {
                Reference r1;
                try
                {
                    r1 = sel.PickObject(ObjectType.Element, "Выберите элемент, с которого нужно скопировать свойства");
                }
                catch
                {
                    return(Result.Cancelled);
                }

                firstElem = doc.GetElement(r1.ElementId);
                Debug.WriteLine("First elem id: " + firstElem.Id.IntegerValue.ToString());
            }

            if (firstElem == null)
            {
                message += "Что-то не получилось. Сохраняйте спокойствие и порядок!";
                Debug.WriteLine("First elem is null");
                return(Result.Failed);
            }

            ParameterMap parameters = firstElem.ParametersMap;

            Debug.WriteLine("Parameters found: " + parameters.Size.ToString());

            while (true)
            {
                try
                {
                    SelectionFilter selFilter = new SelectionFilter(firstElem);
                    Reference       r         = sel.PickObject(ObjectType.Element, selFilter, "Выберите элементы для копирования свойств");
                    if (r == null)
                    {
                        continue;
                    }
                    ElementId curId = r.ElementId;
                    if (curId == null || curId == ElementId.InvalidElementId)
                    {
                        continue;
                    }
                    Element curElem = doc.GetElement(curId);
                    if (curElem == null)
                    {
                        continue;
                    }
                    Debug.WriteLine("Cur element id: " + curId.IntegerValue.ToString());

                    try
                    {
                        ElementId firstTypeId = firstElem.GetTypeId();
                        ElementId curTypeId   = curElem.GetTypeId();
                        if (firstTypeId != curTypeId)
                        {
                            using (Transaction t1 = new Transaction(doc))
                            {
                                t1.Start("Назначение типа");

                                curElem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).Set(firstTypeId);

                                t1.Commit();
                                Debug.WriteLine("Type of element is changed");
                            }
                        }
                    }
                    catch { }


                    using (Transaction t = new Transaction(doc))
                    {
                        t.Start("Копирование свойств");

                        foreach (Parameter param in parameters)
                        {
                            if (param == null)
                            {
                                continue;
                            }
                            if (!param.HasValue)
                            {
                                continue;
                            }
                            try
                            {
                                Parameter curParam = curElem.get_Parameter(param.Definition);

                                switch (param.StorageType)
                                {
                                case StorageType.None:
                                    break;

                                case StorageType.Integer:
                                    curParam.Set(param.AsInteger());
                                    break;

                                case StorageType.Double:
                                    curParam.Set(param.AsDouble());
                                    break;

                                case StorageType.String:
                                    curParam.Set(param.AsString());
                                    break;

                                case StorageType.ElementId:
                                    curParam.Set(param.AsElementId());
                                    break;

                                default:
                                    break;
                                }
                                Debug.WriteLine("Param value is written: " + curParam.Definition.Name + " = " + curParam.AsValueString());
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                                continue;
                            }
                        }
                        t.Commit();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(Result.Succeeded);
                }
            }
            Debug.WriteLine("All done");
        }
Exemple #40
0
        /// <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)
        {
            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");

            try
            {
                transaction.Start();
                Wall  wall  = null;
                Floor floor = null;

                ElementSet elems = commandData.Application.ActiveUIDocument.Selection.Elements;
                #region selection error handle
                //if user have some wrong selection, give user an error message
                if (1 != elems.Size)
                {
                    message = "please selected one Object (Floor or Wall) to create Opening.";
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }

                Autodesk.Revit.DB.Element selectElem = null;
                foreach (Autodesk.Revit.DB.Element e in elems)
                {
                    selectElem = e;
                }

                if (!(selectElem is Wall) && !(selectElem is Floor))
                {
                    message = "please selected one Object (Floor or Wall) to create Opening.";
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }
                #endregion
                try
                {
                    if (selectElem is Wall)
                    {
                        wall = selectElem as Wall;
                        ProfileWall     profileWall     = new ProfileWall(wall, commandData);
                        NewOpeningsForm newOpeningsForm = new NewOpeningsForm(profileWall);
                        newOpeningsForm.ShowDialog();
                    }
                    else if (selectElem is Floor)
                    {
                        floor = selectElem as Floor;
                        ProfileFloor    profileFloor    = new ProfileFloor(floor, commandData);
                        NewOpeningsForm newOpeningsForm = new NewOpeningsForm(profileFloor);
                        newOpeningsForm.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                transaction.Commit();
            }
        }
Exemple #41
0
        static Transform _t = Transform.CreateTranslation(_offset); // 2014

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            List <Element> walls = new List <Element>();

            //XYZ p;
            //List<XYZ> wall_start_points
            //  = walls.Select<Element, XYZ>( e => {
            //    Util.GetElementLocation( out p, e );
            //      return p; } )
            //        .ToList<XYZ>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                //message = ( 0 < sel.Elements.Size ) // 2014
                message = (0 < sel.GetElementIds().Count) // 2015
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }


            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create model curve copies of analytical model curves");

                Creator creator = new Creator(doc);

                foreach (Wall wall in walls)
                {
                    AnalyticalModel am = wall.GetAnalyticalModel();

                    foreach (AnalyticalCurveType ct in _curveTypes)
                    {
                        IList <Curve> curves = am.GetCurves(ct);

                        int n = curves.Count;

                        Debug.Print("{0} {1} curve{2}.",
                                    n, ct, Util.PluralSuffix(n));

                        foreach (Curve curve in curves)
                        {
                            //creator.CreateModelCurve( curve.get_Transformed( _t ) ); // 2013

                            creator.CreateModelCurve(curve.CreateTransformed(_t)); // 2014
                        }
                    }
                }
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Exemple #42
0
        /// <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_revitApp = commandData.Application.Application;
            m_doc      = commandData.Application.ActiveUIDocument.Document;

            Level level1 = GetLevel();

            if (level1 == null)
            {
                throw new Exception("[ERROR] Failed to get level 1");
            }

            try
            {
                //
                // Post a warning and resolve it in FailurePreproccessor
                try
                {
                    Transaction            transaction   = new Transaction(m_doc, "Warning_FailurePreproccessor");
                    FailureHandlingOptions options       = transaction.GetFailureHandlingOptions();
                    FailurePreproccessor   preproccessor = new FailurePreproccessor();
                    options.SetFailuresPreprocessor(preproccessor);
                    transaction.SetFailureHandlingOptions(options);
                    transaction.Start();
                    FailureMessage fm = new FailureMessage(m_idWarning);
                    m_doc.PostFailure(fm);
                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Warning_FailurePreproccessor";
                    return(Result.Failed);
                }

                //
                // Dismiss the overlapped wall warning in FailurePreproccessor
                try
                {
                    Transaction            transaction   = new Transaction(m_doc, "Warning_FailurePreproccessor_OverlappedWall");
                    FailureHandlingOptions options       = transaction.GetFailureHandlingOptions();
                    FailurePreproccessor   preproccessor = new FailurePreproccessor();
                    options.SetFailuresPreprocessor(preproccessor);
                    transaction.SetFailureHandlingOptions(options);
                    transaction.Start();

                    Line line  = Line.CreateBound(new XYZ(-10, 0, 0), new XYZ(-20, 0, 0));
                    Wall wall1 = Wall.Create(m_doc, line, level1.Id, false);
                    Wall wall2 = Wall.Create(m_doc, line, level1.Id, false);
                    m_doc.Regenerate();

                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Warning_FailurePreproccessor_OverlappedWall";
                    return(Result.Failed);
                }

                //
                // Post an error and resolve it in FailuresProcessingEvent
                try
                {
                    m_revitApp.FailuresProcessing += new EventHandler <Autodesk.Revit.DB.Events.FailuresProcessingEventArgs>(FailuresProcessing);
                    Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessingEvent");
                    transaction.Start();

                    Line line = Line.CreateBound(new XYZ(0, 10, 0), new XYZ(20, 10, 0));
                    Wall wall = Wall.Create(m_doc, line, level1.Id, false);
                    m_doc.Regenerate();

                    FailureMessage    fm = new FailureMessage(m_idError);
                    FailureResolution fr = DeleteElements.Create(m_doc, wall.Id);
                    fm.AddResolution(FailureResolutionType.DeleteElements, fr);
                    m_doc.PostFailure(fm);
                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Error_FailuresProcessingEvent";
                    return(Result.Failed);
                }

                //
                // Post an error and resolve it in FailuresProcessor
                try
                {
                    FailuresProcessor processor = new FailuresProcessor();
                    Application.RegisterFailuresProcessor(processor);
                    Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessor");
                    transaction.Start();

                    Line line = Line.CreateBound(new XYZ(0, 20, 0), new XYZ(20, 20, 0));
                    Wall wall = Wall.Create(m_doc, line, level1.Id, false);
                    m_doc.Regenerate();

                    FailureMessage    fm = new FailureMessage(m_idError);
                    FailureResolution fr = DeleteElements.Create(m_doc, wall.Id);
                    fm.AddResolution(FailureResolutionType.DeleteElements, fr);
                    m_doc.PostFailure(fm);
                    transaction.Commit();
                }
                catch (System.Exception)
                {
                    message = "Failed to commit transaction Error_FailuresProcessor";
                    return(Result.Failed);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Debug.Assert(false,
                         "setting the disallow join property was not possible prior to Revit 2012. "
                         + "In Revit 2012, you can use the WallUtils.DisallowWallJoinAtEnd method.");

            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            string s = "a wall, to retrieve its join types";

            Wall wall = Util.SelectSingleElementOfType(
                uidoc, typeof(Wall), s, false) as Wall;

            if (null == wall)
            {
                message = "Please select a wall.";
            }
            else
            {
                JoinType []     a1 = ( JoinType [] )Enum.GetValues(typeof(JoinType));
                List <JoinType> a  = new List <JoinType>((JoinType[])Enum.GetValues(typeof(JoinType)));
                int             n  = a.Count;

                LocationCurve lc = wall.Location as LocationCurve;

                s = Util.ElementDescription(wall) + ":\n";

                /*for( int i = 0; i < 2; ++i )
                 * {
                 * JoinType jt = lc.get_JoinType( i );
                 * int j = a.IndexOf( jt ) + 1;
                 * JoinType jtnew = a[ j < n ? j : 0];
                 * lc.set_JoinType( j, jtnew );
                 * s += string.Format(
                 *  "\nChanged join type at {0} from {1} to {2}.",
                 *  ( 0 == i ? "start" : "end" ), jt, jtnew );
                 * }
                 * // wall.Location = lc; // Property or indexer 'Autodesk.Revit.Element.Location' cannot be assigned to -- it is read only
                 */

                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Set Wall Join Type");

                    for (int i = 0; i < 2; ++i)
                    {
                        JoinType jt    = ((LocationCurve)wall.Location).get_JoinType(i);
                        int      j     = a.IndexOf(jt) + 1;
                        JoinType jtnew = a[j < n ? j : 0];
                        ((LocationCurve)wall.Location).set_JoinType(j, jtnew);
                        s += string.Format(
                            "\nChanged join type at {0} from {1} to {2}.",
                            (0 == i ? "start" : "end"), jt, jtnew);
                    }
                    t.Commit();
                }
            }
            Util.InfoMsg(s);
            return(Result.Succeeded);
        }
Exemple #44
0
        public Result Execute(
            ExternalCommandData commandData,
            ref String message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            FilteredElementCollector a;
            Parameter p;
            int       n;

            #region Using the obsolete TitleBlocks property
#if BEFORE_REVIT_2015
            // The TitleBlocks property was declared deprecated
            // in the Revit 2014 API, and removed in Revit 2015.

            // Using the obsolete deprecated TitleBlocks property

            FamilySymbolSet titleBlocks = doc.TitleBlocks;

            n = titleBlocks.Size;

            Debug.Print(
                "{0} title block element type{1} listed "
                + "in doc.TitleBlocks collection{2}",
                n,
                (1 == n ? "" : "s"),
                (0 == n ? "." : ":"));

            string s;

            foreach (FamilySymbol tb in titleBlocks)
            {
                // these are the family symbols,
                // i.e. the title block element types,
                // i.e. not instances, i.e. not sheets,
                // and they obviously do not have any sheet
                // number, width or height, so 's' ends up empty:

                s = GetParameterValueString(tb, BuiltInParameter.SHEET_NUMBER)
                    + GetParameterValueString(tb, BuiltInParameter.SHEET_WIDTH)
                    + GetParameterValueString(tb, BuiltInParameter.SHEET_HEIGHT);

                Debug.Print(
                    "Title block element type {0} {1}" + s,
                    tb.Name, tb.Id.IntegerValue);
            }
#endif // BEFORE_REVIT_2015
            #endregion // Using the obsolete TitleBlocks property

            // Using this filter returns the same elements
            // as the doc.TitleBlocks collection:

            a = new FilteredElementCollector(doc)
                .OfCategory(BuiltInCategory.OST_TitleBlocks)
                .OfClass(typeof(FamilySymbol));

            n = a.ToElementIds().Count;

            Debug.Print("{0} title block element type{1} "
                        + "retrieved by filtered element collector{2}",
                        n,
                        (1 == n ? "" : "s"),
                        (0 == n ? "." : ":"));

            foreach (FamilySymbol symbol in a)
            {
                Debug.Print(
                    "Title block element type {0} {1}",
                    symbol.Name, symbol.Id.IntegerValue);
            }

            // Retrieve the title block instances:

            a = new FilteredElementCollector(doc)
                .OfCategory(BuiltInCategory.OST_TitleBlocks)
                .OfClass(typeof(FamilyInstance));

            Debug.Print("Title block instances:");

            foreach (FamilyInstance e in a)
            {
                p = e.get_Parameter(
                    BuiltInParameter.SHEET_NUMBER);

                Debug.Assert(null != p,
                             "expected valid sheet number");

                string sheet_number = p.AsString();

                p = e.get_Parameter(
                    BuiltInParameter.SHEET_WIDTH);

                Debug.Assert(null != p,
                             "expected valid sheet width");

                string swidth = p.AsValueString();
                double width  = p.AsDouble();

                p = e.get_Parameter(
                    BuiltInParameter.SHEET_HEIGHT);

                Debug.Assert(null != p,
                             "expected valid sheet height");

                string sheight = p.AsValueString();
                double height  = p.AsDouble();

                ElementId typeId = e.GetTypeId();
                Element   type   = doc.GetElement(typeId);

                Debug.Print(
                    "Sheet number {0} size is {1} x {2} "
                    + "({3} x {4}), id {5}, type {6} {7}",
                    sheet_number, swidth, sheight,
                    Util.RealString(width),
                    Util.RealString(height),
                    e.Id.IntegerValue,
                    type.Name, typeId.IntegerValue);
            }

            // Retrieve the view sheet instances:

            a = new FilteredElementCollector(doc)
                .OfClass(typeof(ViewSheet));

            Debug.Print("View sheet instances:");

            foreach (ViewSheet vs in a)
            {
                string number = vs.SheetNumber;
                Debug.Print(
                    "View sheet name {0} number {1} id {2}",
                    vs.Name, vs.SheetNumber,
                    vs.Id.IntegerValue);
            }
            return(Result.Succeeded);
        }
Exemple #45
0
        /// <summary>
        /// tmp
        /// </summary>
        /// <param name="commandData"></param>
        void changeSlop(ExternalCommandData commandData)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            Selection  sel   = uidoc.Selection;

            Reference ref1 = sel.PickObject(
                ObjectType.Element, "Please pick a floor.");

            Floor f = doc.GetElement(ref1.ElementId) as Floor;

            if (f != null)
            {
                // Retrieve floor edge model line elements.

                ICollection <ElementId> deleted_ids;

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Temporarily Delete Floor");

                    deleted_ids = doc.Delete(f.Id);

                    tx.RollBack();
                }

                // Grab the first floor edge model line.

                ModelLine ml = null;

                foreach (ElementId id in deleted_ids)
                {
                    ml = doc.GetElement(id) as ModelLine;

                    if (null != ml)
                    {
                        break;
                    }
                }

                if (null != ml)
                {
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Change Slope Angle");

                        // This parameter is read only. Therefore,
                        // the change does not work and we cannot
                        // change the floor slope angle after the
                        // floor is created.
                        ml.get_Parameter(
                            BuiltInParameter.CURVE_IS_SLOPE_DEFINING)
                        .Set(1);

                        ml.get_Parameter(
                            BuiltInParameter.ROOF_SLOPE)
                        .Set(1.2);

                        tx.Commit();
                    }
                }
            }
        }
Exemple #46
0
 public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
 {
     Rhinoceros.ShowAsync();
     return(Result.Succeeded);
 }
 /// <summary>
 /// The construct of ExtrusionRoofManager class.
 /// </summary>
 /// <param name="commandData">A reference to the commandData.</param>
 public FootPrintRoofManager(ExternalCommandData commandData)
 {
     m_commandData = commandData;
     m_creationDoc = m_commandData.Application.ActiveUIDocument.Document.Create;
     m_creationApp = m_commandData.Application.Application.Create;
 }
Exemple #48
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            revitDoc = commandData.Application.ActiveUIDocument.Document;
            uidoc    = commandData.Application.ActiveUIDocument;

            ElementId ele = null;


            Selection selection             = uidoc.Selection;
            ICollection <ElementId> element = selection.GetElementIds();

            foreach (ElementId eleID in element)
            {
                ele = eleID;
                break;
            }


            FloorType FT = new FilteredElementCollector(revitDoc)
                           .OfClass(typeof(FloorType))
                           .First <Element>(
                e => e.Name.Equals("樹 150mm 2"))
                           as FloorType;


            Transaction            transaction            = new Transaction(revitDoc);
            FailureHandlingOptions failureHandlingOptions = transaction.GetFailureHandlingOptions();
            FailureHandler         failureHandler         = new FailureHandler();

            failureHandlingOptions.SetFailuresPreprocessor(failureHandler);
            failureHandlingOptions.SetClearAfterRollback(false);
            transaction.SetFailureHandlingOptions(failureHandlingOptions);
            transaction.Start("Transaction Name");
            // Do something here that causes the error

            List <string> Height = new List <string>();
            List <XYZ>    Data   = LoadTest(ref Height, @"D:\Users\95074\Desktop\CADAPI\CombineTreeAndCircle\CombineTreeAndCircle\bin\Debug\final.txt");

            int kk = 0;

            foreach (var xyz in Data)
            {
                CreateFloor(xyz.X, xyz.Y, double.Parse(Height[kk]), xyz.Z, FT, ele);
                kk = kk + 1;
            }
            transaction.Commit();



            // The following is just illustrative.
            // In reality we would collect the errors
            // to show later.

            //if (failureHandler.ErrorMessage != "")
            //{
            //    System.Windows.Forms.MessageBox.Show(
            //      failureHandler.ErrorSeverity + " || "
            //      + failureHandler.ErrorMessage);
            //}

            return(Result.Succeeded);
        }
Exemple #49
0
        public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
        {
            using (System.Diagnostics.Process.Start("https://discourse.mcneel.com/c/serengeti/inside")) { }

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            bool run_ViewSheetSet_Views_benchmark = true;

            if (run_ViewSheetSet_Views_benchmark)
            {
                string     s  = GetViewSheetSetViewsBenchmark(doc);
                TaskDialog td = new TaskDialog(
                    "ViewSheetSet.Views Benchmark");
                td.MainContent = s;
                td.Show();
                return(Result.Succeeded);
            }

            FilteredElementCollector sheets
                = new FilteredElementCollector(doc);

            sheets.OfClass(typeof(ViewSheet));

            // map with key = sheet element id and
            // value = list of viewport element ids:

            Dictionary <ElementId, List <ElementId> >
            mapSheetToViewport =
                new Dictionary <ElementId, List <ElementId> >();

            // map with key = viewport element id and
            // value = sheet element id:

            Dictionary <ElementId, ElementId> mapViewportToSheet
                = new Dictionary <ElementId, ElementId>();

            foreach (ViewSheet sheet in sheets)
            {
                //int n = sheet.Views.Size; // 2014

                ISet <ElementId> viewIds = sheet.GetAllPlacedViews(); // 2015

                int n = viewIds.Count;

                Debug.Print(
                    "Sheet {0} contains {1} view{2}: ",
                    Util.ElementDescription(sheet),
                    n, Util.PluralSuffix(n));

                ElementId idSheet = sheet.Id;

                int i = 0;

                foreach (ElementId id in viewIds)
                {
                    View v = doc.GetElement(id) as View;

                    BoundingBoxXYZ bb;

                    bb = v.get_BoundingBox(doc.ActiveView);

                    Debug.Assert(null == bb,
                                 "expected null view bounding box");

                    bb = v.get_BoundingBox(sheet);

                    Debug.Assert(null == bb,
                                 "expected null view bounding box");

                    Element viewport = GetViewport(sheet, v);

                    // null if not in active view:

                    bb = viewport.get_BoundingBox(doc.ActiveView);

                    BoundingBoxUV outline = v.Outline;

                    Debug.WriteLine(string.Format(
                                        "  {0} {1} bb {2} outline {3}",
                                        ++i, Util.ElementDescription(v),
                                        (null == bb ? "<null>" : Util.BoundingBoxString(bb)),
                                        Util.BoundingBoxString(outline)));

                    if (!mapSheetToViewport.ContainsKey(idSheet))
                    {
                        mapSheetToViewport.Add(idSheet,
                                               new List <ElementId>());
                    }
                    mapSheetToViewport[idSheet].Add(v.Id);

                    Debug.Assert(
                        !mapViewportToSheet.ContainsKey(v.Id),
                        "expected viewport to be contained"
                        + " in only one single sheet");

                    mapViewportToSheet.Add(v.Id, idSheet);
                }
            }
            return(Result.Cancelled);
        }
Exemple #51
0
        public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
        {
            using (System.Diagnostics.Process.Start("http://www.revitapidocs.com/")) { }

            return(Result.Succeeded);
        }
Exemple #52
0
        public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
        {
            using (System.Diagnostics.Process.Start("https://github.com/mcneel/rhino.inside/blob/master/Autodesk/Revit/README.md")) { }

            return(Result.Succeeded);
        }
Exemple #53
0
        /// <summary>
        /// The main (and only :-) command
        /// of our export sample
        /// </summary>
        public Result Execute(
            ExternalCommandData data,
            ref string msg,
            ElementSet elements)
        {
            // This command requires an active document

            UIDocument uidoc = data.Application
                               .ActiveUIDocument;

            if (uidoc == null)
            {
                msg = "Please run this command in an active project document.";
                return(Result.Failed);
            }

            Document doc = uidoc.Document;

            // Collect all 3D views in the document
            // (there must be at least one). The collection
            // will be listed in the option dialog for the
            // user to choose the ones to include in the
            // export.
            List <View3D> views = new List <View3D>(
                new FilteredElementCollector(doc)
                .OfClass(typeof(View3D))
                .Cast <View3D>()
                .Where <View3D>(v =>
                                v.CanBePrinted && !v.IsTemplate));

            int n = views.Count;

            if (0 == n)
            {
                msg = "There are no 3D views in the document!";
                return(Result.Failed);
            }

            // Initiate output with default path to
            // MyDocuments and the current document name

            string defaultName = Path.ChangeExtension(
                doc.Title, ".xml");

            string defaultFolder = System.Environment
                                   .GetFolderPath(
                Environment.SpecialFolder.MyDocuments);



            // Instantiate our custom context

            ExportContext context = new ExportContext(doc);

            // Instantiate a custom exporter with output
            // context given as the argument

            using (CustomExporter exporter
                       = new CustomExporter(doc, context))
            {
                List <ElementId> viewsToExport = new List <ElementId>();

                foreach (View3D v in views)
                {
                    viewsToExport.Add(v.Id);
                }
                try
                {
                    exporter.Export(viewsToExport);
                }
                catch (System.Exception ex)
                {
                    msg = "Exception: " + ex.Message;
                    return(Result.Failed);
                }
            }
            return(Result.Succeeded);
        }
Exemple #54
0
        public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
        {
            using (System.Diagnostics.Process.Start("https://thebuildingcoder.typepad.com/")) { }

            return(Result.Succeeded);
        }
Exemple #55
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = uiapp.ActiveUIDocument.Document;

            //BindingMap bindingMap = doc.ParameterBindings; // slow, fixed in 2009 wu 3, cf. case 1247995

            Guid paramGuid = LabUtils.SharedParamGUID(app,
                                                      LabConstants.SharedParamsGroupAPI, LabConstants.SharedParamsDefFireRating);

            // Let user select the Excel file.

            WinForms.OpenFileDialog dlg = new WinForms.OpenFileDialog();
            dlg.Title  = "Select source Excel file from which to update Revit shared parameters";
            dlg.Filter = "Excel spreadsheet files (*.xls;*.xlsx)|*.xls;*.xlsx|All files (*)|*";
            if (WinForms.DialogResult.OK != dlg.ShowDialog())
            {
                return(Result.Cancelled);
            }

            // Launch/Get Excel via COM Interop:

            X.Application excel = new X.Application();
            if (null == excel)
            {
                LabUtils.ErrorMsg("Failed to get or start Excel.");
                return(Result.Failed);
            }
            excel.Visible = true;
            X.Workbook workbook = excel.Workbooks.Open(dlg.FileName,
                                                       Missing.Value, Missing.Value, Missing.Value,
                                                       Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                       Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                       Missing.Value, Missing.Value, Missing.Value);
            X.Worksheet worksheet = workbook.ActiveSheet as X.Worksheet;

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Import Fire Rating Values from Excel");

                // Starting from row 2, loop the rows and extract Id and FireRating param.

                int    id;
                double fireRatingValue;
                int    row = 2;
                while (true)
                {
                    try
                    {
                        // Extract relevant XLS values.

                        X.Range r = worksheet.Cells[row, 1] as X.Range;
                        if (null == r.Value2)
                        {
                            break;
                        }
                        double d = (double)r.Value2;
                        id = (int)d;
                        if (0 >= id)
                        {
                            break;
                        }
                        r = worksheet.Cells[row, 4] as X.Range;
                        fireRatingValue = (double)r.Value2;

                        // Get document's door element via Id

                        ElementId elementId = new ElementId(id);
                        Element   door      = doc.GetElement(elementId);

                        // Set the param

                        if (null != door)
                        {
                            //Parameter parameter = door.get_Parameter( LabConstants.SharedParamsDefFireRating );
                            Parameter parameter = door.get_Parameter(paramGuid);
                            parameter.Set(fireRatingValue);
                        }
                    }
                    catch (Exception)
                    {
                        break;
                    }
                    ++row;
                }
                t.Commit();
            }

#if ACTIVATE_REVIT
            //
            // Set focus back to Revit (there may be a better way, but this works :-)
            //

#if USE_PROCESS_GET_PROCESSES
            foreach (Process p in Process.GetProcesses())
            {
                try
                {
                    if ("REVIT" == p.ProcessName.ToUpper().Substring(0, 5))
                    {
                        // In VB, we can use AppActivate( p.Id );
                        // Pre-3.0, I think you may need to use p/invoke and call the native Windows
                        // SetForegroundWindow() function directly.
                        // http://www.codeproject.com/csharp/windowhider.asp?df=100
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }
#endif // USE_PROCESS_GET_PROCESSES

            JtRevitWindow w = new JtRevitWindow();
            w.Activate();
#endif // ACTIVATE_REVIT

            return(Result.Succeeded);
        }
Exemple #56
0
 /// <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)
 {
     return(geometrySender.DoSend(commandData));
 }
Exemple #57
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            AllDetailsImportsSettingsForm form = new AllDetailsImportsSettingsForm(commandData.Application);

            return(Result.Succeeded);
        }
 public GetResourseService(ExternalCommandData commandData)
 {
     _docSet = commandData.Application.Application.Documents;
     Initialize();
 }
Exemple #59
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = uiapp.ActiveUIDocument.Document;

            Category cat = doc.Settings.Categories.get_Item(
                Lab4_3_1_CreateAndBindSharedParam.Target);

            // Launch Excel (same as in Lab 4_2, so we really
            // should have better created some utils...)

            X.Application excel = new X.ApplicationClass();
            if (null == excel)
            {
                LabUtils.ErrorMsg("Failed to get or start Excel.");
                return(Result.Failed);
            }
            excel.Visible = true;
            X.Workbook  workbook = excel.Workbooks.Add(Missing.Value);
            X.Worksheet worksheet;
            //while( 1 < workbook.Sheets.Count )
            //{
            //  worksheet = workbook.Sheets.get_Item( 0 ) as X.Worksheet;
            //  worksheet.Delete();
            //}
            worksheet             = excel.ActiveSheet as X.Worksheet;
            worksheet.Name        = "Revit " + cat.Name;
            worksheet.Cells[1, 1] = "ID";
            worksheet.Cells[1, 2] = "Level";
            worksheet.Cells[1, 3] = "Tag";
            worksheet.Cells[1, 4] = LabConstants.SharedParamsDefFireRating;
            worksheet.get_Range("A1", "Z1").Font.Bold = true;

            List <Element> elems = LabUtils.GetTargetInstances(doc,
                                                               Lab4_3_1_CreateAndBindSharedParam.Target);

            // Get Shared param Guid

            Guid paramGuid = LabUtils.SharedParamGUID(app,
                                                      LabConstants.SharedParamsGroupAPI, LabConstants.SharedParamsDefFireRating);

            if (paramGuid.Equals(Guid.Empty))
            {
                LabUtils.ErrorMsg("No Shared param found in the file - aborting...");
                return(Result.Failed);
            }

            // Loop through all elements and export each to an Excel row

            int row = 2;

            foreach (Element e in elems)
            {
                worksheet.Cells[row, 1] = e.Id.IntegerValue; // ID

                //worksheet.Cells[row, 2] = e.Level.Name; // Level // 2013
                worksheet.Cells[row, 2] = doc.GetElement(e.LevelId).Name; // Level // 2014

                // Tag:

                Parameter tagParameter = e.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
                if (null != tagParameter)
                {
                    worksheet.Cells[row, 3] = tagParameter.AsString();
                }

                // FireRating:

                Parameter parameter = e.get_Parameter(paramGuid);
                if (null != parameter)
                {
                    worksheet.Cells[row, 4] = parameter.AsDouble();
                }
                ++row;
            }
            return(Result.Succeeded);
        }
Exemple #60
-1
        Matrix4 m_transformMatrix = null; // store the Matrix used to transform Revit coordinate to window UI

        #endregion Fields

        #region Constructors

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="floor">Floor object in Revit</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabProfile(Autodesk.Revit.DB.Floor floor, ExternalCommandData commandData)
        {
            m_floor = floor;
            m_commandData = commandData;
            m_slabShapeEditor = floor.SlabShapeEditor;
            GetSlabProfileInfo();
        }