我正在尝试编写一种方法来更改 AutoCAD 图形中的现有 block 。在本例中,我想通过更改 block 的比例因子来更改 block 的长度。我编写的方法将通过删除旧 block 并使用新所需的比例因子创建一个新 block 来实现这一目标。
private static ObjectId _adjustCapPlate(ObjectId capPlateID, bool isHorizontal, Distance left = null, Distance right = null)
{
BlockReference capPlate = EntityMethods.GetBlockById(capPlateID); //Getting the block to be replaced
Scale3d oldScales = capPlate.ScaleFactors; //Getting the scales of the old block
Point3d originalLocation = capPlate.Location; // ToDo: Replace capPlate.Location with code that will return the coordinates of the insertion point of the block
EntityMethods.DeleteBlockFromDrawingWithId(capPlate.Id); //Deleting the old block
//Using specified splice plate length if method does not specify something else
if (left == null)
{
left = new Distance(SettingsController.SplicePlateLength / 2);
}
if (right == null)
{
right = new Distance(SettingsController.SplicePlateLength);
}
Distance newXScale, newYScale, newZScale;
Point3d newLocation;
if (isHorizontal) //If wall is oriented horizontally
{
newXScale = new Distance(DistanceType.Inch, oldScales.X - right.Inches);
newYScale = new Distance(DistanceType.Inch, oldScales.Y);
newLocation = new Point3d(originalLocation.X + left.Inches, originalLocation.Y, originalLocation.Z);
}
else
{
newXScale = new Distance(DistanceType.Inch, oldScales.X);
newYScale = new Distance(DistanceType.Inch, oldScales.Y - right.Inches);
newLocation = new Point3d(originalLocation.X, originalLocation.Y + left.Inches, originalLocation.Z);
}
newZScale = new Distance(DistanceType.Inch, oldScales.Z);
BlockReference newCapPlate = EntityMethods.InsertBlock("member", newLocation, "0", null, newXScale, newYScale, newZScale);
}
要使此方法发挥作用,我所需要做的就是将 capPlate.Location 替换为能够获取 AutoCAD 绘图中现有 block 的 XYZ 坐标的内容。没有明显的方法可以通过编程获取 block 的坐标,这似乎很荒谬。
我不会接受改变我的方法的答案。这必须通过删除旧 block 并通过在旧 block 所在位置插入具有新属性的新 block 来替换它来完成。
最佳答案
不要使用 capPlate.Location
,而是使用 capPlate.Position
,您应该会获得所需的行为。
关于c# - 以编程方式获取 AutoCAD 中 block 的位置及其 ObjectId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30876156/