Пример #1
0
 public bool AllowElement(Element element)
 {
     if (RebarHostData.GetRebarHostData(element) != null)
     {
         return true;
     }
     return false;
 }
Пример #2
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.");
            }
        }
Пример #3
0
            public bool AllowElement(Element e)
            {
                RebarHostData myRbHostData = RebarHostData.GetRebarHostData(e);
                
                if (myRbHostData.GetRebarsInHost().Count > 0)
                {
                    return true;
                }

                return false;
            }
Пример #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
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
            List<Element> hostElements = new List<Element>();
            if (selectedIds.Any())
            {
                foreach (ElementId id in selectedIds)
                {
                    Element e = doc.GetElement(id);
                    if (RebarHostData.IsValidHost(e))
                    {
                        hostElements.Add(e);
                    }
                }
            }
            else
            {
                try
                {
                    Reference pickedRef = uidoc.Selection.PickObject(ObjectType.Element, new RebarHostSelectionFilter(), "Pick a rebar host to selct rebar in bottom, TAB to cycle, ESC to cancel");
                    if (pickedRef == null)
                    {
                        message = "Nothing was selected";
                        return Result.Failed;
                    }
                    else
                    {
                        hostElements.Add(doc.GetElement(pickedRef));
                    }
                }
                catch (Autodesk.Revit.Exceptions.OperationCanceledException)
                {
                    return Result.Cancelled;
                }
            }
            ICollection<ElementId> idsToSelect = new List<ElementId>();
            foreach (Element host in hostElements)
            {
                ICollection<ElementId> rebarsInBottomLayer = SelectBottomLayer.GetElementIdsInLayer(doc, host, false);
                idsToSelect = idsToSelect.Concat(rebarsInBottomLayer).ToList();
            }
            uidoc.Selection.SetElementIds(idsToSelect);

            return Result.Succeeded;
        }
Пример #6
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();
            
        }
Пример #7
0
        Stream(ArrayList data, RebarHostData rebarHostData)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RebarHostData)));

            data.Add(new Snoop.Data.Bool("IsValidHost", rebarHostData.IsValidHost()));
        }
Пример #8
0
        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
            Color color = e.ObjToSnoop as Color;

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

            LayoutRule layoutRule = e.ObjToSnoop as LayoutRule;

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

            FormatOptions formatOptions = e.ObjToSnoop as FormatOptions;

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

            CurtainGrid curtainGrid = e.ObjToSnoop as CurtainGrid;

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

            CurtainCell curtainCell = e.ObjToSnoop as CurtainCell;

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

            RebarHostData rebarHostData = e.ObjToSnoop as RebarHostData;

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

            Leader leader = e.ObjToSnoop as Leader;

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

            AreaVolumeSettings areaSettings = e.ObjToSnoop as AreaVolumeSettings;

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

            ViewSheetSetting viewSheetSetting = e.ObjToSnoop as ViewSheetSetting;

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

            Autodesk.Revit.UI.Events.DialogBoxData dlgBoxData = e.ObjToSnoop as Autodesk.Revit.UI.Events.DialogBoxData;
            if (dlgBoxData != null)
            {
                Stream(snoopCollector.Data(), dlgBoxData);
                return;
            }

            Construction construct = e.ObjToSnoop as Construction;

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

            FamilyElementVisibility famElemVisib = e.ObjToSnoop as FamilyElementVisibility;

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

            FamilyManager famManager = e.ObjToSnoop as FamilyManager;

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

            FamilyParameter famParam = e.ObjToSnoop as FamilyParameter;

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

            FamilyType famType = e.ObjToSnoop as FamilyType;

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

            MEPSpaceConstruction mepSpaceConstuct = e.ObjToSnoop as MEPSpaceConstruction;

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

            BuildingSiteExportOptions bldSiteExpOptions = e.ObjToSnoop as BuildingSiteExportOptions;

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

            DGNExportOptions dgnExpOptions = e.ObjToSnoop as DGNExportOptions;

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

            DWFExportOptions dwfExpOptions = e.ObjToSnoop as DWFExportOptions;

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

            DWGExportOptions dwgExpOptions = e.ObjToSnoop as DWGExportOptions;

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

            DWGImportOptions dwgImpOptions = e.ObjToSnoop as DWGImportOptions;

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

            FBXExportOptions fbxExpOptions = e.ObjToSnoop as FBXExportOptions;

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

            TrussMemberInfo trussInfo = e.ObjToSnoop as TrussMemberInfo;

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

            VertexIndexPair vertIndPair = e.ObjToSnoop as VertexIndexPair;

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

            PointElementReference ptElemRef = e.ObjToSnoop as PointElementReference;

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

            Autodesk.Revit.DB.Architecture.BoundarySegment boundSeg = e.ObjToSnoop as Autodesk.Revit.DB.Architecture.BoundarySegment;
            if (boundSeg != null)
            {
                Stream(snoopCollector.Data(), boundSeg);
                return;
            }

            PointLocationOnCurve ptLocOnCurve = e.ObjToSnoop as PointLocationOnCurve;

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

            Entity entity = e.ObjToSnoop as Entity;

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

            Field field = e.ObjToSnoop as Field;

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

            ExtensibleStorageField storeagefield = e.ObjToSnoop as ExtensibleStorageField;

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

            IList <Autodesk.Revit.DB.BoundarySegment> boundSegs = e.ObjToSnoop as
                                                                  IList <Autodesk.Revit.DB.BoundarySegment>;

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

            if (e.ObjToSnoop is KeyValuePair <String, String> )
            {
                KeyValuePair <String, String> stringspair = (KeyValuePair <String, String>)e.ObjToSnoop;
                Stream(snoopCollector.Data(), stringspair);
                return;
            }

            Schema schema = e.ObjToSnoop as Schema;

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

            ElementId elemId = e.ObjToSnoop as ElementId;

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

            PlanViewRange plvr = e.ObjToSnoop as PlanViewRange;

            if (plvr != null)
            {
                Stream(snoopCollector.Data(), plvr);
                return;
            }
            //TF
            RebarConstraintsManager rbcm = e.ObjToSnoop as RebarConstraintsManager;

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

            RebarConstrainedHandle rbch = e.ObjToSnoop as RebarConstrainedHandle;

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

            RebarConstraint rbc = e.ObjToSnoop as RebarConstraint;

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

            //TFEND

            if (Utils.IsSupportedType(e.ObjToSnoop) && e.ObjToSnoop != null)
            {
                Utils.StreamWithReflection(snoopCollector.Data(), e.ObjToSnoop.GetType(), e.ObjToSnoop);
            }
        }
Пример #9
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;
        }
Пример #10
0
      Stream(ArrayList data, RebarHostData rebarHostData)
      {
         data.Add(new Snoop.Data.ClassSeparator(typeof(RebarHostData)));

         data.Add(new Snoop.Data.Bool("IsValidHost", rebarHostData.IsValidHost()));
      }
Пример #11
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;
            }
        }
Пример #12
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));
        }
Пример #13
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;
            }
        }
Пример #14
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;
        }
Пример #15
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);
        }