2

我正在尝试编写一种方法,该方法通过块引用获取图形中的块并将其拉伸。到目前为止,我的方法如下所示:

 public static void stretchBlockWithId(ObjectId passedIdOfObjectToUpdate, Distance newXScale, Distance newYScale, Distance newZScale)
        {
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            using (DocumentLock docLock = doc.LockDocument())
            {
                BlockReference objectToStretch = transaction.GetObject(passedIdOfObjectToUpdate, OpenMode.ForWrite) as BlockReference;

                transaction.Commit();
            }
        }

我让对象通过它的 BlockReference 进行拉伸,但似乎无论如何都没有将块转换为更宽和/或更长(我正在处理 2D 平面)。这样做的最佳方法是什么?

4

2 回答 2

0

我在 VB.net 中做了类似的事情来创建一个在 x、y、z 方向上缩放(多个)对象的函数。这是代码的业务部分,如果需要,将其转换为 C#

 Using myDwg.LockDocument

        Using tr = myDwg.TransactionManager.StartTransaction

            'Open the database for Write
            myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
            myBTR = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

            Dim myBlockRef As BlockReference = tr.GetObject(MyIdsCol(0), OpenMode.ForWrite)
            myBlockRef.ScaleFactors = New Scale3d(CType(Xscale, Double), CType(Yscale, Double), CType(Zscale, Double))

            myBlockRef.ExplodeToOwnerSpace()
            myBlockRef.Erase(True)

            Dim btr As BlockTableRecord = tr.GetObject(myBT(Bloknaam), OpenMode.ForWrite, True, True)
            Dim idcoll As ObjectIdCollection = New ObjectIdCollection()
            idcoll.Add(btr.ObjectId)
            myDwg.Database.Purge(idcoll)
            btr.Erase(True)
            tr.Commit()

        End Using
    End Using
于 2015-04-14T10:01:21.137 回答
0

You cannot "stretch" a block reference. To change it's size you need to either 1. Redefine the Block (definition) or 2. change the BlockReference ScaleFactors property. Changing the ScaleFactors may not give you the results you are looking for. One way to see if it will do what you want is to create the block, insert it into an AutoCAD drawing and then play with the Scale X, Y and Z values in the property editor.

于 2015-04-15T17:46:10.027 回答