Пример #1
0
 public bool AllowElement(Element element)
 {
     if (RebarHostData.GetRebarHostData(element) != null)
     {
         return true;
     }
     return false;
 }
Пример #2
0
            public bool AllowElement(Element e)
            {
                RebarHostData myRbHostData = RebarHostData.GetRebarHostData(e);
                
                if (myRbHostData.GetRebarsInHost().Count > 0)
                {
                    return true;
                }

                return false;
            }
Пример #3
0
        /// <summary>
        /// Do some check for the selection elements, includes geometry check.
        /// If the data doesn't meet our need, Exception will be thrown.
        /// </summary>
        private void Assert()
        {
            // Reserve all element ids for following iteration
            List <ElementId> selectedIds = new List <ElementId>();

            foreach (Autodesk.Revit.DB.ElementId elemId in m_rvtUIDoc.Selection.GetElementIds())
            {
                Autodesk.Revit.DB.Element elem = m_rvtUIDoc.Document.GetElement(elemId);
                selectedIds.Add(elem.Id);
            }
            if (selectedIds.Count == 0)
            {
                throw new Exception("Please select a concrete beam or column to create rebar.");
            }

            //
            // Construct filter to find expected rebar host
            // Structural type filters firstly
            LogicalOrFilter stFilter = new LogicalOrFilter(
                new ElementStructuralTypeFilter(StructuralType.Beam),
                new ElementStructuralTypeFilter(StructuralType.Column));
            // + StructuralMaterial
            LogicalAndFilter hostFilter = new LogicalAndFilter(stFilter,
                                                               new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete));
            // Expected rebar host: it should be family instance
            FilteredElementCollector collector = new FilteredElementCollector(m_rvtUIDoc.Document, selectedIds);
            FamilyInstance           rebarHost = collector.OfClass(typeof(FamilyInstance)).WherePasses(hostFilter).FirstElement() as FamilyInstance;

            // Make sure the selected beam or column is rectangular.
            try
            {
                m_geometryData = new GeometrySupport(rebarHost);
            }
            catch
            {
                throw new Exception("Please select a beam or column in rectangular shape.");
            }

            m_rebarHost = rebarHost;

            // Judge the rebar host is a valid host.
            RebarHostData rebarHostData = RebarHostData.GetRebarHostData(rebarHost);

            if (rebarHostData == null || !rebarHostData.IsValidHost())
            {
                throw new Exception("The selected element is not a valid rebar host.");
            }

            // Make sure the selected beam or column doesn't contain any rebar.
            if (rebarHostData.GetRebarsInHost().Count > 0)
            {
                throw new Exception("Please select a beam or a column which doesn't contain any rebar.");
            }
        }
Пример #4
0
        /// <summary>
        /// Constructor to initialize the fields.
        /// </summary>
        /// <param name="corbel">Corbel family instance</param>
        /// <param name="profile">Trapezoid profile</param>
        /// <param name="path">Extrusion Line</param>
        /// <param name="hostDepth">Corbel Host Depth</param>
        /// <param name="hostTopCorverDistance">Corbel Host cover distance</param>
        public CorbelFrame(FamilyInstance corbel, Trapezoid profile,
                           Line path, double hostDepth, double hostTopCorverDistance)
        {
            m_profile           = profile;
            m_extrusionLine     = path;
            m_corbel            = corbel;
            m_hostDepth         = hostDepth;
            m_hostCoverDistance = hostTopCorverDistance;

            // Get the cover distance of corbel from CommonCoverType.
            RebarHostData rebarHost = RebarHostData.GetRebarHostData(m_corbel);

            m_corbelCoverDistance = rebarHost.GetCommonCoverType().CoverDistance;
        }
