创建墙测试
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)] [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)] public class AxWallCreate : IExternalCommand { Autodesk.Revit.ApplicationServices.Application app; Autodesk.Revit.DB.Document doc; List<AxWallLine> m_WallPolylines = null; public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; app = uiApp.Application; doc = uiDoc.Document; Selection selection = uiDoc.Selection; OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "打开墙线文件"; dlg.Filter = "(*.shp)|*.shp"; if (dlg.ShowDialog() == DialogResult.OK && dlg.FileName != String.Empty) { String wallFileName = dlg.FileName; MessageBox.Show(wallFileName); ReadWallLinesSHP(wallFileName); String info = "读取线的数目:" + m_WallPolylines.Count; MessageBox.Show(info, "信息"); CreateWall(); } return Result.Succeeded; } //读取墙线文件 private void ReadWallLinesSHP(string FILENAME) { IntPtr hShp; hShp = ShapeLib.SHPOpen(FILENAME, "rb+"); m_WallPolylines = new List<AxWallLine>(); // get shape info and verify shapes were created correctly double[] minB = new double[4]; double[] maxB = new double[4]; int nEntities = 0; ShapeLib.ShapeType shapeType = 0; ShapeLib.SHPGetInfo(hShp, ref nEntities, ref shapeType, minB, maxB); double m_MinX = minB[0]; double m_MinY = minB[1]; for (int i = 0; i < nEntities; i++) { int iShape = i; IntPtr pshpObj = ShapeLib.SHPReadObject(hShp, iShape); AxPolyline2d plline = new AxPolyline2d(); ShapeLib.SHPObject shpObj = new ShapeLib.SHPObject(); Marshal.PtrToStructure(pshpObj, shpObj); int parts = shpObj.nParts; if (parts > 0) { int[] partStart = new int[parts]; Marshal.Copy(shpObj.paPartStart, partStart, 0, parts); int[] partType = new int[parts]; Marshal.Copy(shpObj.paPartType, partType, 0, parts); int number = shpObj.nVertices; double[] m_padfX = new double[number]; Marshal.Copy(shpObj.padfX, m_padfX, 0, number); double[] m_padfY = new double[number]; Marshal.Copy(shpObj.padfY, m_padfY, 0, number); for (int iv = 0; iv < number; iv++) { double x = m_padfX[iv]; double y = m_padfY[iv]; x = x - minB[0]; y = y - minB[1]; Vector2d pt = new Vector2d(x * 1000, y * 1000); plline.polyline.Add(pt);// } AxWallLine wall = new AxWallLine(); wall.WallId = 1000 + i; wall.m_Polyline = plline; wall.m_MaxZ = 3000; wall.m_MinZ = 0; wall.m_Thickness = 150; m_WallPolylines.Add(wall); } ShapeLib.SHPDestroyObject(pshpObj); } ShapeLib.SHPClose(hShp); } public void CreateWall() { //List<Curve>; IList<Curve> curves = new List<Curve>(); Line l1 = Line.CreateBound(XYZ.Zero, new XYZ(150, 0, 0)); Line l2 = Line.CreateBound(XYZ.Zero, new XYZ(50, 0, 50)); Line l3 = Line.CreateBound(new XYZ(50, 0, 50), new XYZ(100, 0, 50)); Line l4 = Line.CreateBound(new XYZ(100, 0, 50), new XYZ(150, 0, 0)); curves.Add(l1); curves.Add(l2); curves.Add(l3); curves.Add(l4); using (Transaction ts = new Transaction(doc,"AxCreateWall")) { ts.Start(); Wall.Create(doc, curves, false); ts.Commit(); } for (int i = 0; i < m_WallPolylines.Count; i++) { AxWallLine wall = m_WallPolylines[i]; List<Vector2d> segments = wall.m_Polyline.polyline; for (int j = 0; j < segments.Count-1; j++) { Vector2d segment0 = segments[j]; Vector2d segment1 = segments[j+1]; XYZ pt0 = new XYZ(segment0.X, segment0.Y, 0); XYZ pt1 = new XYZ(segment1.X, segment1.Y, 0); Line line = Line.CreateBound(pt0, pt1); //Wall.Create(doc, line, true); } } } }
标签:int,创建,XYZ,wall,double,二次开发,new,Line,Revit From: https://www.cnblogs.com/yhlx125/p/16664964.html