以编程方式使用ObjectId获取AutoCAD中块的位置

时间:2015-06-16 19:09:14

标签: c# autocad-plugin

我正在尝试编写一种方法来更改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坐标的东西。似乎很荒谬的是,没有明显的方法可以通过编程方式获得块的坐标。

我不接受改变我的方法的答案。这必须通过删除旧块并通过插入具有旧块所在的新属性的新块来替换它。

1 个答案:

答案 0 :(得分:3)

不使用capPlate.Location,而是使用capPlate.Position,您应该获得所需的行为。