Пример #5
0
        internal static ICollection<ElementId> GetElementIdsInLayer(Document doc, Element host, bool bottomLayer)
        {
            RebarHostData hostData = RebarHostData.GetRebarHostData(host);
            ICollection<ElementId> rebarsInHost = hostData.GetRebarsInHost().Select(r => r.Id).ToList();
            BoundingBoxXYZ box = host.get_BoundingBox(null);
            double midZ = 0.5 * (box.Max.Z + box.Min.Z);
            Outline outline;
            if (bottomLayer)
            {
                outline = new Outline(box.Min, new XYZ(box.Max.X, box.Max.Y, midZ));
            }
            else
            {
                outline = new Outline(new XYZ(box.Min.X, box.Min.Y, midZ), box.Max);
            }

            BoundingBoxIsInsideFilter filter = new BoundingBoxIsInsideFilter(outline);
            FilteredElementCollector collector = new FilteredElementCollector(doc, rebarsInHost);
            return collector.WherePasses(filter).ToElementIds();
            
        }
Пример #6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            bool SourceIsWallFoundation = false;
            Reference ref1 = null;
            IList<Reference> ref2List = new List<Reference>();

            try
            {
                ref1 = uidoc.Selection.PickObject(ObjectType.Element, new RebarHostSelectionFilter(), "Pick a rebar host to copy from");
                ref2List = uidoc.Selection.PickObjects(ObjectType.Element, new RebarHostSelectionFilter(), "Pick a rebar host to copy to");
            }
            catch(Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                TaskDialog.Show("Rebar Copy command cancelled", "Click finish in top left corner to complete the command");
                return Result.Cancelled;
            }

            using (Transaction t1 = new Transaction(doc, "Copy rebar"))
            {
                t1.Start();
                foreach (Reference ref2 in ref2List)
                {
                    Element sourceHost = doc.GetElement(ref1.ElementId);
                    Element targetHost = doc.GetElement(ref2.ElementId);
                    ICollection<ElementId> elementIdToBeDeleted = new List<ElementId>();
                    WallFoundation sourceWallFoundation = null;
                    WallFoundation targetWallFoundation = null;
                    //Workaround for wall foundations: They have no location lines, but are completely dependent on their walls. So by copiing the host wall, both the wall foundation and the rebars follows along
                    if (sourceHost is WallFoundation && targetHost is WallFoundation)
                    {
                        SourceIsWallFoundation = true;
                        sourceWallFoundation = (WallFoundation)sourceHost;
                        sourceHost = doc.GetElement(sourceWallFoundation.WallId);
                        targetWallFoundation = (WallFoundation)targetHost;
                        targetHost = doc.GetElement(targetWallFoundation.WallId);
                    }
                    //STEP 1: Copy element to random location
                    //5000 is a random chosen number, surprisingly it matters if its copied in Y or Z direction:
                    ICollection<ElementId> copiedElements = ElementTransformUtils.CopyElement(doc, sourceHost.Id, new XYZ(0, 5000, 0));
                    Element copiedElement = doc.GetElement(copiedElements.FirstOrDefault());
                    elementIdToBeDeleted.Add(copiedElement.Id);

                    //STEP 2: Relocate copy to match the target 
                    if (copiedElement.Location is LocationCurve && targetHost.Location is LocationCurve)
                    {
                        LocationCurve locationTo = targetHost.Location as LocationCurve;
                        LocationCurve locationCopied = copiedElement.Location as LocationCurve;
                        locationCopied.Curve = locationTo.Curve;
                    }
                    else if (copiedElement.Location is LocationPoint && targetHost.Location is LocationPoint)
                    {
                        LocationPoint locationTo = targetHost.Location as LocationPoint;
                        LocationPoint locationCopied = copiedElement.Location as LocationPoint;
                        locationCopied.Point = locationTo.Point;
                        if (locationCopied.Rotation != locationTo.Rotation)
                        {
                            Transform trans1 = Transform.CreateTranslation(new XYZ(0, 0, 1));
                            XYZ origin1 = locationTo.Point;
                            XYZ endAxis = trans1.OfPoint(origin1);
                            Line axis1 = Line.CreateBound(origin1, endAxis);
                            locationCopied.Rotate(axis1, locationTo.Rotation);
                        }
                    }
                    else
                    {
                        TaskDialog.Show("Warning", "Pick two Rebar Hosts with the same location type. Only elements with locatoion lines and location points are supported. Elements such as beams, walls and slanted columns do typically have location lines. Floors and slabs are not supported.");
                        t1.RollBack();
                        return Result.Cancelled;
                    }


                    //STEP 3: Change the type of the copied element to match the target element
                    //TODO: Change types for wall foundations and change heights/offsets for walls
                    try
                    {
                        if (targetHost.GetTypeId() != copiedElement.GetTypeId())
                        {
                            copiedElement.ChangeTypeId(targetHost.GetTypeId());
                        }

                        if (targetHost is Wall && sourceHost is Wall)
                        {
                            copiedElement.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(targetHost.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble());
                            copiedElement.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(targetHost.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).AsDouble());
                        }

                        if (IsNotSlantedColumn(targetHost) && IsNotSlantedColumn(sourceHost))
                        {
                            copiedElement.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(targetHost.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).AsElementId());
                            copiedElement.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(targetHost.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).AsDouble());
                            copiedElement.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(targetHost.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).AsElementId());
                            copiedElement.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(targetHost.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).AsDouble());
                        } 
                    }
                    catch { }

                    doc.Regenerate();

                    //Step 3: Change rebar host from copied element to target element
                    IList<Rebar> copiedRebars = new List<Rebar>();

                    if (SourceIsWallFoundation)
                    {
                        //Need to find the foundation that was created by copying the wall
                        WallFoundation wallFoundation = new FilteredElementCollector(doc)
                            .OfClass(typeof(WallFoundation))
                            .WhereElementIsNotElementType().Cast<WallFoundation>()
                            .FirstOrDefault(q => q.WallId == copiedElement.Id);
                        elementIdToBeDeleted.Add(wallFoundation.Id);
                        copiedRebars = RebarHostData.GetRebarHostData(wallFoundation).GetRebarsInHost();
                        if (targetWallFoundation != null)
                        {
                            foreach (Rebar r in copiedRebars)
                            {
                                r.SetHostId(doc, targetWallFoundation.Id);
                            }
                        }

                    }
                    else
                    {
                        copiedRebars = RebarHostData.GetRebarHostData(copiedElement).GetRebarsInHost();
                        foreach (Rebar r in copiedRebars)
                        {
                            r.SetHostId(doc, targetHost.Id);
                        }
                    }

                    //Step 4: Delete the copied element
                    doc.Delete(elementIdToBeDeleted);

                }

                t1.Commit();
            }
            return Result.Succeeded;
        }
Пример #7
0
        public void makeGroupRebarByHost()
        {
            try {
                UIDocument uiDoc = this.ActiveUIDocument;
                Document   doc   = uiDoc.Document;

                string nameGroup     = "";
                string namePartition = "";
                int    rebarCount    = 1;
                // Show form

                using (SettingDialog myInputFormSetting = new SettingDialog())
                {
                    myInputFormSetting.ShowDialog();

                    //if the user hits cancel just drop out of macro
                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    {
                        //else do all this :)
                        myInputFormSetting.Close();
                    }

                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        nameGroup     = myInputFormSetting.GroupName_Tb1.Text;
                        namePartition = myInputFormSetting.Partition1_Tb.Text;

                        rebarCount = Convert.ToInt32(myInputFormSetting.RebarCount_Tb.Text);

                        myInputFormSetting.Close();
                    }
                }



                List <Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Element, new FilterByNumberRebarHostIn()).ToList();

                foreach (Reference myRef in myListRef)
                {
                    Element myHost = doc.GetElement(myRef);

                    RebarHostData myRbHostData = RebarHostData.GetRebarHostData(myHost);

                    List <Rebar> myListRebar = myRbHostData.GetRebarsInHost() as List <Rebar>;


                    using (Transaction trans_1 = new Transaction(doc, "Change parameter Rebar"))
                    {
                        trans_1.Start();



                        //Set parameter
                        foreach (Rebar myRebar in myListRebar)
                        {
                            //Partition
                            Parameter partitionPara = myRebar.LookupParameter("Partition");

                            if (partitionPara == null)
                            {
                                TaskDialog.Show("Error!!", "Has no parpation");
                            }
                            else
                            {
                                partitionPara.Set(namePartition);
                            }

                            //Partition
                            Parameter rebarCountPara = myRebar.LookupParameter("COUNT_REBAR");

                            if (rebarCountPara == null)
                            {
                                TaskDialog.Show("Error!!", "Has no parpation");
                            }
                            else
                            {
                                rebarCountPara.Set(rebarCount);
                            }
                        }
                        trans_1.Commit();
                    }


                    //Set parameter

                    List <ElementId> myListElementId = new List <ElementId>();
                    foreach (Rebar myRebar in myListRebar)
                    {
                        myListElementId.Add(myRebar.Id);
                    }


                    using (Transaction trans = new Transaction(doc, "Make group Rebar"))
                    {
                        trans.Start();

                        if (myListElementId.Count > 0)
                        {
                            Group myGroupRebar = doc.Create.NewGroup(myListElementId);
                            if (nameGroup != "")
                            {
                                myGroupRebar.GroupType.Name = nameGroup;
                            }
                        }
                        else
                        {
                            TaskDialog.Show("Warning!", "No rebar was hosted by this element, so no any group was created!");
                        }
                        trans.Commit();
                    }
                }
            }
            catch (Exception)
            {
                TaskDialog.Show("Error!!!", "Co loi xay ra, co the tat ca rebar da co trong 1 group");
                throw;
            }
        }
Пример #8
0
        /// <summary>
        /// This method parses geometry information of given Corbel to construct the CorbelFrame.
        /// </summary>
        /// <param name="corbel">Given corbel family instance to parse</param>
        /// <returns>CorbelFrame object</returns>
        public static CorbelFrame ParseCorbelGeometry(FamilyInstance corbel)
        {
            // Get Corbel Host information.
            Element   corbelHost     = corbel.Host;
            Reference corbelHostFace = corbel.HostFace;

            PlanarFace hostPlane  = corbelHost.GetGeometryObjectFromReference(corbelHostFace) as PlanarFace;
            XYZ        hostNormal = GetNormalOutside(hostPlane);

            // Extract the faces in Corbel parallel with Corbel host face.
            Solid      corbelSolid      = GetElementSolid(corbel);
            PlanarFace corbelTopFace    = null;
            PlanarFace corbelBottomFace = null;

            foreach (Face face in corbelSolid.Faces)
            {
                PlanarFace planarFace = face as PlanarFace;
                XYZ        normal     = GetNormalOutside(planarFace);
                if (normal.IsAlmostEqualTo(hostNormal))
                {
                    corbelTopFace = planarFace;
                }
                else if (normal.IsAlmostEqualTo(-hostNormal))
                {
                    corbelBottomFace = planarFace;
                }
            }

            // Extract the faces in Corbel Host parallel with Corbel host face.
            Solid      hostSolid      = GetElementSolid(corbelHost);
            PlanarFace hostTopFace    = null;
            PlanarFace hostBottomFace = hostPlane;

            foreach (Face face in hostSolid.Faces)
            {
                PlanarFace planarFace = face as PlanarFace;
                XYZ        normal     = GetNormalOutside(planarFace);
                if (normal.IsAlmostEqualTo(-hostNormal))
                {
                    hostTopFace = planarFace;
                }
            }

            // Parse the side faces to find out the Trapezoid face.
            Edge       topEdge        = null;
            Edge       leftEdge       = null;
            Edge       bottomEdge     = null;
            Edge       rightEdge      = null;
            PlanarFace trapezoidFace  = null;
            int        foundEdgeIndex = -1;
            bool       foundTrapezoid = false;
            EdgeArray  bottomEdges    = corbelBottomFace.EdgeLoops.get_Item(0);

            foreach (Edge edge in bottomEdges)
            {
                bottomEdge = edge;
                foundEdgeIndex++;
                foundTrapezoid = IsTrapezoid(hostNormal, corbelBottomFace, bottomEdge,
                                             out trapezoidFace, out topEdge, out leftEdge, out rightEdge);
                if (foundTrapezoid)
                {
                    break;
                }
            }

            // Check to see if the Trapezoid faces was found.
            if (!foundTrapezoid)
            {
                // Throw if no any trapezoid face in corbel.
                throw new Exception("Didn't find the trapezoid face in corbel [Id:" + corbel.Id + "].");
            }

            Edge depthEdge = bottomEdges.get_Item((foundEdgeIndex + 1) % bottomEdges.Size);

            double hostDepth = GetDistance(hostTopFace, hostBottomFace);

            // Compute the host face cover distance.
            RebarHostData corbelHostData = RebarHostData.GetRebarHostData(corbelHost);
            // Get CoverType of the given host face
            RebarCoverType coverType = corbelHostData.GetCoverType(hostTopFace.Reference);

            // if the host face don't have a CoverType, then try to get the common CoverType.
            if (coverType == null)
            {
                coverType = corbelHostData.GetCommonCoverType();
            }
            // Get the Cover Distance
            double coverDistance = coverType.CoverDistance;

            // Construct the CorbelFrame from the given parsed trapezoid information.
            return(ConstructCorbelFrame(
                       corbel, depthEdge,
                       leftEdge, bottomEdge, rightEdge, topEdge,
                       corbel.Document, trapezoidFace,
                       hostDepth, coverDistance));
        }
Пример #9
0
        public void makeGroupRebarByHost(UIDocument uiDoc)
        {
            try
            {
                Document doc = uiDoc.Document;

                string nameGroup = "";


                string paraName_1 = "";
                string paraName_2 = "";


                string paraValue_1 = "";
                int    paraValue_2 = 1;


                string warning1 = "";
                string warning2 = "";

                // Show form

                using (SettingDialog myInputFormSetting = new SettingDialog())
                {
                    myInputFormSetting.ShowDialog();

                    //if the user hits cancel just drop out of macro
                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    {
                        //else do all this :)
                        myInputFormSetting.Close();
                    }

                    if (myInputFormSetting.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        nameGroup = myInputFormSetting.GroupName_Tb1.Text;


                        paraName_1 = myInputFormSetting.Para_1Tb.Text;
                        paraName_2 = myInputFormSetting.Para_2Tb.Text;

                        paraValue_1 = myInputFormSetting.Value1_Tb.Text;

                        paraValue_2 = Convert.ToInt32(myInputFormSetting.Value2_Tb.Text);

                        myInputFormSetting.Close();
                    }
                }



                //List<Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Element, new FilterByNumberRebarHostIn()).ToList();

                Reference myRef = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByNumberRebarHostIn());


                Element myHost = doc.GetElement(myRef);

                RebarHostData myRbHostData = RebarHostData.GetRebarHostData(myHost);

                List <Rebar> myListRebar = myRbHostData.GetRebarsInHost() as List <Rebar>;


                using (Transaction trans_1 = new Transaction(doc, "Change parameter Rebar"))
                {
                    trans_1.Start();



                    //Set parameter
                    foreach (Rebar myRebar in myListRebar)
                    {
                        //Partition
                        Parameter Para1 = myRebar.LookupParameter(paraName_1);

                        if (Para1 == null)
                        {
                            warning1 = string.Format("Rebar {0} has no paramater name: {1}", myRebar.Id.ToString(), paraName_1);
                        }
                        else
                        {
                            Para1.Set(paraValue_1);
                        }


                        //Partition
                        Parameter Para2 = myRebar.LookupParameter(paraName_2);

                        if (Para2 == null)
                        {
                            warning2 = string.Format("Rebar {0} has no paramater name: {1}", myRebar.Id.ToString(), paraName_2);
                        }
                        else
                        {
                            Para2.Set(paraValue_2);
                        }
                    }
                    trans_1.Commit();
                }

                if (warning1 != warning2)
                {
                    TaskDialog.Show("Waring", warning1 + "\n" + warning2);
                }


                //Set parameter

                List <ElementId> myListElementId = new List <ElementId>();
                foreach (Rebar myRebar in myListRebar)
                {
                    myListElementId.Add(myRebar.Id);
                }


                using (Transaction trans = new Transaction(doc, "Make group Rebar"))
                {
                    trans.Start();

                    if (myListElementId.Count > 0)
                    {
                        Group myGroupRebar = doc.Create.NewGroup(myListElementId);
                        if (nameGroup != "")
                        {
                            myGroupRebar.GroupType.Name = nameGroup;
                        }
                    }
                    else
                    {
                        TaskDialog.Show("Warning!", "No rebar was hosted by this element, so no any group was created!");
                    }
                    trans.Commit();
                }
            }
            catch (Exception)
            {
                TaskDialog.Show("Error!!!", "Co loi xay ra, co the tat ca rebar da co trong 1 group");
                throw;
            }
        }
Пример #10
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {

            Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            View view1 = doc.ActiveView;
            const double mmTofeet = 1.0 / 304.8;

            //Check if the view is a 3D view, and if it is locked:
            if (view1.ViewType == ViewType.ThreeD)
            {
                View3D view3D1 = (View3D)view1;
                if (!view3D1.IsLocked)
                {
                    TaskDialog.Show("Error", "3D-view must be locked to place tags");
                    return Result.Cancelled;
                }
            }

            //Check if the view has a usable sketchplane active, create and set one if not.
            if (view1.SketchPlane != null)
            {
                XYZ existingSPdir = view1.SketchPlane.GetPlane().Normal;
                if (Math.Abs(view1.ViewDirection.AngleTo(existingSPdir)) > 000.1)
                {
                    SetWorkPlane(view1, doc);
                }
            }
            else SetWorkPlane(view1, doc);

            //Get the rebar host: Use selected element if exactly one is selected, else ask user to pick a element that is host for rebar.
            Element host1 = null;
            XYZ topPt1 = new XYZ();
            try
            {
                ICollection<ElementId> selectedElementIds = uidoc.Selection.GetElementIds();
                if (selectedElementIds.Count == 1)
                {
                    host1 = doc.GetElement(selectedElementIds.First());
                }
                else host1 = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, new RebarHostSelectionFilter(), "Pick a rebar host").ElementId);

                //ui: Pick a point where the top tag should be placed (host tag)
                topPt1 = uidoc.Selection.PickPoint("Pick a point to place tags");
            }

            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            /*
            //Select all rebars and get their hostId, pick the ones with hostId==host1.Id
            FilteredElementCollector fec1 = new FilteredElementCollector(doc, view1.Id).OfCategory(BuiltInCategory.OST_Rebar);
            List<Autodesk.Revit.DB.Structure.Rebar> rebarList = fec1.Cast<Autodesk.Revit.DB.Structure.Rebar>().Where(e => e.GetHostId() == host1.Id).ToList();
            */
            
            //Get rebars in host:
            IList<Autodesk.Revit.DB.Structure.Rebar> rebarList = RebarHostData.GetRebarHostData(host1).GetRebarsInHost();

            //Get View Scale and updirection from active view
            double scale1 = System.Convert.ToDouble(view1.get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger());
            XYZ viewDirUp1 = view1.UpDirection;
            double tagSize1 = 3.5 * mmTofeet;
            double spacing1 = tagSize1 + (2.0 * mmTofeet);
            XYZ deltaVec = viewDirUp1.Normalize().Multiply(spacing1 * scale1);



            //Calculate the spacing of the tags
            int numberOfTags = rebarList.Count();
            XYZ tempPt = topPt1;
            List<XYZ> ptList = new List<XYZ>();
            for (int i = 0; i < numberOfTags; i++)
            {
                tempPt = tempPt.Subtract(deltaVec);
                ptList.Add(tempPt);
            }


            using (Transaction t2 = new Transaction(doc, "Create tag"))
            {
                t2.Start();
#if RVT2017
                doc.Create.NewTag(view1, host1, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, topPt1);
#else
                IndependentTag.Create(doc, view1.Id, new Reference(host1), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, topPt1);
#endif
                for (int i = 0; i < numberOfTags; i++)
                {
#if RVT2017 
                    doc.Create.NewTag(view1, rebarList[i], false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, ptList[i]);
#else
                    IndependentTag.Create(doc, view1.Id, new Reference(rebarList[i]), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, ptList[i]);
#endif
                }

                t2.Commit();
            }

            //The external command requres a return.
            return Result.Succeeded;
        }
Пример #11
0
        //Get all rebar in section
        //Trả về 1 danh sách gồm 2 danh sách, danh sách đầu tiên chứa Id của cac rebar section trên dầm (thép chủ trên),
        // danh sách thứ 2 trả về Id của các rebar phía dưới dầm(thép chủ dưới);

        public List <List <Rebar> > myListRebarIdSorted()
        {
            UIDocument uiDoc = this.ActiveUIDocument;

            Document doc = uiDoc.Document;

            View myView = doc.ActiveView;


            //Pick beam to get min max bound

            Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, "Pick host beam...");
            Element   myBeam    = doc.GetElement(myRefBeam);

            //Boundary of beam
            BoundingBoxXYZ myBeam_BB = myBeam.get_BoundingBox(myView);

            XYZ minPointBeam    = myBeam_BB.Min;
            XYZ maxPointBeam    = myBeam_BB.Max;
            XYZ centerPointBeam = (minPointBeam + maxPointBeam) / 2;

            //Retrive all rebar of beam

            RebarHostData myRbHostData = RebarHostData.GetRebarHostData(myBeam);

            List <Rebar> myListRebar = myRbHostData.GetRebarsInHost() as List <Rebar>;

            //Inter every rebar in ListRebar make section rebar in view

            List <Rebar> myListRebarInSection = new List <Rebar>();

            foreach (Rebar myRebarOfBeam in myListRebar)
            {
                if (myRebarOfBeam.IsRebarInSection(myView) && myRebarOfBeam.NumberOfBarPositions > 1)
                {
                    myListRebarInSection.Add(myRebarOfBeam);
                }
            }


            List <Rebar> listBottomRebar = new List <Rebar>();
            List <Rebar> listTopRebar    = new List <Rebar>();

            if (myListRebarInSection.Count < 1)
            {
                TaskDialog.Show("abc", "Has no rebarinsection in view belong to Host picked");
                return(null);
            }

            else
            {
                //Trong mỗi rebar in section, so sánh vị trí tương đối của rebar với trục giữa dầm(Z)
                foreach (Rebar rebarSet in myListRebarInSection)
                {
                    // Lấy bounding box của mỗi rebar
                    //Get bouding box of rebarSet
                    BoundingBoxXYZ myRebar_BB = rebarSet.get_BoundingBox(myView);

                    XYZ minPointRebar    = myRebar_BB.Min;
                    XYZ maxPointRebar    = myRebar_BB.Max;
                    XYZ centerPointRebar = (minPointRebar + maxPointRebar) / 2;

                    if (centerPointRebar.Z <= centerPointBeam.Z)
                    {
                        //myPickPoint = new XYZ(minPointBeam.X, minPointBeam.Y, minPointBeam.Z + (-1*deltaZ*factorDelta));
                        listBottomRebar.Add(rebarSet);
                    }
                    else
                    {
                        //myPickPoint = new XYZ(maxPointBeam.X, maxPointBeam.Y, maxPointBeam.Z + (deltaZ*factorDelta));
                        listTopRebar.Add(rebarSet);
                    }
                }
            }
            List <List <Rebar> > rebarListList = new List <List <Rebar> >()
            {
                listBottomRebar, listTopRebar
            };

            TaskDialog.Show("abc", "has: " + rebarListList[0].Count() + "; " + rebarListList[1].Count);

            return(rebarListList);
        }