Vince, try this one just for first two points of 3dpolyline
extend code to your needs, just a note created cylinders aren't
real cylinder, many properties of them not applicable,
see properties window after creating things
[CommandMethod("3cy")]
public void Pline3dToExtrudedCylinders()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// radius of cylinder
double rad = 10.0;
SelectionFilter filt = new SelectionFilter(new TypedValue[]{
new TypedValue(0,"polyline")});// add: ,new TypedValue(8,"mylayer")
PromptSelectionResult res = ed.GetSelection(filt);
if (res.Status != PromptStatus.OK) return;
SelectionSet sset = res.Value;
Entity ent;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
foreach (SelectedObject obj in sset)
{
ent = tr.GetObject(obj.ObjectId, OpenMode.ForRead) as Entity;
if (ent == null)
return;
Polyline3d poly = ent as Polyline3d;
if (poly == null) return;
Point3d p1= poly.GetPointAtParameter(poly.StartParam);
Point3d p2 = poly.GetPointAtParameter(poly.StartParam+1.0);
Vector3d vec = (p2 - p1).GetNormal();
double height = p1.DistanceTo(p2);
Circle circ = new Circle(p1, vec, rad);
circ.Normal = vec;
ObjectId objId = btr.AppendEntity(circ);
tr.AddNewlyCreatedDBObject(circ, true);
// Get the boundary curves to create a region
DBObjectCollection regs = new DBObjectCollection();
regs.Add(circ);
// Create a region from the circle.
DBObjectCollection regions = new DBObjectCollection();
regions = Region.CreateFromCurves(regs);
if (regions.Count == 0)
{
ed.WriteMessage("\nFailed to create region\n");
return;
}
Region reg = (Region)regions[0];
// Extrude the region to create a solid.
Solid3d sol = new Solid3d();
sol.RecordHistory = true;// optional
sol.ShowHistory = false;// optional
sol.Extrude(reg, height, 0.0);
ObjectId solId = ObjectId.Null;
solId = btr.AppendEntity(sol);
tr.AddNewlyCreatedDBObject(sol, true);
if (!circ.IsWriteEnabled) circ.UpgradeOpen();
circ.Erase();
}
tr.Commit();
}
}
_____________________________________
C6309D9E0751D165D0934D0621DFF27919