.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DIMSCALE problem

1 REPLY 1
Reply
Message 1 of 2
macleodjb
424 Views, 1 Reply

DIMSCALE problem

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

 

1 REPLY 1
Message 2 of 2
HJohn1
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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost