.NET

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

DIMSCALE problem

113 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 (77 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

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.