Changing Dimension Styles While Adding Dimensions

Changing Dimension Styles While Adding Dimensions

mgorecki
Collaborator Collaborator
1,298 Views
5 Replies
Message 1 of 6

Changing Dimension Styles While Adding Dimensions

mgorecki
Collaborator
Collaborator

Hello,

 In an earlier part of my code, I read in the dimension styles from another drawing.  Now I would like to start adding dimensions.  I have one style that has "Boxed" dimension text.  I have another that is just a basic dimension style.  I would like to know how to make a dimension style current.  I've looked at setting the DimensionStyleName to the name I want, but it errors out, so I'm not doing something right.

Any Help on this would be greatly appreciated.

 

Thanks,

Mark

0 Likes
Accepted solutions (1)
1,299 Views
5 Replies
Replies (5)
Message 2 of 6

mgorecki
Collaborator
Collaborator

By the way, I'm using VB.Net.

0 Likes
Message 3 of 6

Hallex
Advisor
Advisor

take a look at this post

http://forums.autodesk.com/t5/NET/Set-current-textstyle/m-p/2485015/highlight/true#M14423

see code at the bottom of page, published by Irvin

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 4 of 6

Anonymous
Not applicable

Post the code you have that errors out. Maybe someone can take it from there.

0 Likes
Message 5 of 6

mgorecki
Collaborator
Collaborator
Accepted solution

Hi Hallex,

Thanks for the link.  I think I have it figured out.  This code works for me.

 

    Public Sub AddHorDim(ByVal dimPnt1 As Point3d, ByVal dimPnt2 As Point3d, ByVal dimLoc As Point3d, ByVal dimType As String)
        'Get the current database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim DimStyleName As String

        DimStyleName = "BASIC"

        Select Case dimType
            Case "A"
                DimStyleName = "BASIC"
            Case "B"
                DimStyleName = "BASIC_1pl_decimal"
            Case "C"
                DimStyleName = "BASIC_BOXED"
            Case "D"
                DimStyleName = "BASIC_PAREN"
        End Select

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

            Dim acDimStylTbl As DimStyleTable = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead)

            'Open the Block table for read
            Dim acDimStylTblRec As DimStyleTableRecord
            acDimStylTblRec = New DimStyleTableRecord()
            acDimStylTblRec.Name = DimStyleName

            acDimStylTblRec = acTrans.GetObject(acDimStylTbl(DimStyleName), OpenMode.ForWrite)
            acCurDb.Dimstyle = acDimStylTbl(DimStyleName)
            acCurDb.Dimstyle = acDimStylTblRec.ObjectId
            acCurDb.SetDimstyleData(acDimStylTblRec)

            'Commit the changes
            acTrans.Commit()

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

            'Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)

            'Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

            'Create the rotated dimension
            'To add a horizontal dimension, use a rotation angle of 0.0
            Dim acRotDim As RotatedDimension = New RotatedDimension()
            acRotDim.SetDatabaseDefaults()
            acRotDim.XLine1Point = dimPnt1
            acRotDim.XLine2Point = dimPnt2
            acRotDim.DimLinePoint = dimLoc
            'Rotation angle is in radians
            acRotDim.Rotation = 0.0

            'Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acRotDim)
            acTrans.AddNewlyCreatedDBObject(acRotDim, True)

            'Commit the changes

            acTrans.Commit()
        End Using
    End Sub

0 Likes
Message 6 of 6

Hallex
Advisor
Advisor

You're quite welcome,

it's not my code though

Thanks Irvin 🙂

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes