C# 在AutoCAD中获取实体的子实体顶点
我试图找到扫描多段线的顶点。 所以我有一个实体,它是通过沿着三维多段线扫一个圆创建的。 看起来是这样的: 上周整个星期五我都在谷歌上搜索,我想我得好好玩玩子实体部分。例如,我发现了如何更改子实体边的颜色,但为了基督的缘故,我没有发现如何访问几何图形 这是我迄今为止尝试过的,但正如我在底部指出的,我有点迷路了:C# 在AutoCAD中获取实体的子实体顶点,c#,autocad,C#,Autocad,我试图找到扫描多段线的顶点。 所以我有一个实体,它是通过沿着三维多段线扫一个圆创建的。 看起来是这样的: 上周整个星期五我都在谷歌上搜索,我想我得好好玩玩子实体部分。例如,我发现了如何更改子实体边的颜色,但为了基督的缘故,我没有发现如何访问几何图形 这是我迄今为止尝试过的,但正如我在底部指出的,我有点迷路了: [CommandMethod("SubEntExample")] public void SubEntExample() { Document do
[CommandMethod("SubEntExample")]
public void SubEntExample()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a 3D solid: ");
peo.SetRejectMessage("\nInvalid selection...");
peo.AddAllowedClass(typeof(Solid3d), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
Solid3d solid = Tx.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;
ObjectId[] ids = new ObjectId[] { per.ObjectId };
FullSubentityPath path = new FullSubentityPath(ids, new SubentityId(SubentityType.Null, IntPtr.Zero));
List<SubentityId> subEntIds = new List<SubentityId>();
using (Autodesk.AutoCAD.BoundaryRepresentation.Brep brep =
new Autodesk.AutoCAD.BoundaryRepresentation.Brep(path))
{
foreach (Autodesk.AutoCAD.BoundaryRepresentation.Edge edge in brep.Edges)
{
subEntIds.Add(edge.SubentityPath.SubentId);
}
}
foreach (SubentityId subentId in subEntIds)
{
*** here i am lost ***
}
Tx.Commit();
}
}
[CommandMethod(“SubEntExample”)]
public void SubEntExample()
{
Document doc=Application.DocumentManager.MdiActiveDocument;
数据库db=doc.Database;
编辑器ed=文档编辑器;
PrompEntityOptions peo=新PrompEntityOptions(“\n选择三维实体:”);
peo.SetRejectMessage(“\n无效选择…”);
peo.AddAllowedClass(typeof(Solid3d),true);
PrompEntityResult per=ed.GetEntity(peo);
if(per.Status!=PromptStatus.OK)
返回;
使用(Transaction Tx=db.TransactionManager.StartTransaction())
{
Solid3d solid=Tx.GetObject(per.ObjectId,OpenMode.ForWrite)作为Solid3d;
ObjectId[]ids=新ObjectId[]{per.ObjectId};
FullSubentityPath=newfullsubentitypath(id,newsubentityid(SubentityType.Null,IntPtr.Zero));
List subEntIds=new List();
使用(Autodesk.AutoCAD.BoundaryRepresentation.Brep)=
新的Autodesk.AutoCAD.BoundaryRepresentation.Brep(路径))
{
foreach(Autodesk.AutoCAD.BoundaryRepresentation.Edge中的边)
{
添加(edge.SubentityPath.SubentId);
}
}
foreach(SubentityId subentId在subentId中)
{
***我迷路了***
}
Tx.Commit();
}
}
我的第一个解决方案是获取所有的关键点,并确定哪些是相关的,但多亏了互联网的帮助(:)我想出了一个更好的解决方案
/// <summary>
/// Checks if there are boundaryreps that are marked as elliptical or circular arcs
/// returns true if we found at least 2 of those points
/// also stores the points in a referenced Point3dCollection
/// </summary>
/// <param name="solid"></param>
/// <param name="pts"></param>
/// <returns></returns>
private bool GetSweepPathPoints(Solid3d solid, ref Point3dCollection pts)
{
// create boundary rep for the solid
using (Brep brep = new Brep(solid))
{
// get edges of the boundary rep
BrepEdgeCollection edges = brep.Edges;
foreach (Edge edge in edges)
{
// get the nativ curve geometry of the edges and then
// check if it is a circle
// for more info look at:
// http://adndevblog.typepad.com/autocad/2012/08/retrieving-native-curve-geometry-using-brep-api.html
Curve3d curv = ((ExternalCurve3d)edge.Curve).NativeCurve;
if (curv is CircularArc3d)
{
// transform curved arch into circle and add it to the colecction
// (if not in it alreadz)
CircularArc3d circle = curv as CircularArc3d;
if (!pts.Contains(circle.Center)) pts.Add(circle.Center);
}
}
}
return (pts.Count > 1) ? true : false;
}
//
///检查是否存在标记为椭圆或圆弧的BoundaryRep
///如果至少找到其中两个点,则返回true
///还将点存储在引用的Point3dCollection中
///
///
///
///
私有布尔GetSweepPathPoints(Solid3d实体,参考点3DCollection点)
{
//为实体创建边界表示
使用(Brep Brep=新Brep(固体))
{
//获取边界的边
BrepEdgeCollection边=brep.边;
foreach(边中的边)
{
//获取边的nativ曲线几何体,然后
//检查它是否是一个圆
//有关更多信息,请参阅:
// http://adndevblog.typepad.com/autocad/2012/08/retrieving-native-curve-geometry-using-brep-api.html
Curve3d curv=((ExternalCurve3d)edge.Curve).NativeCurve;
if(曲线为圆形C3d)
{
//将弧形拱转化为圆形,并将其添加到集合中
//(如果不在其中,请参阅)
CircularC3d圆=曲线为CircularC3d;
如果(!pts.Contains(circle.Center))pts.Add(circle.Center);
}
}
}
返回(pts.Count>1)?真:假;
}
那我就这样说了
Point3dCollection pts = new Point3dCollection();
// only do the whole thing if we face a swept solid
if (GetSweepPathPoints(sld, ref pts))
{
for (int i = 0; i < pts.Count; i++)
{
ed.WriteMessage("\nPt[{0}] = {1}", i, pts[i]);
}
}
Point3dCollection pts=new Point3dCollection();
//只有当我们面对一个被扫过的实体时,才能完成整个过程
if(获取扫描路径点(sld,参考点))
{
for(int i=0;i
将实体导出到DXF并查看文本文件中数据的组成如何?它可能会向您解释子实体的机制。我对手头的案件没有具体的了解,但是,如果他们是“身份证”,那么你接下来会如何“打开”这些身份证?这些将返回提供坐标数据的合适对象。但这只是猜测。查看DXF可能会向您显示更多信息。也许你可以把它添加到你的问题中。