วันอังคารที่ 26 กันยายน พ.ศ. 2560

อ่าน Paint Material จาก Wall

อ่านค่า Paint ที่ระบายบนกำแพง


  public static string getPaintWallFaces(ElementId wallId,Document doc)
        {
            Element wall = doc.GetElement(wallId);
            GeometryElement geometryElement = wall.get_Geometry(new Options());
            string str= "";
            foreach (GeometryObject geometryObject in geometryElement)
            {
                if (geometryObject is Solid)
                {
                    Solid solid = geometryObject as Solid;
                    foreach (Face face in solid.Faces)
                    {
                        if (doc.IsPainted(wallId, face))
                        {
                            ElementId mid = doc.GetPaintedMaterial(wallId, face); 
                           Material mel = doc.GetElement(mid) as Material;
                            str+=mel.Name+"\n";
                        }
                    }
                }
            }
            return str;
        }

Debug โปรแกรม C# เมื่อ Run ด้วย DDD

การเรียกโปรแกรม ทำงาน ด้วย DDD ทำได้เป็น Pre-Compiled Mode ทำได้ ทันที โดยไม่ต้อง Load หรือเข้าโปรแกรม Revit ใหม่ ก็สามารถใช้ TaskDialog เพื่อการแสดงค่า ที่ไม่ทราบได้ แต่บางครั้ง จำเป็นต้อง ให้ ทำการ แสดงค่า Watch ระหว่างทำงาน สามารถใช้ Visual Studio ที่กำลังเขียน Code อยู่ Debug ได้
วิธีการ

เลือกที่ Debug และ เลือก Attach To Process -

เลือก Revit.Exe
และ ไปที่ Source code ทดลอง Click ที่หน้าบรรทัด จะเป็น จุดสีแดง หมายถึง Break line 



กลับไป Run คำสั่ง ใน หน้า Revit ->Addins->DDD และเรียกคำสั่งที่ต้องการ Debug จะเห็นว่าโปรแกรมจะหยุดที่บรรทัดนี้ เอา Mouse ไปวางที่ตัวแปร ก็จะแสดงค่า ตัวแปรออกมา ถ้าต้องการไ ปต่อ ก็กดที่ Continue (F5) ถ้าต้องการไปบรรทัดต่อไป ก็กด (Step Over F11)


หาวัตถุที่ ตัดกันโดยใช้ BoundingBox ใน Revit

การหาวัตถุที่ตัดกันใน Revit แบบเร็วๆ ใช้ Bounding Box หรือ ขนาดกล่องที่ใส่วัตถุ นั้นเช่นกำแพง เสา และเช็คว่าตัดกับ วัตถุอะไร แบบประมาณการ เมื่อได้แล้วค่อยไปเช็กอีกที่ว่าตัดกันจริงหรือไม่

// check intersection by box
        public static void chkInterBound(  ExternalCommandData commandData)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            var app = uiApp.Application;
            Document doc = uiDoc.Document;

            // Select something to use as base bounding box.

            Reference r = uiDoc.Selection.PickObject( Autodesk.Revit.UI.Selection.ObjectType.Element);

            // Find the bounding box from the selected 
            // object and convert to outline.
            Element Er = doc.GetElement(r.ElementId);
            BoundingBoxXYZ bb = Er.get_BoundingBox( doc.ActiveView);

            Outline outline = new Outline(bb.Min, bb.Max);

            // Create a BoundingBoxIntersectsFilter to 
            // find everything intersecting the bounding 
            // box of the selected element.

            BoundingBoxIntersectsFilter bbfilter
              = new BoundingBoxIntersectsFilter(outline);

            // Use a view to construct the filter so we 
            // get only visible elements. For example, 
            // the analytical model will be found otherwise.

            FilteredElementCollector collector
              = new FilteredElementCollector(
                doc, doc.ActiveView.Id);

            // Lets also exclude the view itself (which 
            // often will have an intersecting bounding box), 
            // and also the element selected.

            ICollection<ElementId> idsExclude
              = new List<ElementId>();

            idsExclude.Add(r.ElementId);

            // No need for this, BoundingBoxIntersectsFilter 
            // excludes all objects derived from View, as 
            // pointed out by Jim Jia below:
            //
            //idsExclude.Add( doc.ActiveView.Id );

            // Get the set of elements that pass the 
            // criteria. Note both filters are quick, 
            // so order is not so important.

            collector.Excluding(idsExclude)
              .WherePasses(bbfilter);

            // Generate a report to display in the dialog.

            int nCount = 0;
            string report = string.Empty;
            foreach (Element e in collector)
            {
                string name = e.Name;

                report += "\nName = " + name
                  + " Element Id: " + e.Id.ToString();

                nCount++;
            }

            TaskDialog.Show(
              "Bounding Box + View + Exclusion Filter",
              "Found " + nCount.ToString()
              + " elements whose bounding box intersects\n"+
              report);

           
        }

