public void testRebarSys()
        {
            UIDocument uiDoc = this.ActiveUIDocument;
            Document   doc   = uiDoc.Document;


            // Load rebar Shape
            FilteredElementCollector fecRebarShap = new FilteredElementCollector(doc)
                                                    .OfClass(typeof(RebarShape));

            IEnumerable <RebarShape> iterRebarBarShapes = fecRebarShap.Cast <RebarShape>();

            RebarShape myRebarShape   = iterRebarBarShapes.FirstOrDefault <RebarShape>();
            ElementId  myRebarShapeId = myRebarShape.Id;


            // Select first Element (ex RebarSystem)
            Reference myRefRebar = uiDoc.Selection.PickObject(ObjectType.Element,
                                                              "Pick a Rebar...");
            Element       mySysRebar   = doc.GetElement(myRefRebar);
            RebarInSystem myRebarInSys = mySysRebar as RebarInSystem;

            List <Subelement> myList = myRebarInSys.GetSubelements() as List <Subelement>;



            TaskDialog.Show("abc", "xyz" + myList.Count);
        }
Example #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document       doc    = commandData.Application.ActiveUIDocument.Document;
            UIDocument     uidoc  = commandData.Application.ActiveUIDocument;
            View           view   = doc.ActiveView;
            List <Element> rebars = RebarSelectHelper.GetSelectedOrAll(uidoc);

            using (Transaction t1 = new Transaction(doc, "Set Unobscured in View"))
            {
                t1.Start();
                foreach (Element rebar in rebars)
                {
                    if (rebar is RebarInSystem)
                    {
                        RebarInSystem r = (RebarInSystem)rebar;

                        if (!r.IsUnobscuredInView(view))
                        {
                            r.SetUnobscuredInView(view, true);
                        }
                    }
                    if (rebar is Rebar)
                    {
                        Rebar r = (Rebar)rebar;

                        if (!r.IsUnobscuredInView(view))
                        {
                            r.SetUnobscuredInView(view, true);
                        }
                    }
                }
                t1.Commit();
            }
            return(Result.Succeeded);
        }
Example #3
0
 /// <summary>
 /// Gets bar position transform.
 /// </summary>
 /// <param name="element">The rebar element.</param>
 /// <param name="barPositionIndex">The bar position.</param>
 /// <returns>The transform.</returns>
 static Transform GetBarPositionTransform(object element, int barPositionIndex)
 {
     if (element is Rebar)
     {
         Rebar     rebar             = element as Rebar;
         Transform movedBarTransform = rebar.GetMovedBarTransform(barPositionIndex);
         if (rebar.IsRebarFreeForm())
         {
             return(movedBarTransform);
         }
         else
         {
             // shape driven
             Transform barPosTrf = rebar.GetShapeDrivenAccessor().GetBarPositionTransform(barPositionIndex);
             Transform entireTrf = movedBarTransform.Multiply(barPosTrf);
             return(entireTrf);
         }
     }
     else if (element is RebarInSystem)
     {
         RebarInSystem rebarInSystem = element as RebarInSystem;
         Transform     barPosTrf     = rebarInSystem.GetBarPositionTransform(barPositionIndex);
         Transform     movedBarTrf   = rebarInSystem.GetMovedBarTransform(barPositionIndex);
         Transform     entireTrf     = movedBarTrf.Multiply(barPosTrf);
         return(entireTrf);
     }
     else if (element is RebarContainerItem)
     {
         return((element as RebarContainerItem).GetBarPositionTransform(barPositionIndex));
     }
     else
     {
         throw new ArgumentException("Not a rebar.");
     }
 }
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false); // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            AnalyticalModel aModel = e.ObjToSnoop as AnalyticalModel;

            if (aModel != null)
            {
                Stream(snoopCollector.Data(), aModel);
                return;
            }

            CompoundStructure compStruct = e.ObjToSnoop as CompoundStructure;

            if (compStruct != null)
            {
                Stream(snoopCollector.Data(), compStruct);
                return;
            }

            CompoundStructureLayer compStructLayer = e.ObjToSnoop as CompoundStructureLayer;

            if (compStructLayer != null)
            {
                Stream(snoopCollector.Data(), compStructLayer);
                return;
            }

            AnalyticalModelSupport supportData = e.ObjToSnoop as AnalyticalModelSupport;

            if (supportData != null)
            {
                Stream(snoopCollector.Data(), supportData);
                return;
            }

            RebarInSystem barDesc = e.ObjToSnoop as RebarInSystem;

            if (barDesc != null)
            {
                Stream(snoopCollector.Data(), barDesc);
                return;
            }
        }
