标签:int 创建 XYZ wall double 二次开发 new Line Revit
创建墙测试
[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 来源: https://www.cnblogs.com/yhlx125/p/16664964.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。
