2

I'm trying to write a method that takes a block in a drawing via it's block reference and stretches it out. So far my method looks like this:

 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();
            }
        }

I get the object to stretch by it's BlockReference but there does not appear to be anyway to transform the block so that it is wider and/or longer (I'm working on a 2D plane). What is the best way to go about doing this?

Nick Gilbert
  • 4,159
  • 8
  • 43
  • 90
  • 1
    You should not try to stretch the existing block. You should instead find all the blocks you want to stretch and insert new ones with the correct sizes in place of the old ones. – jth41 Mar 18 '15 at 11:36

2 Answers2

0

I did something similar in VB.net to create a function to scale (multiple) objects in x,y, z directions. here's the business part of the code, convert it to C# if needed

 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
Alain
  • 304
  • 3
  • 9
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.

mohnston
  • 737
  • 1
  • 6
  • 18