วันอาทิตย์ที่ 11 พฤศจิกายน พ.ศ. 2561

การ Update เสา ให้มีค่า Grid ลงใน Comment

เป็นประโยชน์ ในการประยุกต์ หลายอย่าง ที่ต้องการบอก Grid ใน การออกรายงาน Schedule

ตัวอย่างนี้ จะ กำหนดระยะะ ที่ไม่เกิน 1/10 ฟุต จะอยู่ใน Grid

static public void checkColumnGrid(ExternalCommandData command)
        {
            UIApplication uiapp = command.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

        IList<Reference> selElement=    
                uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element,"Select all grid");
            //     Reference myItem2 = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element
            //                                            , "Select Column");
            //     ElementId id2 = myItem2.ElementId; // Number of Object

            List<ElementId> cols = new List<ElementId>();
            foreach (Reference myItem in selElement)
            {
                ElementId id = myItem.ElementId;
                Element elem = doc.GetElement(id);
                string fmt = elem.Category.Name ;

                if (!fmt.Contains("Column")) continue;
                cols.Add(id);
            }
            foreach (ElementId id2 in cols)
            {
                XYZ columnPoint = getColumnPoint(id2, doc); // column location
                foreach (Reference myItem in selElement)
                {
                    ElementId id = myItem.ElementId;
                    Element elem = doc.GetElement(id);
                    string fmt = elem.GetParameters("Family").First().AsValueString();

                    if (fmt != "Grid") continue;

                    string gridName = elem.Name;

                    BoundingBoxXYZ bb = elem.get_BoundingBox(doc.ActiveView);
                    XYZ p1 = bb.Max;
                    XYZ p2 = bb.Min;

                    string columnOnGrid = "";
                    bool isHor = false; // is Vertical
                    if (p1.X - p2.X > p1.Y - p2.Y)
                    {
                        // Horizontal
                        isHor = true;
                        // base Y average
                        double averY = (p1.Y - p2.Y) / 2 + p2.Y;

                        // assum 0.1 foot is Equal object
                        if (Math.Abs(columnPoint.Y - averY) < 0.1)
                        {
                            columnOnGrid = gridName;
                            //  TaskDialog.Show("Column on Hor Average Y", averY.ToString());
                        }
                        else
                        {
                            //    TaskDialog.Show("Hor Average Y", averY.ToString());
                        }
                    }
                    else
                    {
                        // Horizontal
                        isHor = false;
                        // base Y average
                        double averX = (p1.X - p2.X) / 2 + p2.X;
                        if (Math.Abs(columnPoint.X - averX) < 0.1)
                        {
                            columnOnGrid = gridName;
                            //  TaskDialog.Show("Column on Ver Average X", averX.ToString());
                        }
                        else
                        {
                            //   TaskDialog.Show("Ver Average X", averX.ToString());
                        }
                    }
                    if (columnOnGrid != "")
                    {
                        Element elem2 = doc.GetElement(id2);
                        using (Transaction tr = new Transaction(doc))
                        {
                            tr.Start("update comment");
                            try
                            {// do some
                                Parameter mypm = elem2.GetParameters("Comments").First();
                                string pComment = mypm.AsString() + columnOnGrid + ",";
                                mypm.Set(pComment);

                                tr.Commit();
                            }
                            catch
                            {
                                tr.RollBack();
                            }

                        }

             //           TaskDialog.Show("ONGRid", columnOnGrid);
                    }
                }
            }

        }



1 ความคิดเห็น: