gpt4 book ai didi

c#, Autocad, 显示填充的属性

转载 作者:行者123 更新时间:2023-12-05 09:26:32 27 4
gpt4 key购买 nike

我正在使用 C# 编写 AutoCAD 插件,需要在阴影对象的中间(例如,圆心)显示阴影属性。我在代码中有两个问题:

  1. 如何访问圆心?

  2. 如何获取hatch的属性?

我在 autocad 中的这一行遇到错误。

acText.TextString = hatch.Area.ToString(); // Area of hatch

下面是主要摘自Stackflow的代码.

 [CommandMethod("DisplyArea")]
public static void SelectCirclesToHatch()
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var filter = new SelectionFilter(new[] { new TypedValue(0, "CIRCLE") });
var selection = ed.GetSelection(filter);
int vr = 1;
if (selection.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var id in selection.Value.GetObjectIds())
{
var ids = new ObjectIdCollection(new[] { id });
using (var hatch = new Hatch())
{
curSpace.AppendEntity(hatch);
tr.AddNewlyCreatedDBObject(hatch, true);
hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
hatch.Associative = true;
hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
hatch.EvaluateHatch(true);
DBText acText = new DBText();

//它需要是 CIRCLE.CENTER,但我怎样才能访问它?????

                        acText.Position = new Point3d(2,2,0);     

acText.TextString = hatch.Area.ToString(); // Area of hatch
acText.Height = 0.5;
curSpace.AppendEntity(acText);
tr.AddNewlyCreatedDBObject(acText, true);
}
}
tr.Commit();
}
}

有什么解决办法吗?

最佳答案

  1. 如何访问圆心?
    答:
    Circle oCircle = tr.GetObject(id, OpenMode.ForRead) as Circle; var _centerPosition = oCircle.Center;

  2. 如何获取hatch的属性?
    答:
    你需要改变
    来自 hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
    hatch.AppendLoop(HatchLoopTypes.External, ids);

我修改了你的代码,它对我有用

public static void SelectCirclesToHatch()
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var filter = new SelectionFilter(new[] { new TypedValue(0, "CIRCLE") });
var selection = ed.GetSelection(filter);
int vr = 1;
if (selection.Status != PromptStatus.OK) { return; }

using (var tr = db.TransactionManager.StartTransaction())
{
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (var id in selection.Value.GetObjectIds())
{
try
{
var ids = new ObjectIdCollection(new[] { id });
using (var hatch = new Hatch())
{
curSpace.AppendEntity(hatch);
tr.AddNewlyCreatedDBObject(hatch, true);
hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
hatch.Associative = true;
hatch.AppendLoop(HatchLoopTypes.External, ids);
hatch.EvaluateHatch(true);
hatch.HatchStyle = HatchStyle.Normal;

Circle oCircle = tr.GetObject(id, OpenMode.ForRead) as Circle;
var _centerPosition = oCircle.Center;

DBText acText = new DBText();
acText.Position = _centerPosition;

acText.TextString = hatch.Area.ToString(); // Area of hatch
acText.Height = 0.5;
curSpace.AppendEntity(acText);
tr.AddNewlyCreatedDBObject(acText, true);
}
}
catch { }
}
tr.Commit();
}
}

关于c#, Autocad, 显示填充的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73813281/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com