- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
// based on C++ code by Virupaksha Aithal from this page:
//http://adndevblog.typepad.com/autocad/2012/08/create-3d-solid-by-extruding-a-polyline.html
[CommandMethod("extt")]
public void CreateExtrude()
{
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("delobj", 1);
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.SingleOnly = true;
pso.SinglePickInSpace = true;
pso.MessageForAdding = "\nPlease select a polyline: ";
pso.MessageForRemoval = "Failed to select a polyline";
pso.PrepareOptionalDetails = true;
SelectionFilter filter =
new SelectionFilter(
new TypedValue[] { new TypedValue(0, "lwpolyline"),new TypedValue(70, 1) });
//select the polyline
PromptSelectionResult sres = ed.GetSelection(pso,filter);
if (sres.Status != PromptStatus.OK) return;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
//get the boundary curves of the polyline
ObjectId idPoly = sres.Value[0].ObjectId;
Entity pEntity = tr.GetObject(idPoly, OpenMode.ForRead) as Entity;
Polyline pPoly = pEntity as Polyline; ;
if (pPoly == null) return;
DBObjectCollection lines = new DBObjectCollection();
pPoly.Explode(lines);
// Create a region from the set of lines.
DBObjectCollection regions = new DBObjectCollection();
regions = Region.CreateFromCurves(lines);
if (regions.Count == 0)
{
ed.WriteMessage("\nFailed to create region\n");
return;
}
Region pRegion = (Region)regions[0];
// Extrude the region to create a solid.
Solid3d pSolid = new Solid3d();
pSolid.RecordHistory = true;
pSolid.Extrude(pRegion, 10.0, 0.0);
ObjectId savedExtrusionId = ObjectId.Null;
ObjectId modelId;
modelId = SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTableRecord btr = tr.GetObject(modelId, OpenMode.ForWrite) as BlockTableRecord;
savedExtrusionId = btr.AppendEntity(pSolid);
tr.AddNewlyCreatedDBObject(pSolid,true);
if (!pPoly.IsWriteEnabled) pPoly.UpgradeOpen();
pPoly.Erase();
tr.Commit();
}
} |
|