Sorry Mario, TT is right.
Well another more attempt, I can't reach at RunCommand,
still working in A2010 only, better test it in 3d view
[CommandMethod("testCylinderByVector")]
public void DrawExtrudedCylinderByVector()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Point3d cp,vecpt;
PromptPointOptions ptopts = new PromptPointOptions("\nSelect center point of circel: ");
PromptPointResult ptres = ed.GetPoint(ptopts);
// Exit if the user presses ESC or cancels the command
if (ptres.Status != PromptStatus.OK) return;
// Center point
cp = ptres.Value;
ptopts.Message = "\nSpecify direction vector: ";
ptopts.BasePoint = cp;
ptopts.UseBasePoint = true;
ptres = ed.GetPoint(ptopts);
// Exit if the user presses ESC or cancels the command
if (ptres.Status != PromptStatus.OK) return;
// Center point
vecpt = ptres.Value;
Vector3d vec = (vecpt - cp).GetNormal();
PromptDistanceOptions pdo = new PromptDistanceOptions("\nEnter a radius: ");
pdo.AllowNone = true;
pdo.UseDefaultValue = true;
pdo.DefaultValue = 100.0;
pdo.BasePoint = cp;
pdo.UseBasePoint = true;
pdo.UseDashedLine = true;
PromptDoubleResult res;
res = ed.GetDistance(pdo);
if (res.Status != PromptStatus.OK)
return;
double rad = res.Value;
pdo = new PromptDistanceOptions("\nEnter cylinder height: ");
pdo.AllowNone = true;
pdo.UseDefaultValue = true;
pdo.DefaultValue = 1000.0;
pdo.BasePoint = cp;
pdo.UseBasePoint = true;
pdo.UseDashedLine = true;
res = ed.GetDistance(pdo);
if (res.Status != PromptStatus.OK)
return;
double height = res.Value;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Circle circ = new Circle(cp, Vector3d.ZAxis, rad);
circ.Normal = vec;
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
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;// important
sol.ShowHistory = true;// important
sol.Extrude(reg, height, 0.0);// < --- set taper angle here
ObjectId solId = ObjectId.Null;
solId = btr.AppendEntity(sol);
tr.AddNewlyCreatedDBObject(sol, true);
if (!circ.IsWriteEnabled) circ.UpgradeOpen();
circ.Erase();
tr.Commit();
}
}