วันจันทร์ที่ 25 กันยายน พ.ศ. 2560

เขียน Model Line ใน Revit

Model Line จำเป็นต้องใช้ในบางงาน ที่ต้องการบอก เป็นเส้น เช้น Boundary หรือ Wire ที่ไม่มี Model

Source

// about line in revit
        public static void drawMline(ExternalCommandData commandData)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            XYZ p1 = new XYZ();
            XYZ p2= p1.Add(new XYZ(5,5,0));
            using (Transaction tr = new Transaction(doc, "MLINE"))
            {
                tr.Start();
                CreateModelLine(doc, p1, p2);
                tr.Commit();
            }
        }

      public static void CreateModelLine( Autodesk.Revit.DB.Document doc,XYZ p, XYZ q)
        {
            if (p.Equals(q))
            {
                throw new ArgumentException(
                  "Expected two different points.");
            }
            Line line = Line.CreateBound(p, q);     //_app.NewLine(p, q, true);
            if (null == line)
            {
                throw new Exception(
                  "Geometry line creation failed.");
            }

            doc.Create.NewModelCurve(line,NewSketchPlanePassLine(doc,line));
        }
      public static SketchPlane NewSketchPlanePassLine(Autodesk.Revit.DB.Document doc, Line line)
      {
          XYZ p = line.GetEndPoint(0);
          XYZ q = line.GetEndPoint(1);
          XYZ norm;
          if (p.X == q.X)
          {
              norm = XYZ.BasisX;
          }
          else if (p.Y == q.Y)
          {
              norm = XYZ.BasisY;
          }
          else
          {
              norm = XYZ.BasisZ;
          }
          Plane plane = doc.Application.Create.NewPlane(norm, p);

          return SketchPlane.Create(doc, plane);

      }

วันพฤหัสบดีที่ 17 สิงหาคม พ.ศ. 2560

คำสั่งแปลง File pdf เป็น PNG

ให้ download ghostscript  (32bit ก็ได้)และติดตั้ง
คำสั่งที่ใช้ได้ สำหรับ การเปลี่ยน PDF เป็น PNG  ง่ายๆ

..\bin\gswin32c.exe -dBATCH -dNOPAUSE -sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -r150 -sOutputFile=out%%03d.png annots.pdf

วันเสาร์ที่ 5 สิงหาคม พ.ศ. 2560

ทดสอบสร้าง CAD ด้วย GDI+

Microsoft ออก Dotnet GDI + มานานแล้วพี่งจะลอง พบว่า สร้าง CAD ได้ง่ายมาก โดยใช้ Linq ช่วยเป็น Database พบว่า ทำให้สร้าง CAD เฉพาะงาน ได้ แต่กิน Ram พอสมควร (คิดว่าไม่มากตอนนี้ ถ้าใช้ Win10 ก็ควรจะมี 8 Gb)

วันศุกร์ที่ 4 สิงหาคม พ.ศ. 2560

ขั้นตอน ของ MEP

จะเขียนแบบ ท่อ
1. ต้อง ใช้ Template Pumping
2. ใช้ Link Revit File ที่เป็น Architech
3. กรณีต้องการ Level ให้มาด้วย ต้อง Collaborate->copy/monitor
   select link -> copy ที่เส้นอีกที
4. ไปรูปแปลน View->FloorPlan เช่น footing ตั้งค่า Offset และ เขียนเส้นท่อ ถ้า
  ต้องการ ขึ้น บน ก็ให้ ไปรูปด้าน


ของแบบไฟฟ้า
1. ต้องใช้ Template EE
2. Link File
3. ไป View->FloorPlan Level 1
4. เปิด System Browser (F9)
5. วาง หลอดไฟ สวิทย์ ตู้ไฟ
6. สร้าง Circuit จาก วาง Mouse ที่ หลอดไฟ  จะเห็น Power กับ Switch
   Swich จะเชื่อม Switch กับ หลอด Power จะสร้าง สาย กับ หลอด โดยกด Tab เป็น สีเหลี่ยม
ดูใน Sytem Browser จะมี Circuit ใหม่
กด Edit เพิ่ม สวิทย์
และจะเห็น ให้สร้าง Circuit
เลือก Panel ให้เลือก ที่ แถบ ระวัง Panel ต้อง มี Power Rating ตรงกับ หลอด และ สาย