Author Topic: Changing a property on a single dimension  (Read 1824 times)

0 Members and 1 Guest are viewing this topic.

MickB

  • Guest
Changing a property on a single dimension
« on: January 19, 2015, 11:36:22 AM »
Hi,

If i'm using AutoCAD and change the properties on a single dimension (i.e. turn alt units on)
this will change only this dimension and not others.

Is there any way to do this in code using the objectid of the dimension?

Thanks

Mick

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Changing a property on a single dimension
« Reply #1 on: January 19, 2015, 12:30:23 PM »
If your ObjectId is a dimension, then just cast it to a Dimension object.  There you can change a ton of properties, and some have to do with alternative items.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MickB

  • Guest
Re: Changing a property on a single dimension
« Reply #2 on: January 19, 2015, 02:26:55 PM »
Thanks for that, I'll have a go tomorrow and let you know how i get on.

Thanks
Mick

MickB

  • Guest
Re: Changing a property on a single dimension
« Reply #3 on: January 20, 2015, 01:41:11 PM »
Hi Tim,

I got it working, thanks for the help.

Mick

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Changing a property on a single dimension
« Reply #4 on: January 20, 2015, 02:05:36 PM »
Good to hear Mick.

If you can, would you post the code so others who have the same issue can find a working example?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MickB

  • Guest
Re: Changing a property on a single dimension
« Reply #5 on: January 21, 2015, 02:10:32 PM »
Hi Tim,

Here is the code I got to work. It's very simple, just pass in the ObjectID of a dimension.
There is no error checking in this.

Code: [Select]
Public Shared Sub ChangeDimension(ByVal MyDim As ObjectId)

        ' This code will overide the current dimension setting the alternative units to true
        ' Setting the precision of the alternative units to 2 and giving the alternative units
        ' a prefix of the symbol for diameter

        Dim myDwg As Document = DocumentManager.MdiActiveDocument

        Using myTrans As Transaction = myDwg.TransactionManager.StartTransaction

            Using (myDwg.LockDocument())

                'Open the database for Read
                Dim myBT As BlockTable = myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)

                'Open ModelSpace for Write
                Dim myBTR As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

                Dim NewDim As Dimension = TryCast(myTrans.GetObject(MyDim, OpenMode.ForWrite), Dimension)

                NewDim.Dimalt = True
                NewDim.Dimaltd = 2
                NewDim.Dimapost = "%%C[]"

                'Commit the transaction
                myTrans.Commit()

            End Using

        End Using
    End Sub

Thank again for your help.

Mick