Esempio n. 1
0
        List <FileInfo> m_FileDwgList; //list of read files before export to the directory

        #endregion


        #region <constructors>
        public REXExpImpMng(REXExtension argExt)
            : base(argExt)
        {
            m_CommandData = argExt.Revit.CommandData();

            m_FileDwgList = new List <FileInfo>();
        }
Esempio n. 2
0
        public Autodesk.Revit.UI.Result Execute
            (Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Get access to the active uidoc and doc
            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = commandData.Application.ActiveUIDocument.Document;

            Autodesk.Revit.UI.Selection.Selection sel = uidoc.Selection;

            try {
                Reference r =
                    sel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                Element elem = doc.GetElement(r);

                IList <ElementId> elemsWithinBBox = WallJoinerCmd
                                                    .GetWallsIntersectBoundingBox(doc, elem)
                                                    .Select(e => e.Id)
                                                    .ToList();

                sel.SetElementIds(elemsWithinBBox);

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (Exception ex) {
                Autodesk.Revit.UI.TaskDialog.Show("Exception",
                                                  string.Format("Message: {0}\nStackTrace: {1}",
                                                                ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 3
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.
                                                ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application"));

            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            try {
                IList <Wall> walls = new FilteredElementCollector(doc)
                                     .OfClass(typeof(Wall))
                                     .WhereElementIsNotElementType()
                                     .Cast <Wall>()
                                     .ToList();

                Tracer.Write("All the walls in the project: " + walls.Count);

                foreach (Wall wall in walls)
                {
                    IList <Element> intrudingWalls =
                        GetWallsIntersectBoundingBox(doc, wall);

                    Tracer.Write(string.Format("Wall {0} is intersected by {1} walls",
                                               wall.Id.ToString(), intrudingWalls.Count));

                    using (Transaction t = new Transaction(doc, "Join walls")) {
                        t.Start();
                        foreach (Element elem in intrudingWalls)
                        {
                            if (((Wall)elem).WallType.Kind == WallKind.Curtain)
                            {
                                continue;
                            }
                            try {
                                if (!JoinGeometryUtils.AreElementsJoined(doc, wall, elem))
                                {
                                    JoinGeometryUtils.JoinGeometry(doc, wall, elem);
                                }
                            }
                            catch (Exception ex) {
                                Tracer.Write(string.Format("{0}\nWall: {1} cannot be joined to {2}",
                                                           ex.Message, wall.Id.ToString(), elem.Id.ToString()));
                                continue;
                            }
                        }
                        t.Commit();
                    }
                }

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (Exception ex) {
                Tracer.Write(string.Format("{0}\n{1}",
                                           ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Overload constructor
 /// </summary>
 /// <param name="pathRein">path reinforcement object</param>
 /// <param name="commandData">revit command data</param>
 public PathReinforcementForm(Autodesk.Revit.DB.Structure.PathReinforcement pathRein,
                              Autodesk.Revit.UI.ExternalCommandData commandData) : this()
 {
     m_pathRein   = pathRein;
     m_properties = new PathReinProperties(pathRein);
     m_properties.UpdateSelectObjEvent += new PathReinProperties.UpdateSelectObjEventHandler(UpdatePropSelectedObject);
     this.propertyGrid.SelectedObject   = m_properties;
     m_profile = new Profile(pathRein, commandData);
 }
Esempio n. 5
0
        // public Result HandleData(ExternalCommandData commandData, ref string message, ElementSet elements)
        public void Test_399_HandleData()
        {
            ExeWriter.CF_WriterUtils     Target   = new ExeWriter.CF_WriterUtils();
            Autodesk.Revit.UI.ElementSet elements = new Autodesk.Revit.UI.ElementSet();
            string message = null;

            Autodesk.Revit.UI.ExternalCommandData commandData = new Autodesk.Revit.UI.ExternalCommandData();
            Autodesk.Revit.UI.Result ARUIResult = Target.HandleData(commandData, ref message, elements);
            Assert.IsNotNull(Target);
        }
Esempio n. 6
0
        /// <inheritdoc />
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var win       = new SettingsWindow();
            var viewModel = new SettingsViewModel(win);

            win.DataContext = viewModel;
            win.Closed     += (sender, args) => viewModel.ApplySettings();
            win.ShowDialog();
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Esempio n. 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(
            Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            ElementSet collection = revit.ActiveUIDocument.Selection.Elements;

            // check user selection
            if (collection.Size < 1)
            {
                message = "Please select object(s) before delete.";
                return(Autodesk.Revit.UI.Result.Cancelled);
            }

            bool error = true;

            try
            {
                error = true;

                // delete selection
                IEnumerator e         = collection.GetEnumerator();
                bool        MoreValue = e.MoveNext();
                while (MoreValue)
                {
                    Element component = e.Current as Element;
                    revit.ActiveUIDocument.Document.Delete(component);
                    MoreValue = e.MoveNext();
                }

                error = false;
            }
            catch
            {
                // if revit threw an exception, try to catch it
                foreach (Element c in collection)
                {
                    elements.Insert(c);
                }
                message = "object(s) can't be deleted.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                // if revit threw an exception, display error and return failed
                if (error)
                {
                    MessageBox.Show("Delete failed.");
                }
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Esempio n. 8
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            System.Diagnostics.Trace.Listeners.
            Add(new System.Diagnostics.EventLogTraceListener("Application"));

            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.DB.Document   doc   = uidoc.Document;

            try {
                CreateSharedParamWin hwnd =
                    new CreateSharedParamWin(doc);
                hwnd.ShowDialog();

                if (hwnd.ParameterName == null ||
                    hwnd.ParameterName.Length == 0)
                {
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }

                SharedParametersManager spManager =
                    new SharedParametersManager(doc);
                spManager.CreateSharedParameter(
                    hwnd.ParameterName,
                    hwnd.ParameterType,
                    new List <BuiltInCategory>
                {
                    hwnd.Category
                },
                    hwnd.ParameterGroup,
                    hwnd.IsInstance,
                    hwnd.IsModifiable,
                    hwnd.IsVisible,
                    hwnd.GroupName
                    );

                if (hwnd.CanVaryBtwGroups)
                {
                    spManager.CanVaryBtwGroups(hwnd.ParameterName, true);
                }

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (System.Exception ex) {
                Autodesk.Revit.UI.TaskDialog.Show("Exception",
                                                  string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 9
0
        //public bool partExists(string str_FileName)
        public void Test_011_partExists()
        {
            ExeWriter.Cl_Exewriter Target = new ExeWriter.Cl_Exewriter();

            Autodesk.Revit.UI.ExternalCommandData commandData = new Autodesk.Revit.UI.ExternalCommandData();
            string message = null;

            Autodesk.Revit.UI.ElementSet elements  = new Autodesk.Revit.UI.ElementSet();
            Autodesk.Revit.UI.Result     ARUResult = Target.Execute(commandData, ref message, elements);
            Assert.AreEqual(ARUResult, Autodesk.Revit.UI.Result.Failed);
            ARUResult = Target.Execute(commandData, ref message, elements);
            Assert.AreEqual(ARUResult, Autodesk.Revit.UI.Result.Succeeded);
        }
Esempio n. 10
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(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (!Validation.ValidateMep(commandData.Application.Application))
            {
                Validation.MepWarning();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            if (!Validation.ValidatePipesDefined(commandData.Application.ActiveUIDocument.Document))
            {
                Validation.PipesDefinedWarning();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            ofd.DefaultExt = ".xml";
            ofd.Filter     = "RoutingPreference Builder Xml files (*.xml)|*.xml";

            if (ofd.ShowDialog() == true)
            {
                StreamReader reader = new StreamReader(ofd.FileName);
                XDocument    routingPreferenceBuilderDoc = XDocument.Load(new XmlTextReader(reader));
                reader.Close();

                //Distribute the .xsd file to routing preference builder xml authors as necessary.
                string xmlValidationMessage;
                if (!SchemaValidationHelper.ValidateRoutingPreferenceBuilderXml(routingPreferenceBuilderDoc, out xmlValidationMessage))
                {
                    Autodesk.Revit.UI.TaskDialog.Show("RoutingPreferenceBuilder", "Xml file is not a valid RoutingPreferenceBuilder xml document.  Please check RoutingPreferenceBuilderData.xsd.  " + xmlValidationMessage);
                    return(Autodesk.Revit.UI.Result.Succeeded);
                }
                try
                {
                    RoutingPreferenceBuilder builder = new RoutingPreferenceBuilder(commandData.Application.ActiveUIDocument.Document);
                    builder.ParseAllPipingPoliciesFromXml(routingPreferenceBuilderDoc);
                    Autodesk.Revit.UI.TaskDialog.Show("RoutingPreferenceBuilder", "Routing Preferences imported successfully.");
                }
                catch (RoutingPreferenceDataException ex)
                {
                    Autodesk.Revit.UI.TaskDialog.Show("RoutingPreferenceBuilder error: ", ex.ToString());
                }
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Esempio n. 11
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(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (!Validation.ValidateMep(commandData.Application.Application))
            {
                Validation.MepWarning();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            if (!Validation.ValidatePipesDefined(commandData.Application.ActiveUIDocument.Document))
            {
                Validation.PipesDefinedWarning();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            MainWindow mainWindow = new MainWindow(commandData.Application);

            mainWindow.ShowDialog();
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Esempio n. 12
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(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (!Validation.ValidateMep(commandData.Application.Application))
            {
                Validation.MepWarning();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            if (!Validation.ValidatePipesDefined(commandData.Application.ActiveUIDocument.Document))
            {
                Validation.PipesDefinedWarning();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
            sfd.DefaultExt = ".xml";
            sfd.Filter     = "RoutingPreference Builder Xml files (*.xml)|*.xml";
            sfd.FileName   = (System.IO.Path.GetFileNameWithoutExtension(commandData.Application.ActiveUIDocument.Document.PathName)) + ".routingPreferences.xml";
            if (sfd.ShowDialog() == true)
            {
                RoutingPreferenceBuilder builder = new RoutingPreferenceBuilder(commandData.Application.ActiveUIDocument.Document);
                bool              pathsNotFound  = false;
                XDocument         routingPreferenceBuilderDoc = builder.CreateXmlFromAllPipingPolicies(ref pathsNotFound);
                XmlWriterSettings xmlWriterSettings           = new XmlWriterSettings();
                xmlWriterSettings.Indent = true;
                xmlWriterSettings.NewLineOnAttributes = false;
                XmlWriter writer = XmlWriter.Create(sfd.FileName, xmlWriterSettings);
                routingPreferenceBuilderDoc.WriteTo(writer);
                writer.Flush();
                writer.Close();
                string pathmessage = "";
                if (pathsNotFound)
                {
                    pathmessage = "One or more paths to .rfa files were not found.  You may need to add these paths in manually to the generated xml file.";
                }
                Autodesk.Revit.UI.TaskDialog.Show("RoutingPreferenceBuilder", "Routing Preferences exported successfully.   " + pathmessage);
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
 /// <summary>
 /// Overload the constructor
 /// </summary>
 /// <param name="commandData">an instance of Data class</param>
 public ViewFiltersForm(Autodesk.Revit.UI.ExternalCommandData commandData)
 {
     InitializeComponent();
     m_doc = commandData.Application.ActiveUIDocument.Document;
 }
Esempio n. 14
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Trace.Listeners
            .Add(new System.Diagnostics.EventLogTraceListener("Application"));

            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            try {
                // get hold of the print manager
                Autodesk.Revit.DB.PrintManager printManager =
                    doc.PrintManager;

                // select the printer
                printManager.SelectNewPrintDriver("Adobe PDF");
                printManager.PrintRange   = Autodesk.Revit.DB.PrintRange.Select;
                printManager.CombinedFile = false;
                if (printManager.IsVirtual != Autodesk.Revit.DB.VirtualPrinterType.AdobePDF)
                {
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // access the in-session print settings
                Autodesk.Revit.DB.IPrintSetting printSetting =
                    printManager.PrintSetup.InSession;

                printSetting.PrintParameters.PaperPlacement =
                    Autodesk.Revit.DB.PaperPlacementType.Margins;
                printSetting.PrintParameters.MarginType =
                    Autodesk.Revit.DB.MarginType.NoMargin;
                printSetting.PrintParameters.ZoomType      = Autodesk.Revit.DB.ZoomType.Zoom;
                printSetting.PrintParameters.Zoom          = 100;
                printSetting.PrintParameters.ColorDepth    = Autodesk.Revit.DB.ColorDepthType.BlackLine;
                printSetting.PrintParameters.RasterQuality = Autodesk.Revit.DB.RasterQualityType.High;
                //printManager.Apply();

                // Promt the user to select the sets to print out
                PrintWnd hwnd = new PrintWnd(doc);
                hwnd.ShowDialog();

                IList <RvtElement> sets = hwnd.SelectedSets;

                for (int i = 0; i < sets.Count; ++i)
                {
                    ViewSheetSet set = sets[i] as ViewSheetSet;

                    foreach (Autodesk.Revit.DB.View view in set.Views)
                    {
                        if (view is ViewSheet)
                        {
                            SetUpSizeAndPrint((ViewSheet)view, printManager, printSetting);
                        }
                    }
                }
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (System.Exception ex) {
                Trace.Write(string.Format("Command Exception:\n{0}\n{1}",
                                          ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 15
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Trace.Listeners
            .Add(new System.Diagnostics.EventLogTraceListener("Application"));

            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.DB.Document   doc   = uidoc.Document;

            try {
                // get hold of the print manager
                Autodesk.Revit.DB.PrintManager printManager =
                    doc.PrintManager;

                // select the printer
                printManager.SelectNewPrintDriver("Adobe PDF");
                printManager.PrintRange = Autodesk.Revit.DB.PrintRange.Select;
                if (printManager.IsVirtual != Autodesk.Revit.DB.VirtualPrinterType.AdobePDF)
                {
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // access the in-session print settings
                Autodesk.Revit.DB.IPrintSetting printSetting =
                    printManager.PrintSetup.InSession;

                printSetting.PrintParameters.PaperPlacement =
                    Autodesk.Revit.DB.PaperPlacementType.Margins;
                printSetting.PrintParameters.MarginType =
                    Autodesk.Revit.DB.MarginType.NoMargin;
                printSetting.PrintParameters.ZoomType = Autodesk.Revit.DB.ZoomType.Zoom;
                printSetting.PrintParameters.Zoom     = 100;

                //
                IList <Autodesk.Revit.DB.ViewSheetSet> viewSheetSets = GetViewSheetSet(doc);
                System.Text.StringBuilder strBld = new System.Text.StringBuilder();
                foreach (Autodesk.Revit.DB.ViewSheetSet vss in viewSheetSets)
                {
                    strBld.AppendLine(string.Format("Name:{0}; Views.Count={1}", vss.Name, vss.Views.Size));
                }
                Trace.Write(strBld.ToString());
                return(Autodesk.Revit.UI.Result.Succeeded);

                //

                // apply the updated settings and print
                foreach (Autodesk.Revit.DB.View view in printManager.ViewSheetSetting.AvailableViews)
                {
                    if (view.ViewType == Autodesk.Revit.DB.ViewType.DrawingSheet)
                    {
                        SetUpSizeAndPrint((ViewSheet)view, printManager, printSetting);
                    }
                }
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (System.Exception ex) {
                Trace.Write(string.Format("Command Exception:\n{0}\n{1}",
                                          ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 16
0
        //*****************************************************************************
        #endregion

        #region <constructors>
        //*****************************************************************************
        public REXRevitData(Autodesk.Revit.UI.ExternalCommandData argCommandData)
        {
            m_ViewListStr = new List <string>();
            m_ViewList    = new List <View>();
            m_CommandData = argCommandData;
        }
Esempio n. 17
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            System.Diagnostics.Trace.Listeners.
            Add(new System.Diagnostics.EventLogTraceListener("Application"));

            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.DB.Document   doc   = uidoc.Document;


            try {
                // set the location of a new .txt file
                string filePath = System.Environment
                                  .GetFolderPath(Environment.SpecialFolder.Personal) +
                                  "\\" + doc.Title + ".txt";

                // Create the .txt file containing shared parameter definitions
                using (System.IO.Stream s = System.IO.File.Create(filePath)) {
                    s.Close();
                }

                // set the file as a shared parameter source file to the application
                doc.Application.SharedParametersFilename = filePath;

                // Get access to the file
                Autodesk.Revit.DB.DefinitionFile defFile =
                    doc.Application.OpenSharedParameterFile();

                // Create a new group called 'ReadOnly'
                Autodesk.Revit.DB.DefinitionGroup defGroup =
                    defFile.Groups.Create("ReadOnly");

                // Create a new defintion
                Autodesk.Revit.DB.ExternalDefinitionCreationOptions defCrtOptns =
                    new Autodesk.Revit.DB.ExternalDefinitionCreationOptions
                        ("RM_BLOCK", Autodesk.Revit.DB.ParameterType.Text);
                defCrtOptns.UserModifiable = false;
                defCrtOptns.Visible        = true;

                // Insert the definition into the group
                Autodesk.Revit.DB.Definition def =
                    defGroup.Definitions.Create(defCrtOptns);

                // Lay out the categories to which the param
                // will be bound
                Autodesk.Revit.DB.CategorySet catSet =
                    new Autodesk.Revit.DB.CategorySet();
                catSet.Insert(doc.Settings.Categories
                              .get_Item(Autodesk.Revit.DB.BuiltInCategory.OST_Rooms));

                // Define a binding type
                Autodesk.Revit.DB.InstanceBinding instBnd =
                    new Autodesk.Revit.DB.InstanceBinding(catSet);

                // Bind the parameter to the active document
                using (Autodesk.Revit.DB.Transaction t =
                           new Autodesk.Revit.DB.Transaction(doc)) {
                    t.Start("Add Param");
                    Autodesk.Revit.DB.SubTransaction st =
                        new Autodesk.Revit.DB.SubTransaction(doc);
                    doc.ParameterBindings.Insert
                        (def, instBnd, Autodesk.Revit.DB.BuiltInParameterGroup.PG_DATA);
                    t.Commit();
                }

                Autodesk.Revit.DB.DefinitionBindingMapIterator itr =
                    doc.ParameterBindings.ForwardIterator();

                //
                while (itr.MoveNext())
                {
                    Autodesk.Revit.DB.InternalDefinition intDef = itr.Current as
                                                                  Autodesk.Revit.DB.InternalDefinition;
                }

                Autodesk.Revit.UI.TaskDialog.Show("Success",
                                                  string.Format("The parameter called {0} has been successfully added to the document",
                                                                def.Name));

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (System.Exception ex) {
                Autodesk.Revit.UI.TaskDialog.Show("Exception",
                                                  string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Esempio n. 18
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.
                                                ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application"));

            Autodesk.Revit.UI.UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            try {
                // Set the minimum wall width
                double minWallWidth = UnitUtils
                                      .ConvertToInternalUnits(400, DisplayUnitType.DUT_MILLIMETERS); // 400mm

                // Select all walls wider than 400 mm
                ElementParameterFilter widthFilter =
                    new ElementParameterFilter(ParameterFilterRuleFactory
                                               .CreateGreaterOrEqualRule(new ElementId(BuiltInParameter.WALL_ATTR_WIDTH_PARAM),
                                                                         minWallWidth, 0.1));

                IList <Wall> walls = new FilteredElementCollector(doc)
                                     .OfClass(typeof(Wall))
                                     .WhereElementIsNotElementType()
                                     .WherePasses(widthFilter)
                                     .Cast <Wall>()
                                     .ToList();

                Tracer.Write("The number of walls in the project: " + walls.Count);

                using (Transaction t = new Transaction(doc, "Join walls")) {
                    FailureHandlingOptions handlingOptions = t.GetFailureHandlingOptions();
                    handlingOptions.SetFailuresPreprocessor(new AllWarningSwallower());
                    t.SetFailureHandlingOptions(handlingOptions);
                    t.Start();

                    foreach (Wall wall in walls)
                    {
                        IList <Element> intrudingWalls =
                            GetWallsIntersectBoundingBox(doc, wall, minWallWidth);

                        Tracer.Write(string.Format("Wall {0} is intersected by {1} walls",
                                                   wall.Id.ToString(), intrudingWalls.Count));

                        foreach (Element elem in intrudingWalls)
                        {
                            if (//((Wall)elem).WallType.Width < minWallWidth ||
                                ((Wall)elem).WallType.Kind == WallKind.Curtain)
                            {
                                continue;
                            }
                            try {
                                if (!JoinGeometryUtils.AreElementsJoined(doc, wall, elem))
                                {
                                    JoinGeometryUtils.JoinGeometry(doc, wall, elem);
                                }
                            }
                            catch (Exception ex) {
                                Tracer.Write(string.Format("{0}\nWall: {1} cannot be joined to {2}",
                                                           ex.Message, wall.Id.ToString(), elem.Id.ToString()));
                                continue;
                            }
                        }
                    }
                    t.Commit();
                }

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (Exception ex) {
                Tracer.Write(string.Format("{0}\n{1}",
                                           ex.Message, ex.StackTrace));
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }