Beispiel #1
0
 /// <summary>
 /// Constructor which takes a Revit.Document as parameter.
 /// </summary>
 /// <param name="rvtDoc">Revit.Document parameter</param>
 protected HostedSweepCreator(Autodesk.Revit.UI.UIDocument rvtDoc)
 {
     m_rvtUIDoc            = rvtDoc;
     m_rvtDoc              = rvtDoc.Document;
     m_elemGeom            = new Dictionary <Autodesk.Revit.DB.Element, ElementGeometry>();
     m_createdHostedSweeps = new List <ModificationData>();
 }
Beispiel #2
0
 public FrontForm(Autodesk.Revit.UI.UIDocument document, IList <Autodesk.Revit.DB.ViewSheet> sheets)
 {
     uidoc      = document;
     doc        = uidoc.Document;
     viewsheets = sheets;
     InitializeComponent();
 }
Beispiel #3
0
 public HelloForm(Document dbdoc, Autodesk.Revit.UI.UIDocument uidoc, Autodesk.Revit.DB.View uiview)
 {
     InitializeComponent();
     this.dbdoc = dbdoc;
     this.uidoc = uidoc;
     view       = uiview;
 }
Beispiel #4
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_uiApp = commandData.Application;
            m_uiDoc = m_uiApp.ActiveUIDocument;

            // get the target element to be used for the Distance computation
            ElementSet collection = m_uiDoc.Selection.Elements;
            Parameter  param      = null;

            Autodesk.Revit.DB.XYZ targetPoint = getTargetPoint(m_uiDoc.Selection.Elements);

            // get all the divided surfaces in the Revit document
            List <DividedSurface> dsList = GetElements <DividedSurface>();

            foreach (DividedSurface ds in dsList)
            {
                GridNode gn = new GridNode();
                int      u  = 0;
                while (u < ds.NumberOfUGridlines)
                {
                    gn.UIndex = u;
                    int v = 0;
                    while (v < ds.NumberOfVGridlines)
                    {
                        gn.VIndex = v;
                        if (ds.IsSeedNode(gn))
                        {
                            FamilyInstance familyinstance = ds.GetTileFamilyInstance(gn, 0);
                            if (familyinstance != null)
                            {
                                param = familyinstance.get_Parameter("Distance");
                                if (param == null)
                                {
                                    throw new Exception("Panel family must have a Distance instance parameter");
                                }
                                else
                                {
                                    LocationPoint loc        = familyinstance.Location as LocationPoint;
                                    XYZ           panelPoint = loc.Point;

                                    double d = Math.Sqrt(Math.Pow((targetPoint.X - panelPoint.X), 2) + Math.Pow((targetPoint.Y - panelPoint.Y), 2) + Math.Pow((targetPoint.Z - panelPoint.Z), 2));
                                    param.Set(d);

                                    // uncomment the following lines to create points and lines showing where the distance measurement is made
                                    //ReferencePoint rp = m_doc.FamilyCreate.NewReferencePoint(panelPoint);
                                    //Line line = m_app.Create.NewLine(targetPoint, panelPoint, true);
                                    //Plane plane = m_app.Create.NewPlane(targetPoint.Cross(panelPoint), panelPoint);
                                    //SketchPlane skplane = m_doc.FamilyCreate.NewSketchPlane(plane);
                                    //ModelCurve modelcurve = m_doc.FamilyCreate.NewModelCurve(line, skplane);
                                }
                            }
                        }
                        v = v + 1;
                    }
                    u = u + 1;
                }
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        public void Execute(UIApplication uiapp)
        {
            this.uiapp = uiapp;
            this.uidoc = this.uiapp.ActiveUIDocument;
            this.doc   = this.uidoc.Document;

            ModifyScene(uiapp, "Renumber Viewports Handler");
        }
Beispiel #6
0
 public WTA_FPSettings(ExternalCommandData commandData)
 {
     InitializeComponent();
     uiapp = commandData.Application;
     uidoc = uiapp.ActiveUIDocument;
     app   = uiapp.Application;
     doc   = uidoc.Document;
 }
Beispiel #7
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
            {
                m_project = commandData.Application.ActiveUIDocument;

                // Get the selected element and store it to data member.
                if (!GetSelectedElement())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a BoundingBoxXYZ instance which used in NewViewSection() method
                if (!GenerateBoundingBoxXYZ())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a section view.
                Transaction transaction = new Transaction(m_project.Document, "CreateSectionView");
                transaction.Start();
                //ViewSection section = m_project.Document.Create.NewViewSection(m_box);
                ElementId       DetailViewId = new ElementId(-1);
                IList <Element> elems        = new FilteredElementCollector(m_project.Document).OfClass(typeof(ViewFamilyType)).ToElements();
                foreach (Element e in elems)
                {
                    ViewFamilyType v = e as ViewFamilyType;

                    if (v != null && v.ViewFamily == ViewFamily.Detail)
                    {
                        DetailViewId = e.Id;
                        break;
                    }
                }
                ViewSection section = ViewSection.CreateDetail(m_project.Document, DetailViewId, m_box);
                if (null == section)
                {
                    message = "Can't create the ViewSection.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Modify some parameters to make it look better.
                section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
                transaction.Commit();

                // If everything goes right, give successful information and return succeeded.
                TaskDialog.Show("Revit", "Create view section succeeded.");
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
        public void init(Autodesk.Revit.UI.UIApplication uiapp, TileAction tileAction)
        {
            this.uiapp               = uiapp;
            this.uidoc               = this.uiapp.ActiveUIDocument;
            this.doc                 = this.uidoc.Document;
            this.drawAreaRectangle   = this.uiapp.DrawingAreaExtents;
            this.mainWindowRectangle = this.uiapp.MainWindowExtents;

            List <string> planViewsTitles = getOpenPlanViewsTitles();

            if (this.almEnabled)
            {
                try
                {
                    switch (tileAction)
                    {
                    case TileAction.Left:
                        setWindowsTileLeft();
                        break;

                    case TileAction.Right:
                        setWindowsTileRight();
                        break;

                    case TileAction.Top:
                        setWindowsTileTop();
                        break;

                    case TileAction.Bottom:
                        setWindowsTileBottom();
                        break;

                    case TileAction.Bigger:
                        setWindowsTileBigger();
                        break;

                    case TileAction.Smaller:
                        setWindowsTileSmaller();
                        break;

                    case TileAction.Load:
                        setWindowsTileLoad();
                        break;

                    case TileAction.Save:
                        setWindowsTileSave();
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Beispiel #9
0
        public SpatialAnalysis.Geometry.UV PickPoint(string message)
        {
            UIDocument uidoc   = new Autodesk.Revit.UI.UIDocument(OSM_FOR_REVIT.RevitDocument);
            XYZ        xyz     = uidoc.Selection.PickPoint(message);
            var        revitUV = new SpatialAnalysis.Geometry.UV(xyz.X, xyz.Y);

            UnitConversion.Transform(revitUV, Length_Unit_Types.FEET, unitConversion.FromUnit);
            return(revitUV);
        }
        public void UpdateDoc(Document doc)
        {
            UIDocument d = new UIDocument(doc);

            this.uidoc = d;
            this.doc   = doc;

            this.updateTreeView(doc, "mech");
        }
        Boolean CreateCopy(Autodesk.Revit.UI.UIDocument project, ParameterFilterElement filter) //select filters (or create them)
        {
            //search filters
            //ParameterFilterElement filter = null;
            // FilteredElementCollector coll = new FilteredElementCollector(project.Document).OfClass(typeof(ParameterFilterElement));
            // string topRebarFilter = "Rebar Layer Top";
            // string bottomRebarFilter = "Rebar Layer Bottom";

            return(true);
        }
        public void init(UIApplication uiapp)
        {
            this.uiapp = uiapp;
            this.uidoc = this.uiapp.ActiveUIDocument;
            this.doc   = this.uidoc.Document;

            if (this.uiapp != null)
            {
                updateTreeView(doc, "mech");
            }
        }
        public SetParameterViewModel(Autodesk.Revit.UI.UIDocument uidoc)
        {
            _uidoc = uidoc;
            _doc   = uidoc.Document;

            Reference r = _uidoc.Selection.PickObject(ObjectType.Element);
            Element   e = _doc.GetElement(r);

            _Element = e;
            Process();
        }
Beispiel #14
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="commandData">
        /// object which contains reference of Revit Application
        /// </param>
        public MyDocument(ExternalCommandData commandData)
        {
            m_commandData = commandData;
            m_uiDocument  = m_commandData.Application.ActiveUIDocument;
            m_document    = m_uiDocument.Document;

            // initialize the curtain system data
            m_systemData = new CurtainSystem.SystemData(this);

            // get the curtain system type of the active Revit document
            GetCurtainSystemType();
        }
Beispiel #15
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication uiapp = commandData.Application;
            Autodesk.Revit.UI.UIDocument    uidoc = uiapp.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Autodesk.Revit.DB.Document doc = uidoc.Document;

            // Build a wall profile for the wall creation
            XYZ[] pts = new XYZ[] {
                XYZ.Zero,
                new XYZ(20, 0, 0),
                new XYZ(20, 0, 15),
                new XYZ(10, 0, 30),
                new XYZ(0, 0, 15)
            };

            // Get application creation object
            Autodesk.Revit.Creation.Application appCreation = app.Create;

            // Create wall profile
            CurveArray profile = new CurveArray();
            XYZ        q       = pts[pts.Length - 1];

            foreach (XYZ p in pts)
            {
                profile.Append(appCreation.NewLineBound(q, p));
                q = p;
            }

            XYZ normal = XYZ.BasisY;

            WallType wallType
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(WallType))
                  .First <Element>()
                  as WallType;

            Level level
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(Level))
                  .First <Element>(e
                                   => e.Name.Equals("Level 1"))
                  as Level;

            Transaction trans = new Transaction(doc);

            trans.Start("Test Gable Wall");
            Wall wall = doc.Create.NewWall(profile, wallType, level, true, normal);

            trans.Commit();

            return(Result.Succeeded);
        }
        public ToolPalettesOldForm(UIApplication uiapp)
        {
            InitializeComponent();

            this.uiapp = uiapp;
            this.uidoc = this.uiapp.ActiveUIDocument;
            this.doc   = this.uidoc.Document;

            previewSize = this.pictureBoxPalette.Size;
            updateTreeView(doc, "mech");
            this.Show();
        }
        Boolean CreateFilters(Autodesk.Revit.UI.UIDocument project) //select filters (or create them)
        {
            // FilteredElementCollector coll = new FilteredElementCollector(project.Document).OfClass(typeof(ParameterFilterElement));
            string topRebarFilter       = "Rebar Layer Top";
            string bottomRebarFilter    = "Rebar Layer Bottom";
            string topAddRebarFilter    = "Rebar Layer Top Add";
            string bottomAddRebarFilter = "Rebar Layer Bottom Add";

            /*
             * ParameterFilterElement f_topRebarView = null;
             * ParameterFilterElement f_bottomRebarView = null;
             * ParameterFilterElement f_topAddRebarView = null;
             * ParameterFilterElement f_bottomAddRebarView = null;
             * */
            IEnumerable <Element> filters = new FilteredElementCollector(project.Document).OfClass(typeof(ParameterFilterElement)).ToElements();

            //List<ElementId> categories = new List<ElementId>();
            //categories.Add(new ElementId(BuiltInCategory.OST_Rebar));
            // List<FilterRule> filterRules = new List<FilterRule>();
            foreach (Element element in filters)
            {
                if (element.Name.Equals(topRebarFilter))
                {
                    f_topRebarView = element as ParameterFilterElement;
                }
                else
                {
                }       //create new filter
                if (element.Name.Equals(bottomRebarFilter))
                {
                    f_bottomRebarView = element as ParameterFilterElement;
                }
                else
                {
                }       //create new filter
                if (element.Name.Equals(topAddRebarFilter))
                {
                    f_topAddRebarView = element as ParameterFilterElement;
                }
                else
                {
                }       //create new filter
                if (element.Name.Equals(bottomAddRebarFilter))
                {
                    f_bottomAddRebarView = element as ParameterFilterElement;
                }
            }

            return(true);
        }
Beispiel #18
0
 public static void Excute(Autodesk.Revit.UI.UIApplication uiapp, string text)
 {
     Autodesk.Revit.UI.UIDocument uidoc = uiapp.ActiveUIDocument;
     Autodesk.Revit.DB.Document   doc   = uidoc.Document;
     if (uidoc != null && doc != null)
     {
         Reference   re    = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "");
         Element     e     = doc.GetElement(re);
         Transaction trans = new Transaction(doc, text);
         trans.Start();
         doc.Delete(e.Id);
         trans.Commit();
     }
 }
Beispiel #19
0
        /// <summary>
        /// Get necessary data from revit.such as selected beams, wall types and level information
        /// </summary>
        /// <param name="project">A reference of current document</param>
        /// <returns>true if no error happens; otherwise, false.</returns>
        Boolean PrepareData(Autodesk.Revit.UI.UIDocument project)
        {
            // Search all the wall types in the Revit
            FilteredElementCollector filteredElementCollector = new FilteredElementCollector(project.Document);

            filteredElementCollector.OfClass(typeof(WallType));
            m_wallTypeCollection = filteredElementCollector.Cast <WallType>().ToList <WallType>();

            // Find the selection of beams in Revit
            ElementSet selection = new ElementSet();

            foreach (ElementId elementId in project.Selection.GetElementIds())
            {
                selection.Insert(project.Document.GetElement(elementId));
            }
            AnalyticalModel model;     // store the AnalyticalModel of the beam.

            foreach (Autodesk.Revit.DB.Element e in selection)
            {
                FamilyInstance m = e as FamilyInstance;

                // Use StructuralType property can judge whether it is a beam.
                if (null != m && StructuralType.Beam == m.StructuralType)
                {
                    m_beamCollection.Add(e);    // store the beams

                    // Get the curve of beam's AnalyticalModel.
                    model = m.GetAnalyticalModel();
                    if (null == model)
                    {
                        m_errorInformation = "The beam should have analytical model.";
                        return(false);
                    }
                    m_analyticalLineCollection.Add(model.GetCurve());
                }
            }
            if (0 == m_beamCollection.Count)
            {
                m_errorInformation = "Can not find any beams.";
                return(false);
            }

            // Get the level which will be used in create method
            FilteredElementCollector collector = new FilteredElementCollector(project.Document);

            m_level = collector.OfClass(typeof(Level)).FirstElement() as Level;
            return(true);
        }
        private void ModifyScene(UIApplication uiapp, String text, MyOperation operation)
        {
            uidoc = uiapp.ActiveUIDocument;

            if (uidoc != null)
            {
                using (Transaction trans = new Transaction(uidoc.Document))
                {
                    if (trans.Start(text) == TransactionStatus.Started)
                    {
                        operation(1);

                        trans.Commit();
                    }
                }
            }
        }
Beispiel #21
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
            {
                m_project = commandData.Application.ActiveUIDocument;

                // Get the selected element and store it to data member.
                if (!GetSelectedElement())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a BoundingBoxXYZ instance which used in NewViewSection() method
                if (!GenerateBoundingBoxXYZ())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a section view.
                Transaction transaction = new Transaction(m_project.Document, "CreateSectionView");
                transaction.Start();
                ViewSection section = m_project.Document.Create.NewViewSection(m_box);
                if (null == section)
                {
                    message = "Can't create the ViewSection.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Modify some parameters to make it look better.
                section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
                transaction.Commit();

                // If everything goes right, give successful information and return succeeded.
                MessageBox.Show("Create view section succeeded.", "Revit");
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
        public SuperFilterForm(Autodesk.Revit.DB.Document doc)
        {
            InitializeComponent();

            try
            {
                this.doc   = doc;
                this.uidoc = new UIDocument(this.doc);

                if (this.uidoc != null)
                {
                    InitUI();
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void ModifyScene(UIApplication uiapp, String text)
        {
            uidoc = uiapp.ActiveUIDocument;

            if (uidoc != null)
            {
                doc = uidoc.Document;

                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start(text);
                    RenumberViewports(1);

                    trans.Commit();
                    trans.Dispose();
                }
            }
        }
        public Result Execute(
            ExternalCommandData revit,
            ref string message,
            ElementSet elements)
        {
            m_uiApp = revit.Application;
              m_app = m_uiApp.Application;
              m_uiDoc = m_uiApp.ActiveUIDocument;
              m_doc = m_uiDoc.Document;

              TaskDialog.Show( "Test application",
            "Revit version: " + m_app.VersionBuild );

              m_writer = new StreamWriter( @"C:\SRD201483.txt" );

              WriteDimensionReferences( 161908 );
              WriteElementGeometry( 161900 );

              m_writer.Close();

              return Result.Succeeded;
        }
Beispiel #25
0
        public static void IdlingHandler(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs args)
        {
            UIApplication uiapp = sender as UIApplication;

            if (uiapp != null)
            {
                Autodesk.Revit.UI.UIDocument uidoc = uiapp.ActiveUIDocument;
                Autodesk.Revit.DB.Document   doc   = uidoc.Document;
                if (uidoc != null && doc != null)
                {
                    Reference re = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "");
                    Element   e  = doc.GetElement(re);

                    System.Windows.Forms.MessageBox.Show(e.Id.ToString() + e.Name);
                    uiapp.Idling -= IdlingHandler;
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Must should Idling!");
            }
        }
 public AutomaticDoorRenumberProcessor(UIApplication uiapp)
 {
     this.uiapp = uiapp;
     this.uidoc = uiapp.ActiveUIDocument;
     this.doc   = uidoc.Document;
 }
Beispiel #27
0
 public dynElementSettings(Autodesk.Revit.UI.UIApplication app, Autodesk.Revit.UI.UIDocument doc,
     Element dynVolatile, Element dynPersistent, Element dynX, Element dynY, Element dynZ,
     FamilySymbol defaultFraming, Level defaultLevel, DynamoWarningSwallower warningSwallower, Transaction t)
 {
     this.dynX = dynX;
     this.dynY = dynY;
     this.dynZ = dynZ;
     this.dynPersistent = dynPersistent;
     this.dynVolatile = dynVolatile;
     this.revit = app;
     this.doc = doc;
     this.defaultFraming = defaultFraming;
     this.defaultLevel = defaultLevel;
     this.warningSwallower = warningSwallower;
     this.trans = t;
 }
Beispiel #28
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements)
        {
            try
            {
                //create a log file
                string tempPath = System.IO.Path.GetTempPath();
                string logPath  = Path.Combine(tempPath, "dynamoLog.txt");

                if (File.Exists(logPath))
                {
                    File.Delete(logPath);
                }

                tw = new StreamWriter(logPath);
                tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString());

                m_revit = revit.Application;
                m_doc   = m_revit.ActiveUIDocument;

                trans = new Transaction(m_doc.Document, "Dynamo");
                trans.Start();

                FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions();
                failOpt.SetFailuresPreprocessor(new DynamoWarningSwallower());
                trans.SetFailureHandlingOptions(failOpt);

                m_revit.Idling += new EventHandler <IdlingEventArgs>(OnIdling);

                #region default level
                Level defaultLevel = null;
                FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document);
                fecLevel.OfClass(typeof(Level));
                for (int i = 0; i < fecLevel.ToElements().Count; i++)
                {
                    defaultLevel = fecLevel.ToElements()[i] as Level;
                    break;
                }

                #endregion

                DynamoWarningSwallower swallow = new DynamoWarningSwallower();

                dynElementSettings.SharedInstance.Revit            = m_revit;
                dynElementSettings.SharedInstance.Doc              = m_doc;
                dynElementSettings.SharedInstance.DefaultLevel     = defaultLevel;
                dynElementSettings.SharedInstance.WarningSwallower = swallow;
                dynElementSettings.SharedInstance.MainTransaction  = trans;
                dynElementSettings.SharedInstance.Writer           = tw;
                //dynElementSettings settings = new dynElementSettings(m_revit, m_doc,
                //defaultLevel, swallow, trans);


                //show the log
                dynamoForm = new dynBench();

                //get the window handle
                Process process = Process.GetCurrentProcess();
                new System.Windows.Interop.WindowInteropHelper(dynamoForm).Owner = process.MainWindowHandle;
                dynamoForm.Show();

                if (dynamoForm.DialogResult.HasValue && dynamoForm.DialogResult.Value == false)   //the WPF false is "cancel"
                {
                    tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString());
                    tw.Close();

                    return(Autodesk.Revit.UI.Result.Cancelled);
                }
            }
            catch (Exception e)
            {
                trans.Dispose();
                Debug.WriteLine(e.Message + ":" + e.StackTrace);
                Debug.WriteLine(e.InnerException);
                message = e.Message + " : " + e.StackTrace;

                if (tw != null)
                {
                    tw.WriteLine(e.Message);
                    tw.WriteLine(e.StackTrace);
                    tw.Close();
                }

                return(Autodesk.Revit.UI.Result.Failed);
            }

            trans.Commit();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
 public ExportToExcelProcessor(Autodesk.Revit.UI.UIApplication uiapp)
 {
     this.uiapp = uiapp;
     this.uidoc = this.uiapp.ActiveUIDocument;
     this.doc   = this.uidoc.Document;
 }
Beispiel #30
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements)
        {
            if (dynamoBench != null)
            {
                dynamoBench.Focus();
                return Result.Succeeded;
            }

            //SplashScreen splashScreen = null
            Window splashScreen = null;

            try
            {
                //create a log file
                string tempPath = System.IO.Path.GetTempPath();
                string logPath = Path.Combine(tempPath, "dynamoLog.txt");

                if (File.Exists(logPath))
                    File.Delete(logPath);

                tw = new StreamWriter(logPath);
                tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString());

                m_revit = revit.Application;
                m_doc = m_revit.ActiveUIDocument;

                #region default level

                Level defaultLevel = null;
                FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document);
                fecLevel.OfClass(typeof(Level));
                defaultLevel = fecLevel.ToElements()[0] as Level;

                #endregion
                dynRevitSettings.Revit = m_revit;
                dynRevitSettings.Doc = m_doc;
                dynRevitSettings.DefaultLevel = defaultLevel;
                dynSettings.Writer = tw;

                IdlePromise.ExecuteOnIdle(new Action(
                    delegate
                    {
                        try{
                        //get window handle
                        IntPtr mwHandle = Process.GetCurrentProcess().MainWindowHandle;

                        //prepare and show splash
                        //splashScreen = new SplashScreen(Assembly.GetExecutingAssembly(), "splash.png");
                        splashScreen = new DynamoSplash();
                        //splashScreen.Show(false, true);

                        //show the window
                        var dynamoController = new DynamoController_Revit(DynamoRevitApp.updater);
                        dynamoBench = dynamoController.Bench;

                        //set window handle and show dynamo
                        new System.Windows.Interop.WindowInteropHelper(dynamoBench).Owner = mwHandle;

                        if (System.Windows.Forms.SystemInformation.MonitorCount > 1)
                        {
                            dynamoBench.WindowStartupLocation = WindowStartupLocation.Manual;

                            System.Drawing.Rectangle bounds = System.Windows.Forms.Screen.AllScreens[1].Bounds;
                            dynamoBench.Left = bounds.X;
                            dynamoBench.Top = bounds.Y;
                            dynamoBench.Loaded += new RoutedEventHandler(dynamoForm_Loaded);
                        }
                        else
                        {
                            //System.Drawing.Rectangle bounds = System.Windows.Forms.Screen.AllScreens[0].Bounds;
                            //dynamoForm.Left = bounds.X;
                            //dynamoForm.Top = bounds.Y;
                            dynamoBench.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        }

                        dynamoBench.Show();

                        dynamoBench.Closed += new EventHandler(dynamoForm_Closed);
                         }
                        catch (Exception ex)
                         {
                             System.Windows.Forms.MessageBox.Show(ex.ToString());
                         }
                    }
                ));
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                if (tw != null)
                {
                    tw.WriteLine(ex.Message);
                    tw.WriteLine(ex.StackTrace);
                tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString());
                tw.Close();
                }
                return Result.Failed;
            }

            return Autodesk.Revit.UI.Result.Succeeded;
        }
 public RevitUI.Result Execute(RevitUI.ExternalCommandData commandData, ref string message, RevitDB.ElementSet elements)
 {
     RevitUI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
     RevitDB.Document   doc   = uidoc.Document;
     if (doc.IsFamilyDocument)//感觉族文档没必要
     {
         RevitUI.TaskDialog.Show("Revit", "该操作仅适用项目文档,不适用族文档!");
         return(RevitUI.Result.Succeeded);
     }
     try
     {
         RevitDB.View view = doc.ActiveView;                                    //当前视图
         ICollection <RevitDB.ElementId> ids = uidoc.Selection.GetElementIds(); //选择对象
         if (0 == ids.Count)                                                    //如果没有选择
         {
             if (view is RevitDB.ViewSection)                                   //当前视图为立面视图且没有选择对象时退出
             {
                 return(RevitUI.Result.Succeeded);
             }
             else if (view is RevitDB.View3D)//当前视图为三维视图且没有选择对象时切换至原楼层平面视图
             {
                 RevitDB.FilteredElementCollector collectL    = new RevitDB.FilteredElementCollector(doc);
                 ICollection <RevitDB.Element>    collectionL = collectL.OfClass(typeof(RevitDB.View)).ToElements();
                 foreach (RevitDB.Element element in collectionL)
                 {
                     RevitDB.View v = element as RevitDB.View;
                     if (view.ViewName == "三维视图_" + v.ViewType.ToString() + "_" + v.ViewName)
                     {
                         if (!v.IsTemplate)
                         {
                             uidoc.ActiveView = v;
                             break;
                         }
                     }
                 }
                 return(RevitUI.Result.Succeeded);
             }//未选择对象时列出当前视图所有可见对象
             RevitDB.FilteredElementCollector collector = new RevitDB.FilteredElementCollector(doc, view.Id).WhereElementIsNotElementType();
             ids = collector.ToElementIds();
         }
         RevitDB.Transaction ts = new RevitDB.Transaction(doc, "Create_View3D");
         ts.Start();
         bool fg = true;
         RevitDB.FilteredElementCollector collect    = new RevitDB.FilteredElementCollector(doc);
         ICollection <RevitDB.Element>    collection = collect.OfClass(typeof(RevitDB.View3D)).ToElements();
         RevitDB.View3D view3d = null;
         foreach (RevitDB.Element element in collection)
         {
             RevitDB.View3D v = element as RevitDB.View3D;
             if (v.ViewName == "三维视图_" + view.ViewType.ToString() + "_" + view.ViewName)
             {
                 if (!v.IsTemplate)
                 {
                     view3d = v;
                     fg     = false;//已生成过当前视图的三维视图
                     break;
                 }
             }
         }
         if (fg)
         {
             RevitDB.ViewFamilyType viewFamilyType = null;
             collect = new RevitDB.FilteredElementCollector(doc);
             var viewFamilyTypes = collect.OfClass(typeof(RevitDB.ViewFamilyType)).ToElements();
             foreach (RevitDB.Element e in viewFamilyTypes)
             {
                 RevitDB.ViewFamilyType v = e as RevitDB.ViewFamilyType;
                 if (v.ViewFamily == RevitDB.ViewFamily.ThreeDimensional)
                 {
                     viewFamilyType = v;
                     break;
                 }
             }
             view3d          = RevitDB.View3D.CreateIsometric(doc, viewFamilyType.Id);
             view3d.ViewName = "三维视图_" + view.ViewType.ToString() + "_" + view.ViewName;
         }
         ts.Commit();
         uidoc.ActiveView = view3d;//设置生成的三维视图为当前视图
         RevitDB.Transaction tss = new RevitDB.Transaction(doc, "View3D_HideElements");
         tss.Start();
         if (fg)
         {
             view    = doc.ActiveView;
             collect = new RevitDB.FilteredElementCollector(doc, view.Id).WhereElementIsNotElementType();
             ICollection <RevitDB.ElementId> idss = collect.ToElementIds();
             ICollection <RevitDB.ElementId> ds   = idss;
             ds = idss.Except(ids).ToList();
             ids.Clear();
             foreach (RevitDB.ElementId id in ds)
             {
                 RevitDB.Element element = doc.GetElement(id);
                 if (element.CanBeHidden(view) == true)
                 {
                     ids.Add(id);
                 }
             }
             view.HideElementsTemporary(ids);//临时隐藏其他图元
         }
         tss.Commit();
     }
     catch (Exception)
     {
         return(RevitUI.Result.Cancelled);
     }
     return(RevitUI.Result.Succeeded);
 }
Beispiel #32
0
      /// <summary>
      /// constructor
      /// </summary>
      /// <param name="commandData">
      /// object which contains reference of Revit Application
      /// </param>
      public MyDocument(ExternalCommandData commandData)
      {
         m_commandData = commandData;
         m_uiDocument = m_commandData.Application.ActiveUIDocument;
         m_document = m_uiDocument.Document;

         // initialize the curtain system data
         m_systemData = new CurtainSystem.SystemData(this);

         // get the curtain system type of the active Revit document
         GetCurtainSystemType();
      }
        public RevitUI.Result Execute(RevitUI.ExternalCommandData commandData, ref string message, RevitDB.ElementSet elements)
        {
            RevitUI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            RevitDB.Document   doc   = uidoc.Document;
            if (doc.IsFamilyDocument)//感觉族文档没必要
            {
                RevitUI.TaskDialog.Show("Revit", "该操作仅适用项目文档,不适用族文档!");
                return(RevitUI.Result.Succeeded);
            }
            try
            {
                RevitDB.ViewSchedule     vs   = doc.ActiveView as RevitDB.ViewSchedule;
                RevitDB.TableData        td   = vs.GetTableData();
                RevitDB.TableSectionData tsdh = td.GetSectionData(RevitDB.SectionType.Header);
                RevitDB.TableSectionData tsdb = td.GetSectionData(RevitDB.SectionType.Body);

                Excel.Application app = new Excel.Application();
                Excel.Workbooks   wbs = app.Workbooks;
                Excel.Workbook    wb  = wbs.Add(Type.Missing);
                Excel.Worksheet   ws  = wb.Worksheets["Sheet1"];

                int cs = tsdb.NumberOfColumns;
                int rs = tsdb.NumberOfRows;

                Excel.Range rg1 = ws.Cells[1, 1];
                Excel.Range rg2 = ws.Cells[1, cs];
                rg1.Value = vs.GetCellText(RevitDB.SectionType.Header, 0, 0);
                rg2.Value = "";
                Excel.Range rg = ws.get_Range(rg1, rg2);
                rg.Merge();
                rg.Font.Name           = "黑体";
                rg.Font.Bold           = 400;
                rg.Font.Size           = 14;
                rg.Font.ColorIndex     = Excel.XlColorIndex.xlColorIndexAutomatic;
                rg.HorizontalAlignment = Excel.Constants.xlCenter;
                rg.RowHeight           = 25;

                for (int i = 0; i < rs; i++)
                {
                    for (int j = 0; j < cs; j++)
                    {
                        RevitDB.CellType ct = tsdb.GetCellType(i, j);
                        ws.Cells[i + 2, j + 1] = vs.GetCellText(RevitDB.SectionType.Body, i, j);
                    }
                }

                rg1                    = ws.Cells[2, 1];
                rg2                    = ws.Cells[rs + 1, cs];
                rg                     = ws.get_Range(rg1, rg2);
                rg.Font.Name           = "仿宋";
                rg.Font.Size           = 11;
                rg.Font.ColorIndex     = Excel.XlColorIndex.xlColorIndexAutomatic;
                rg.HorizontalAlignment = Excel.Constants.xlCenter;
                rg.Borders.ColorIndex  = Excel.XlColorIndex.xlColorIndexAutomatic;
                rg.Borders.LineStyle   = Excel.XlLineStyle.xlContinuous;
                rg.EntireColumn.AutoFit();
                rg.RowHeight = 20;

                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).Weight        = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).ColorIndex    = 3;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).Weight     = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).ColorIndex = 3;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).Weight       = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).ColorIndex   = 3;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).Weight      = Excel.XlBorderWeight.xlMedium;
                rg.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).ColorIndex  = 3;

                SaveFileDialog sf = new SaveFileDialog();
                sf.Title        = "Revit";
                sf.AddExtension = true;
                sf.Filter       = "Excel2007文件|*.xlsx|Excel2003文件|*.xls|文本文件|*.txt|所有文件|*.*";
                sf.FileName     = vs.ViewName;
                if (DialogResult.OK == sf.ShowDialog())
                {
                    wb.SaveAs(sf.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                }

                app.AlertBeforeOverwriting = false;
                wb.Close(true, Type.Missing, Type.Missing);
                wbs.Close();
                app.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                wb  = null;
                wbs = null;
                app = null;
                GC.Collect();
            }
            catch (Exception)
            {
                return(RevitUI.Result.Cancelled);
            }

            RevitUI.TaskDialog.Show("Revit", "Revit Export Excel Successful!");
            return(RevitUI.Result.Succeeded);
        }
