Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to convert a line segment or arc to a poly line, but when I execute it with AoutCAD, it becomes "e IllgalEntityType" and I cannot convert it.
Can you tell me how to convert it?
The code I'm writing is designed to behave as follows.
1.Get polylines and solids from model space.
2.Create a surface from a polyline.
3.Get the intersection of a surface and a solid.
4.Get the boundary edge from the intersection and convert it to a polyline.
5.Join polylines
Attach the code you are writing and the test data.
Thank you.
public class Class1
{
[CommandMethod("SolidPl")]
public void SolidPl()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor oED = acDoc.Editor;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
PromptSelectionResult acSSPrompt = acDoc.Editor.GetSelection();
BlockTable oDb;
oDb = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
BlockTableRecord obtr;
obtr = (BlockTableRecord)acTrans.GetObject(oDb[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
//Sort solids and polylines.
List<object> Poly2d = new List<object>();
List<object> Solid3d = new List<object>();
foreach (SelectedObject acSSObj in acSSet)
{
if (acSSObj != null)
{
Entity acEnt = (Entity)acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite);
if (acEnt != null)
{
List<object> Oblist = new List<object>();
Oblist.Add(acEnt);
List<string> Polylist = new List<string>();
Polylist.Add("Autodesk.AutoCAD.DatabaseServices.Polyline");
List<string> Sollist = new List<string>();
Sollist.Add("Autodesk.AutoCAD.DatabaseServices.Solid3d");
foreach (object a in Oblist)
{
foreach (string b in Polylist)
{
if (a.ToString() == b)
{
Poly2d.Add(a);
}
else
{
Solid3d.Add(a);
}
}
}
}
}
}
// Create a surface from polylines.
// Make the cross section where the surface and the solid overlap into a surface.
// Get the boundary edge (region) of the surface.
// Convert regions to polylines and combine them.
foreach (Polyline Poly3d in Poly2d)
{
Point3d sad = Poly3d.StartPoint;
foreach (Solid3d SolidSt in Solid3d)
{
Point3d sad2 = Poly3d.StartPoint;
if (SolidSt.ToString() == "Autodesk.AutoCAD.DatabaseServices.Solid3d")
{
Solid3d Solid = SolidSt as Solid3d;
// Create a surface from polylines.
Point3d Stp = Poly3d.StartPoint;
Point3d Etp = Poly3d.EndPoint;
double XPoint = Stp.X;
double YPoint = Stp.Y;
double ZPoint = Stp.Z;
Vector3d Vec1 = Stp.GetVectorTo(new Point3d(XPoint, YPoint, ZPoint-1000));
Polyline Poly3dCl = Poly3d.Clone() as Polyline;
Poly3dCl.TransformBy(Matrix3d.Displacement(Vec1));
Point3d StpCo = Poly3dCl.StartPoint;
Point3d EtpCo = Poly3dCl.EndPoint;
Line Lin = new Line(Stp, StpCo);
Line Lin2 = new Line(Etp, EtpCo);
obtr.AppendEntity(Lin);
acTrans.AddNewlyCreatedDBObject(Lin, true);
obtr.AppendEntity(Lin2);
acTrans.AddNewlyCreatedDBObject(Lin2, true);
obtr.AppendEntity(Poly3dCl);
acTrans.AddNewlyCreatedDBObject(Poly3dCl, true);
Entity[] Ent1 = new Entity[] { Poly3d,Poly3dCl };
Entity[] Ent2 = new Entity[] { Lin, Lin2 };
LoftedSurface LofSu = new LoftedSurface();
LofSu.CreateLoftedSurface(Ent1, Ent2, null, new LoftOptions());
obtr.AppendEntity(LofSu);
acTrans.AddNewlyCreatedDBObject(LofSu, true);
// Get the intersection of solid and surface.
Entity[] EntSurf = LofSu.BooleanIntersect(Solid);
foreach (Autodesk.AutoCAD.DatabaseServices.Surface Surf2 in EntSurf)
{
// Get the boundary edge (region) of the surface.
Entity[] EntLine = Surf2.ConvertToRegion();
foreach (Region region in EntLine)
{
// Convert from region to polyline.
var plines = new List<Polyline>();
using (var curves = new DBObjectCollection())
{
region.Explode(curves);
foreach (Curve curve in curves)
{
using (Polyline pline = new Polyline())
{
pline.ConvertFrom(curve, false);
obtr.AppendEntity(pline);
acTrans.AddNewlyCreatedDBObject(pline, true);
curve.Erase();
}
}
}
}
}
}
}
}
}
acTrans.Commit();
}
}
}
Solved! Go to Solution.