Example #5
0
 public void SetUnobscuredInView(View v, bool IsUnobsqured)
 {
     if (RevitBar is Rebar)
     {
         Rebar bar = RevitBar as Rebar;
         bar.SetUnobscuredInView(v, IsUnobsqured);
     }
     if (RevitBar is RebarInSystem)
     {
         RebarInSystem bar = RevitBar as RebarInSystem;
         bar.SetUnobscuredInView(v, IsUnobsqured);
     }
 }
Example #6
0
 public void SetSolidInView(View3D v, bool AsBody)
 {
     if (RevitBar is Rebar)
     {
         Rebar bar = RevitBar as Rebar;
         bar.SetSolidInView(v, AsBody);
     }
     if (RevitBar is RebarInSystem)
     {
         RebarInSystem bar = RevitBar as RebarInSystem;
         bar.SetSolidInView(v, AsBody);
     }
 }
Example #7
0
        Stream(ArrayList data, RebarInSystem barDesc)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RebarInSystem)));

            data.Add(new Snoop.Data.Object("Bar type", GetElementById(barDesc.GetTypeId())));
            data.Add(new Snoop.Data.Object("Bar shape", GetElementById(barDesc.RebarShapeId)));
            //data.Add(new Snoop.Data.Bool("Hooks in same direction", barDesc.HooksInSameDirection));
            //data.Add(new Snoop.Data.Int("Layer", barDesc.Layer));
            data.Add(new Snoop.Data.Double("Length", barDesc.TotalLength));

            //data.Add(new Snoop.Data.CategorySeparator("Hook Types"));
            //data.Add(new Snoop.Data.Int("Count", barDesc.Count));

            data.Add(new Snoop.Data.Object("Start hook type", barDesc.GetHookTypeId(0)));
            data.Add(new Snoop.Data.Object("End hook type", barDesc.GetHookTypeId(1)));
        }
Example #8
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document   doc   = commandData.Application.ActiveUIDocument.Document;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            View3D view = doc.ActiveView as View3D;

            if (view == null)
            {
                TaskDialog.Show("Warning", "Active view must be a 3D view.");
                return(Result.Failed);
            }


            List <Element> rebars = RebarSelectHelper.GetSelectedOrAll(uidoc);

            using (Transaction t3 = new Transaction(doc, "Set Solid in View"))
            {
                t3.Start();
                foreach (Element rebar in rebars)
                {
                    if (rebar is RebarInSystem)
                    {
                        RebarInSystem r = (RebarInSystem)rebar;
                        if (!r.IsSolidInView(view))
                        {
                            r.SetSolidInView(view, true);
                        }
                    }
                    else if (rebar is Rebar)
                    {
                        Rebar r = (Rebar)rebar;
                        if (!r.IsSolidInView(view))
                        {
                            r.SetSolidInView(view, true);
                        }
                    }
                }
                t3.Commit();
            }
            return(Result.Succeeded);
        }
        private void Stream(ArrayList data, RebarInSystem barDesc)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RebarInSystem)));

             data.Add(new Snoop.Data.Object("Bar type", GetElementById(barDesc.GetTypeId())));
             data.Add(new Snoop.Data.Object("Bar shape", GetElementById(barDesc.RebarShapeId)));
             //data.Add(new Snoop.Data.Bool("Hooks in same direction", barDesc.HooksInSameDirection));
             //data.Add(new Snoop.Data.Int("Layer", barDesc.Layer));
             data.Add(new Snoop.Data.Double("Length", barDesc.TotalLength));

             //data.Add(new Snoop.Data.CategorySeparator("Hook Types"));
             //data.Add(new Snoop.Data.Int("Count", barDesc.Count));

             data.Add(new Snoop.Data.Object("Start hook type", barDesc.GetHookTypeId(0)));
             data.Add(new Snoop.Data.Object("End hook type", barDesc.GetHookTypeId(1)));
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("SelectHost"));

            UIDocument       uiDoc  = commandData.Application.ActiveUIDocument;
            Document         doc    = uiDoc.Document;
            Selection        sel    = uiDoc.Selection;
            List <ElementId> selIds = sel.GetElementIds().ToList();

            if (selIds.Count != 1)
            {
                message = "Выберите элемент, для которого нужно найти основу.";
                return(Result.Failed);
            }
            Element selElem = doc.GetElement(selIds.First());

            Debug.WriteLine("Selected elem id: " + selElem.Id.IntegerValue.ToString());
            ElementId hostId = null;


            if (selElem is AreaReinforcement)
            {
                AreaReinforcement el = selElem as AreaReinforcement;
                hostId = el.GetHostId();
                Debug.WriteLine("It is area reinforcement");
            }
            if (selElem is PathReinforcement)
            {
                PathReinforcement el = selElem as PathReinforcement;
                hostId = el.GetHostId();
                Debug.WriteLine("It is path reinforcement");
            }
            if (selElem is Rebar)
            {
                Rebar el = selElem as Rebar;
                hostId = el.GetHostId();
                Debug.WriteLine("It is rebar");
            }
            if (selElem is RebarInSystem)
            {
                RebarInSystem el = selElem as RebarInSystem;
                hostId = el.SystemId;
                Debug.WriteLine("It is rebar in system");
            }

            if (selElem is FamilyInstance)
            {
                FamilyInstance el   = selElem as FamilyInstance;
                Element        host = el.Host;
                if (host != null)
                {
                    hostId = host.Id;
                    Debug.WriteLine("It is family instance with host");
                }
                else
                {
                    Element parentFamily = el.SuperComponent;
                    if (parentFamily != null)
                    {
                        Debug.WriteLine("It is family instance with parent family");
                        hostId = parentFamily.Id;
                    }
                }
            }


            if (hostId == null)
            {
                message = "Не удалось получить родительский элемент.";
                Debug.WriteLine("Host not found");
                return(Result.Failed);
            }
            else
            {
                sel.SetElementIds(new List <ElementId> {
                    hostId
                });
                Debug.WriteLine("Host id: " + hostId.IntegerValue.ToString());
                return(Result.Succeeded);
            }
        }