Beispiel #34
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit, ref string message, ElementSet elements)
        {
            try
            {

                //create a log file
                string tempPath = System.IO.Path.GetTempPath();
                string logPath = Path.Combine(tempPath, "dynamoLog.txt");

                if (File.Exists(logPath))
                    File.Delete(logPath);

                tw = new StreamWriter(logPath);
                tw.WriteLine("Dynamo log started " + System.DateTime.Now.ToString());

                m_revit = revit.Application;
                m_doc = m_revit.ActiveUIDocument;

                trans = new Transaction(m_doc.Document, "Dynamo");
                trans.Start();

                FailureHandlingOptions failOpt = trans.GetFailureHandlingOptions();
                failOpt.SetFailuresPreprocessor(new DynamoWarningSwallower());
                trans.SetFailureHandlingOptions(failOpt);

                m_revit.Idling += new EventHandler<IdlingEventArgs>(OnIdling);

                #region default level
                Level defaultLevel = null;
                FilteredElementCollector fecLevel = new FilteredElementCollector(m_doc.Document);
                fecLevel.OfClass(typeof(Level));
                for (int i = 0; i < fecLevel.ToElements().Count; i++)
                {
                    defaultLevel = fecLevel.ToElements()[i] as Level;
                    break;
                }

                #endregion

                DynamoWarningSwallower swallow = new DynamoWarningSwallower();

                dynElementSettings.SharedInstance.Revit = m_revit;
                dynElementSettings.SharedInstance.Doc = m_doc;
                dynElementSettings.SharedInstance.DefaultLevel = defaultLevel;
                dynElementSettings.SharedInstance.WarningSwallower = swallow;
                dynElementSettings.SharedInstance.MainTransaction = trans;
                dynElementSettings.SharedInstance.Writer = tw;
                //dynElementSettings settings = new dynElementSettings(m_revit, m_doc,
                    //defaultLevel, swallow, trans);

                //show the log
                dynamoForm = new dynBench();

                //get the window handle
                Process process = Process.GetCurrentProcess();
                new System.Windows.Interop.WindowInteropHelper(dynamoForm).Owner = process.MainWindowHandle;
                dynamoForm.Show();

                if (dynamoForm.DialogResult.HasValue && dynamoForm.DialogResult.Value == false)   //the WPF false is "cancel"
                {
                    tw.WriteLine("Dynamo log ended " + System.DateTime.Now.ToString());
                    tw.Close();

                    return Autodesk.Revit.UI.Result.Cancelled;
                }

            }
            catch (Exception e)
            {
                trans.Dispose();
                Debug.WriteLine(e.Message + ":" + e.StackTrace);
                Debug.WriteLine(e.InnerException);
                message = e.Message + " : " + e.StackTrace;

                if (tw != null)
                {
                    tw.WriteLine(e.Message);
                    tw.WriteLine(e.StackTrace);
                    tw.Close();
                }

                return Autodesk.Revit.UI.Result.Failed;
            }

            trans.Commit();

            return Autodesk.Revit.UI.Result.Succeeded;
        }
Beispiel #35
0
        private void ProcessSelection(string selectedFilePathName)
        {
            string runningMsg;

            if (selectedFilePathName != null)
            {
                if ((bool)chkInfoOnly.IsChecked)
                {
                    try {
                        RevitFileSniffer rfs = new RevitFileSniffer(selectedFilePathName);
                        rfs.ReportRevitInfo();
                    } catch (Exception ex) {
                        string ms = "\n\nDo you must have this file open? The sniffer cannot snif if it's open.";
                        System.Windows.MessageBox.Show(ex.Message + ms, "Error At RevitFileSniffer");
                    }
                    return;
                }
                Hide();
                FormMsgWPF HUD        = new FormMsgWPF();
                string     FileToOpen = selectedFilePathName;
                try {
                    OpenOptions op = new OpenOptions();
                    op.SetOpenWorksetsConfiguration(null);  // makes all worksets opened?
                    op.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach;
                    ModelPath mdlPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(FileToOpen);

                    string fName = System.IO.Path.GetFileNameWithoutExtension(FileToOpen);
                    string fext  = System.IO.Path.GetExtension(FileToOpen);

                    string UserInitials = Environment.UserName.ToString();
                    fName      = fName + "_" + UserInitials + fext;
                    runningMsg = selectedFilePathName + " for " + UserInitials;
                    HUD.SetMsg(runningMsg, "Processing for " + UserInitials);
                    HUD.Show();
                    string   source           = FileToOpen;
                    string[] stringSeparators = new string[] { "\\" };
                    var      result           = source.Split(stringSeparators, StringSplitOptions.None);

                    string    localPrjPath = string.Empty;
                    string    fullLFname   = string.Empty;
                    ModelPath localPath    = null;
                    try {
                        if (result.Length > 4)
                        {
                            localPrjPath = _locRevitRoot + "\\" + result[3] + "_" + UserInitials + "\\";
                            fullLFname   = localPrjPath + fName;
                            //MessageBox.Show(fullLFname, "First Pass Local Path");
                            localPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(fullLFname);
                        }
                        else
                        {
                            HUD.Close();
                            System.Windows.MessageBox.Show("Based on its location, the file selected does not look like a project file .\n\n" + FileToOpen, "Not Touching This Without A Ten Foot Pole");
                            Close();
                            return;
                        }

                        #region Check For Open Document
                        DocumentSet ds = _uiapp.Application.Documents;
                        foreach (Document d in ds)
                        {
                            String dF = d.PathName.Replace(@"\\SYSFILE\CADD", "J:");
                            if (fullLFname.ToUpper().Equals(dF.ToUpper()))
                            {
                                string msg = "You have " + selectedFilePathName + " already open";
                                msg = msg + " or it is linked to a file you have open. Either way";
                                msg = msg + " Revit will not let you open it until the other one is unloaded.";
                                System.Windows.MessageBox.Show(msg, "Sorry, You Cannot Open The File");
                                HUD.Close();
                                Close();
                                return;
                            }
                        }
                        #endregion

                        if (!Directory.Exists(localPrjPath))
                        {
                            try {
                                runningMsg = runningMsg + "\n\nCreated Local Folder: " + localPrjPath;
                                HUD.SetMsg(runningMsg, "Creating This Local Folder");
                                Directory.CreateDirectory(localPrjPath);
                            } catch (Exception ex) {
                                HUD.Close();
                                System.Windows.MessageBox.Show(localPrjPath + "\n\n" + ex.Message, "Error Creating Directory");
                                Close();
                                return;
                            }
                        }
                        else
                        {
                            runningMsg = runningMsg + "\n\nUsing Local Folder: " + localPrjPath;
                            HUD.SetMsg(runningMsg, "Using This Local Folder");
                        }
                    } catch (Exception) {
                        HUD.Close();
                        System.Windows.MessageBox.Show("Error: Did Not Create " + localPrjPath, "Debug");
                        Close();
                        return;
                    }

                    #region Handle any existing local file
                    if (File.Exists(fullLFname))
                    {
                        string StashFolder = localPrjPath + "PriorsStash\\";
                        runningMsg = runningMsg + "\n\nStashing Older Local File To: " + StashFolder;
                        HUD.SetMsg(runningMsg, "Stashing Older Local File To");
                        if (!Directory.Exists(StashFolder))
                        {
                            try {
                                Directory.CreateDirectory(StashFolder);
                            } catch (Exception ex) {
                                HUD.Close();
                                System.Windows.MessageBox.Show(StashFolder + "\n\n" + ex.Message, "Error Creating Directory");
                                Close();
                                return;
                            }
                        }
                        string OrgFNameWOExt = System.IO.Path.GetFileNameWithoutExtension(fullLFname);
                        string ext           = System.IO.Path.GetExtension(fullLFname);
                        string NewFNameWExt  = AssignNewUniqueFileName(StashFolder + OrgFNameWOExt + ext);
                        try {
                            File.Move(fullLFname, NewFNameWExt);
                            int qtyDeleted = LimitNumberOfStashedFiles(StashFolder + OrgFNameWOExt + ext, stashMax);
                            if (qtyDeleted > 0)
                            {
                                runningMsg = runningMsg + "\n\nTrashed " + qtyDeleted.ToString() + " stashed older file" + pluralOrNot(qtyDeleted) + " from the PriorsStash folder.";
                            }
                        } catch (Exception ex) {
                            HUD.Close();
                            System.Windows.MessageBox.Show(fullLFname + "\nto\n" + NewFNameWExt + "\n\n" + ex.Message, "File Error Moving File");
                            Close();
                            return;
                        }
                        string backupFldr = localPrjPath + OrgFNameWOExt + "_backup";
                        if (Directory.Exists(backupFldr))
                        {
                            try {
                                runningMsg = runningMsg + "\n\nTrashing Older Backup Folder: " + backupFldr;
                                HUD.SetMsg(runningMsg, "Trashing Older Backup Folder");
                                Directory.Delete(backupFldr, true);
                            } catch (Exception ex) {
                                HUD.Close();
                                System.Windows.MessageBox.Show(backupFldr + "\n\n" + ex.Message, "Error Deleting Backup Folder");
                                Close();
                                return;
                            }
                        }
                    }
                    #endregion

                    runningMsg = runningMsg + "\n\nLocal Document Is: " + fullLFname;
                    /////runningMsg = runningMsg + "\n\n" + ExcludeTheseMsg();
                    HUD.SetMsg(runningMsg, "Revit Is Opening This Document For " + UserInitials);
                    HUD.UpdateLayout();
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));
                    HUD.Close();
                    SetStatusBarText(_revitHandle, "Just guessing that maybe you actually think something is happening.");

                    #region Finally Create and Open
                    Autodesk.Revit.UI.UIDocument newUIDoc = null;

                    if (mdlPath != null || localPath != null)
                    {
                        AKSOpenUtils AKSOpen = new AKSOpenUtils(_uiapp, revVersion);
                        // MessageBox.Show(fullLFname, "Will OpenNewLocalFromModelPath");
                        PokeRevit();
                        newUIDoc = AKSOpen.DoOpenNewLocalFromModelPath(mdlPath, localPath);
                    }
                    #endregion
                    adWin.ComponentManager.Ribbon.Visibility = System.Windows.Visibility.Visible;
                } catch (Exception ex) {
                    HUD.Close();
                    System.Windows.MessageBox.Show(ex.Message + " | " + ex.InnerException.Message, "Where is this Bummer");
                    Close();
                    return;
                }

                UpDateRecentsList(FileToOpen);

                Close();
            }
        }
Beispiel #36
0
 /// <summary>
 /// Constructor, initialize fields and do some assert.
 /// If the Assert throw exception, creation will fail.
 /// </summary>
 /// <param name="commandData">ExternalCommandData</param>
 public RebarCreator(ExternalCommandData commandData)
 {
     m_rvtUIDoc = commandData.Application.ActiveUIDocument;
     Assert();
 }
Beispiel #37
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
            {
                m_project = commandData.Application.ActiveUIDocument;

                // Get the selected element and store it to data member.
                if (!GetSelectedElement())
                {
                    message = m_errorInformation;
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Create a BoundingBoxXYZ instance which used in NewViewSection() method
                if (!GenerateBoundingBoxXYZ())
                {
                    message = m_errorInformation;
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Create a section view.
                Transaction transaction = new Transaction(m_project.Document, "CreateSectionView");
                transaction.Start();
                ViewSection section = m_project.Document.Create.NewViewSection(m_box);
                if (null == section)
                {
                    message = "Can't create the ViewSection.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Modify some parameters to make it look better.
                section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
                transaction.Commit();

                // If everything goes right, give successful information and return succeeded.
                MessageBox.Show("Create view section succeeded.", "Revit");
                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception e)
            {
                message = e.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }