我正在尝试编写一种方法来更改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
,您应该获得所需的行为。
关于c# - 以编程方式使用其ObjectId获取AutoCAD中块的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30876156/