Example #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("RebarPresentation"));
            Document     doc  = commandData.Application.ActiveUIDocument.Document;
            View         v    = doc.ActiveView;
            Selection    sel  = commandData.Application.ActiveUIDocument.Selection;
            List <Rebar> bars = new List <Rebar>();

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Rebar presentation");
                foreach (ElementId id in sel.GetElementIds())
                {
                    Rebar r = doc.GetElement(id) as Rebar;
                    if (r != null)
                    {
                        Debug.WriteLine("Current rebar id: " + id.IntegerValue.ToString());
                        bool check = r.CanApplyPresentationMode(v);
                        if (!check)
                        {
                            Debug.WriteLine("Cant apply presentation mode");
                            continue;
                        }

                        r.SetPresentationMode(v, RebarPresentationMode.Select);
                        int count  = r.NumberOfBarPositions;
                        int middle = count / 2;
                        Debug.WriteLine("Bars count: " + count + ", middle bar: " + middle);
                        for (int i = 0; i < count; i++)
                        {
                            if (i == 0 || i == (count - 1) || i == middle)
                            {
                                r.SetBarHiddenStatus(v, i, false);
                                Debug.WriteLine("Bar " + i + ", set visible");
                            }
                            else
                            {
                                r.SetBarHiddenStatus(v, i, true);
                                Debug.WriteLine("Bar " + i + ", set invisible");
                            }
                        }
                    }
                    RebarInSystem ris = doc.GetElement(id) as RebarInSystem;
                    if (ris != null)
                    {
                        Debug.WriteLine("Current RebarInSystem id: " + id.IntegerValue.ToString());
                        bool check = ris.CanApplyPresentationMode(v);
                        if (!check)
                        {
                            Debug.WriteLine("Cant apply presentation mode");
                            continue;
                        }
                        ris.SetPresentationMode(v, RebarPresentationMode.Select);
                        int count  = ris.NumberOfBarPositions;
                        int middle = count / 2;
                        for (int i = 0; i < count; i++)
                        {
                            if (i == 0 || i == (count - 1) || i == middle)
                            {
                                ris.SetBarHiddenStatus(v, i, false);
                                Debug.WriteLine("Bar " + i + ", set visible");
                            }
                            else
                            {
                                ris.SetBarHiddenStatus(v, i, true);
                                Debug.WriteLine("Bar " + i + ", set invisible");
                            }
                        }
                    }
                }
                t.Commit();
            }
            Debug.WriteLine("All done");
            return(Result.Succeeded);
        }