以编程方式获取 AutoCAD 中块及其 ObjectId 的位置
本文关键字:ObjectId 位置 编程 方式 获取 AutoCAD | 更新日期: 2023-09-27 17:56:48
我正在尝试编写一种方法来更改AutoCAD图形中的现有块。在这种情况下,我想通过更改块的比例因子来更改块的长度。我编写的方法将通过删除旧块并使用新所需的比例因子创建一个新块来实现这一点。
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图形中获取现有块的XYZ坐标的内容。没有明显的方法来以编程方式获取块的坐标,这似乎很荒谬。
我不会接受改变我方法的答案。这必须通过删除旧块并通过在旧块所在的位置插入具有新属性的新块来替换它来完成。
不要使用 capPlate.Location
,请使用 capPlate.Position
,您应该获得所需的行为。