- 积分
- 848
- 明经币
- 个
- 注册时间
- 2008-8-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 LDJ 于 2015-6-5 09:57 编辑
// 由图案填充类型、填充图案名称、
// 填充角度和填充比例创建图案填充的函数.
// partType:0为预定义图案;1为用户定义图案;2为自定义图案.
private ObjectId AddHatch(out Hatch hatchEnt, HatchPatternType patType,
String patName, Double patternAngle, Double patternScale)
{
//ObjectId entId = Autodesk.AutoCAD.DatabaseServices.ObjectId.Null;
Hatch ent = new Hatch();
ent.HatchObjectType = HatchObjectType.HatchObject;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject
(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject
(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
ObjectId entId = btr.AppendEntity(ent);
try
{
trans.AddNewlyCreatedDBObject(ent, true);
ent.SetDatabaseDefaults();
ent.PatternAngle = patternAngle;//出现异常
ent.PatternScale = patternScale;
ent.SetHatchPattern(patType, patName);
hatchEnt = ent;
return entId;
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
hatchEnt = ent;
return entId;
}
trans.Commit();
}
}
[CommandMethod("testdiff", CommandFlags.UsePickSet | CommandFlags.Modal | CommandFlags.Redraw)]
public void testdiff()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult res = ed.SelectImplied();
if (PromptStatus.OK == res.Status)
{
// Convert the SelectionSet to MgSelectionBase using AcMapFeatureEntityService.
Debug.Assert(res.Value != null);
if (res.Value.Count != 1) return;
ObjectId entityID = res.Value[0].ObjectId;
//ObjectId entityID2 = res.Value[1].ObjectId;
ObjectIdCollection loops1 = new ObjectIdCollection();
loops1.Add(entityID);
//loops1.Add(entityID2);
ObjectIdCollection[] loops = new ObjectIdCollection[1];
loops.SetValue(loops1, 0);
Hatch hatchEnt;
ObjectId hatEntId = AddHatch(out hatchEnt, 0, "ANGLE", Math.PI / 3, 10);
Database db = HostApplicationServices.WorkingDatabase;
// 关联填充图案与边界.
using (Transaction tr = db.TransactionManager.StartTransaction())
{
hatchEnt = (Hatch)tr.GetObject(hatEntId, OpenMode.ForWrite);
hatchEnt.Associative = true;
for (int i = 0; i < loops.Length; i++)
{
hatchEnt.AppendLoop(HatchLoopTypes.Default, loops);
}
tr.Commit();
}
}
}
选择一个封闭的pline后 运行代码,出现异常,提示eInvalidInput
高手帮助看下
|
|