Esempio n. 1
0
 GetRebarsByPartitionHostMarkAssembly(
     Document doc, string partition, string hostMark, string assembly)
 {
     return(RebarsUtils.GetAllRebarsInDoc(doc)
            .Where(fi => (
                       (fi.LookupParameter(RebarsUtils.PARTITION).AsString() == partition) &&
                       (fi.LookupParameter(RebarsUtils.HOST_MARK).AsString() == hostMark) &&
                       (fi.LookupParameter(RebarsUtils.ASSEMBLY_MARK).AsString() == assembly)))
            .ToList());
 }
Esempio n. 2
0
 GetRebarsNotInAssemblyByPartitionHostMark(
     Document doc, string partition, string hostMark)
 {
     return(RebarsUtils.GetAllRebarsInDoc(doc)
            .Where(fi => (
                       (fi.LookupParameter(RebarsUtils.PARTITION).AsString() == partition) &&
                       (fi.LookupParameter(RebarsUtils.HOST_MARK).AsString() == hostMark) &&
                       (fi.LookupParameter(RebarsUtils.IS_IN_ASSEMBLY).AsInteger() == 0)))
            .ToList());
 }
Esempio n. 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Add an EventLogTraceListener object
            System.Diagnostics.Trace.Listeners.Add(
                new System.Diagnostics.EventLogTraceListener("Application"));

            // Lay the hands on the active document
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            // Set up a timer
            Timing myTimer = new Timing();

            myTimer.StartTime();
            try {
                IDictionary <string, ISet <string> > values =
                    RebarsUtils.GetPartitionHostMarkDic(doc);
                Schema schema =
                    ExtensibleStorageUtils.GetSchema(SCHEMA_GUID, SCHEMA_NAME, values);
                DataStorage dataStorage =
                    ExtensibleStorageUtils.GetDataStorage(doc, DATA_STORAGE_NAME);

                if (ExtensibleStorageUtils
                    .AssignValues(schema,
                                  dataStorage,
                                  values))
                {
                    TaskDialog.Show("Success!", "Everything has gone smoothly.");
                }

                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Result.Cancelled);
            }
            catch (Exception ex) {
                TaskDialog.Show("Exception",
                                string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                System.Diagnostics.Trace.Write(string.Format("{0}\n{1}",
                                                             ex.Message, ex.StackTrace));
                return(Result.Failed);
            }
            finally {
                myTimer.StopTime();
                System.Diagnostics.Trace
                .Write(string.Format("Time elapsed: {0}s",
                                     myTimer.Duration.TotalSeconds));
            }
        }
Esempio n. 4
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message, ElementSet elements)
        {
            Tracer.Listeners.Add(new
                                 System.Diagnostics.EventLogTraceListener("Application"));

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

            RebarsMarkerWnd wnd = null;

            try
            {
                // Get all the necessary particulars about partitions and
                // host marks from the repository
                Schema schema = ExtensibleStorageUtils
                                .GetSchema(UpdateRepository.SCHEMA_GUID);
                if (schema == null)
                {
                    TaskDialog.Show("Warning",
                                    "No repository exists. " +
                                    "Please generate one before proceeding with this command.");
                    return(Result.Cancelled);
                }

                // Dig up the data storage element
                Autodesk.Revit.DB.ExtensibleStorage.DataStorage ds =
                    ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME);
                if (ds == null)
                {
                    TaskDialog.Show("Warning", "No data storage element. " +
                                    "Please update the repository.");
                    return(Result.Cancelled);
                }

                // Retrieve host marks grouped by partition
                IDictionary <string, ISet <string> > partsHostMarks =
                    ExtensibleStorageUtils.GetValues(
                        schema,
                        ds,
                        UpdateRepository.FN_PARTS_HOST_MARKS);

                if (partsHostMarks.Keys.Count == 0)
                {
                    TaskDialog.Show("Warning",
                                    "No rebars to mark have been bagged.");
                    return(Result.Cancelled);
                }

                // Get hold of all assemblies grouped by host marks
                IDictionary <string, ISet <string> > hostMarksAssemblies =
                    ExtensibleStorageUtils.GetValues(
                        schema,
                        ds,
                        UpdateRepository.FN_HOST_MARKS_ASSEMBLIES);

                wnd = new RebarsMarkerWnd(partsHostMarks, hostMarksAssemblies);


                wnd.OkClicked += (sender, args) =>
                {
                    IList <FamilyInstance> filteredRebars = null;

                    if (args.Assemblies.Count == 0)
                    {
                        filteredRebars =
                            //GetRebarsNotInAssemblyByPartitionHostMark(
                            //    doc,
                            //    args.Partition,
                            //    args.HostMark);
                            RebarsUtils.GetAllRebars(
                                doc,
                                args.Partition,
                                args.HostMark)
                            .Cast <FamilyInstance>()
                            .ToList();
                    }
                    else
                    {
                        filteredRebars =
                            //GetRebarsByPartitionHostMarkAssembly(
                            //    doc,
                            //    args.Partition,
                            //    args.HostMark,
                            //    args.Assemblies.ElementAt(i));
                            RebarsUtils.GetAllRebars(
                                doc,
                                args.Partition,
                                args.HostMark,
                                args.Assemblies.ToList())
                            .Cast <FamilyInstance>()
                            .ToList();
                    }

                    Tracer.Write("The number of rebars looked up amounts to " + filteredRebars.Count);

                    // Group the rebars into three categories and mark them
                    GroupRebars(filteredRebars);
                };
                wnd.ShowDialog();

                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions
                   .OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (System.Exception ex)
            {
                string errorMsg = string.Format("{0}\n{1}", ex.Message, ex.StackTrace);
                Tracer.Write(errorMsg);
                TaskDialog.Show("Exception", errorMsg);
                return(Result.Failed);
            }
            finally
            {
                if (wnd != null)
                {
                    wnd.Close();
                }
            }
        }
Esempio n. 5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application"));

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

            RebarsCollectorWnd wnd = null;

            System.Text.StringBuilder strBld =
                new System.Text.StringBuilder();

            try
            {
                List <ViewType> allowedViews =
                    new List <ViewType>
                {
                    ViewType.EngineeringPlan,
                    ViewType.FloorPlan,
                    ViewType.Section,
                    ViewType.Elevation,
                    ViewType.Detail,
                    ViewType.DraftingView
                };

                List <ElementId> rebarIds = new List <ElementId>();

                // if the active view is a sheet, bag all the view belonging to it
                if (doc.ActiveView.ViewType == ViewType.DrawingSheet)
                {
                    ViewSheet vs = doc.ActiveView as ViewSheet;

                    foreach (ElementId viewId in vs.GetAllPlacedViews())
                    {
                        View view = doc.GetElement(viewId) as View;

                        if (allowedViews.Contains(view.ViewType))
                        {
                            rebarIds.AddRange(
                                RebarsUtils
                                .GetAllRebarIdsInView(view));
                        }
                    }
                }
                else if (allowedViews.Contains(doc.ActiveView.ViewType))
                {
                    rebarIds.AddRange(
                        RebarsUtils
                        .GetAllRebarIdsInView(doc.ActiveView));
                }

                if (rebarIds.Count == 0)
                {
                    TaskDialog.Show("Warning", "No rebars have been collected.");
                    return(Result.Cancelled);
                }

                // Get partitions and host marks from the data storage
                IDictionary <string, ISet <string> > partsHostMarks =
                    ExtensibleStorageUtils.GetValues(
                        ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID),
                        ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME),
                        UpdateRepository.FN_PARTS_HOST_MARKS);

                // Dig out assemblies grouped by partition + host mark names
                IDictionary <string, ISet <string> > partsMarksAssemblies =
                    ExtensibleStorageUtils.GetValues(
                        ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID),
                        ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME),
                        UpdateRepository.FN_HOST_MARKS_ASSEMBLIES);

                wnd = new RebarsCollectorWnd(partsHostMarks, partsMarksAssemblies);

                wnd.ButtonClicked += (sender, e) =>
                {
                    using (Transaction t = new Transaction(doc, "Set rebars' properties"))
                    {
                        t.Start();
                        foreach (ElementId rebarId in rebarIds)
                        {
                            strBld.Clear();
                            strBld.AppendFormat("Id: {0}",
                                                rebarId.ToString());

                            // Get hold of the element represented by its id
                            Element rebar = doc.GetElement(rebarId);

                            // See about the partitions
                            Parameter partition =
                                rebar.LookupParameter(RebarsUtils.PARTITION);
                            if (partition != null &&
                                !partition.IsReadOnly &&
                                e.Partition != null)
                            {
                                partition.Set(e.Partition);
                            }

                            // Set the value in the host mark parameter
                            Parameter hostMark =
                                rebar.LookupParameter(RebarsUtils.HOST_MARK);
                            if (hostMark != null &&
                                !hostMark.IsReadOnly &&
                                e.HostMark != null)
                            {
                                hostMark.Set(e.HostMark);
                            }

                            // if checked, set the value in the assembly mark parameter
                            Parameter assemblyMark =
                                rebar.LookupParameter(RebarsUtils.ASSEMBLY_MARK);
                            if (assemblyMark != null &&
                                !assemblyMark.IsReadOnly &&
                                e.AssemblyMark != null)
                            {
                                assemblyMark.Set(e.AssemblyMark);
                            }

                            // if checked and calculable, then set the value
                            Parameter isCalculable =
                                rebar.LookupParameter(RebarsUtils.IS_CALCULABLE);
                            if (e.IsCalculable != null &&
                                isCalculable != null &&
                                !isCalculable.IsReadOnly)
                            {
                                isCalculable
                                .Set((e.IsCalculable == true ? 1 : 0));
                            }

                            // if checked and specifiable, then set the value
                            Parameter isSpecifiable =
                                rebar.LookupParameter(RebarsUtils.IS_SPECIFIABLE);
                            if (e.IsSpecifiable != null &&
                                isSpecifiable != null &&
                                !isSpecifiable.IsReadOnly)
                            {
                                isSpecifiable
                                .Set((e.IsSpecifiable == true ? 1 : 0));
                            }
                            // if checked and in an assembly, then set the value
                            Parameter isAssembly =
                                rebar.LookupParameter(RebarsUtils.IS_IN_ASSEMBLY);
                            if (e.IsAssembly != null &&
                                isAssembly != null &&
                                !isAssembly.IsReadOnly)
                            {
                                isAssembly
                                .Set((bool)e.IsAssembly ? 1 : 0);
                            }
                        }
                        t.Commit();
                    }
                };

                wnd.ShowDialog();

                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions
                   .OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (System.Exception ex)
            {
                if (wnd != null)
                {
                    wnd.Close();
                }

                TaskDialog.Show("Exception",
                                string.Format("{0}\n{1}\n{2}",
                                              strBld.ToString(), ex.Message, ex.StackTrace));

                Tracer.Write(string.Format("{0}\n{1}",
                                           ex.Message, ex.StackTrace));

                return(Result.Failed);
            }
        }
Esempio n. 6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Add an EventLogTraceListener object
            System.Diagnostics.Trace.Listeners.Add(
                new System.Diagnostics.EventLogTraceListener("Application"));

            // Lay the hands on the active document
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            // Set up a timer
            Timing myTimer = new Timing();

            myTimer.StartTime();
            try {
                // Track down all partitions as well as map them
                // to host marks
                IDictionary <string, ISet <string> > partHostValues =
                    RebarsUtils.GetPartitionHostMarkDic(doc);

                RebarContainer rebarContainer = new RebarContainer();
                foreach (FamilyInstance fi in RebarsUtils.GetAllRebarsInDoc(doc))
                {
                    GeneralRebar rebar = new GeneralRebar(fi);
                    rebarContainer.Add(rebar);
                }

                // Dig up all host marks and map them
                // to assemblies
                IDictionary <string, ISet <string> > hostAssemblyValues =
                    rebarContainer.GetHostAssemblies();

                // Get hold of all partitions and
                // map them to structural types
                SortedList <string, SortedSet <string> > partsStrTypes =
                    TektaRevitPlugins.Multischedule.MultischeduleUtils.DigUpPartsStrTypes(doc);

                Schema schema =
                    ExtensibleStorageUtils.GetSchema(
                        SCHEMA_GUID, SCHEMA_NAME,
                        FN_PARTS_HOST_MARKS,
                        FN_HOST_MARKS_ASSEMBLIES,
                        FN_PARTS_STR_TYPES);

                DataStorage dataStorage =
                    ExtensibleStorageUtils.GetDataStorage(
                        doc, DATA_STORAGE_NAME);

                ExtensibleStorageUtils
                .AssignValues(schema,
                              dataStorage,
                              FN_PARTS_HOST_MARKS,
                              FN_HOST_MARKS_ASSEMBLIES,
                              FN_PARTS_STR_TYPES,
                              partHostValues,
                              hostAssemblyValues,
                              partsStrTypes);

                TaskDialog.Show("Success!", "Repository has been updated.");
                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Result.Cancelled);
            }
            catch (Exception ex) {
                TaskDialog.Show("Exception",
                                string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                System.Diagnostics.Trace.Write(string.Format("{0}\n{1}",
                                                             ex.Message, ex.StackTrace));
                return(Result.Failed);
            }
            finally {
                myTimer.StopTime();
                System.Diagnostics.Trace
                .Write(string.Format("Time elapsed: {0}s",
                                     myTimer.Duration.TotalSeconds));
            }
        }