.NET

Reply
Distinguished Contributor
macleodjb
Posts: 137
Registered: ‎12-22-2004
Message 1 of 2 (117 Views)

DIMSCALE problem

117 Views, 1 Replies
02-06-2014 05:04 PM

Is it really this difficult to set a dimscale in an existing drawing to the current one?  Geez.  I've been googling for way too long without a result.  Hoping someone here can set me on the right path.  So I have two remaining questions.  #1 - How can I fix the code below to set an existing dim style to be the current one.  I'd like to pass in a name of the Dim Style and have it become active.  #2 - How can I loop through the dim style table to view all the available dim styles.  Thanks in advance.

 

        <CommandMethod("MyTest")> _
        Public Sub MyTest()
            '' Get the current database
            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database

            '' Start a transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                '' Open the DimStyle table for read
                Dim acDimStyleTbl As DimStyleTable
                acDimStyleTbl = DirectCast(acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead), DimStyleTable)

                For Each objectid As ObjectId In acDimStyleTbl
                    MessageBox.Show(objectid.ToString)
                Next

                '' Commit the changes and dispose of the transaction
                acTrans.Commit()
            End Using
        End Sub

 

Distinguished Contributor
HJohn1
Posts: 170
Registered: ‎09-26-2008
Message 2 of 2 (81 Views)

Re: DIMSCALE problem

02-07-2014 05:31 AM in reply to: macleodjb

You can try this, you can pass a dimension name and scale.

<CommandMethod("MyTest")> _
        Public Sub MyTest(ByVal DimName As String, ByVal DimScale As Double)
            '' Get the current database
            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database

            '' Start a transaction
            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                '' Open the DimStyle table for read
                Dim acDimStyleTbl As DimStyleTable
                acDimStyleTbl = DirectCast(acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead), DimStyleTable)

                Dim DimTblRec As DimStyleTableRecord

                For Each objectid As ObjectId In acDimStyleTbl

                    DimTblRec = CType(acTrans.GetObject(objectid, OpenMode.ForRead), DimStyleTableRecord)

                    MessageBox.Show(DimTblRec.Name)

                Next

                If acDimStyleTbl.Has(DimName) = True Then

                    DimTblRec = CType(acTrans.GetObject(acDimStyleTbl(DimName), OpenMode.ForWrite), DimStyleTableRecord)

                    DimTblRec.Dimscale = DimScale

                    acCurDb.Dimstyle = DimTblRec.ObjectId

                    acCurDb.SetDimstyleData(DimTblRec)

                Else

                    'Add code to handle this

                End If

                '' Commit the changes and dispose of the transaction
                acTrans.Commit()
            End Using
        End Sub

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!