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

Creating Dimension Styles

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
thedude2008
803 Views, 3 Replies

Creating Dimension Styles

I'm having trouble creating dimension styles. The process I take is this... Assign and/or change dimension variables, name the dimension style, add the dimension style record to the dimension style table. This process creates the dimension style as wanted, but creates a dimension override... that's not what I want... as an example I have attached the code...

 

Public Sub CreateDimStyle()

    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database

        Dim DimStyleName As String = "English"

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Dim acDimStylTbl As DimStyleTable = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead)
            Dim acDimStylTblRec As DimStyleTableRecord

            'Assign dimension variables
            acCurDb.Dimalt = 0
            acCurDb.Dimaltd = 2
            acCurDb.Dimaltf = 25.4
            acCurDb.Dimaltrnd = 0.0

            acDimStylTblRec = New DimStyleTableRecord()
            acDimStylTblRec.Name = DimStyleName

            If acDimStylTbl.Has(CEGDimensionStyle) = False Then 'If dimension style does not exist, create it
                If acDimStylTbl.IsWriteEnabled = False Then acDimStylTbl.UpgradeOpen()
                acDimStylTbl.Add(acDimStylTblRec)
                acTrans.AddNewlyCreatedDBObject(acDimStylTblRec, True)
            Else 'Dimension style exists... open style record for changes
                acDimStylTblRec = acTrans.GetObject(acDimStylTbl(DimStyleName), OpenMode.ForWrite)
            End If
            acTrans.Commit()
        End Using
    End Sub

 

The above code inserts the dimension style with an override (if you were to look in the dimstyle dialog box for instance) if you set the above dim style to the current style. Any ideas on what im doing wrong? I want to set the newly created dim style in the above code to the current dim style WITHOUT an override and with all the dim style settings saved.

 

Please... any help is greatly appreciated! Thanks in advance.

3 REPLIES 3
Message 2 of 4

Don't assign the dimalt.. variables to the database, assign them to the style you are creating (or modifying).  I did a little test with your code rearranged slightly, and it did not create a dimstyle override.

 

Of course, the code you posted does nothing but open and close the style if it exists.

Dave O.                                                                  Sig-Logos32.png
Message 3 of 4

Thanks for the quick reply chiefbraincloud, but my problem occurs (the override is created) when i attempt to set the newly created dimension style to the current dimension style... i re-arranged my code to attempt to add the dimension style proeprties after creating the dimension style as you suggested, but after setting the dimension style to the current dimension style... the override issue still occurs... please take a look at the following code and let me know what you (or whoever) thinks... (i also now assign the dimension variables to the dimension record instead of the current db)...

 

 

Public Sub CADDimensionStyleTest()

        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        Dim DimStyleName As String = "English"

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Dim acDimStylTbl As DimStyleTable = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead)
            Dim acDimStylTblRec As DimStyleTableRecord

            acDimStylTblRec = New DimStyleTableRecord()
            acDimStylTblRec.Name = DimStyleName

            If acDimStylTbl.Has(DimStyleName) = False Then 'If dimension style does not exist, create it
                If acDimStylTbl.IsWriteEnabled = False Then acDimStylTbl.UpgradeOpen()
                acDimStylTbl.Add(acDimStylTblRec)
                acTrans.AddNewlyCreatedDBObject(acDimStylTblRec, True)
            End If

            acDimStylTblRec = acTrans.GetObject(acDimStylTbl(DimStyleName), OpenMode.ForWrite)                                                                                                                                                        'Add all required dimension style settings here, etc...
            acDimStylTblRec.Dimadec = 4

            acTrans.Commit()

            'This is where the problem occurs... it creates a dimension override when setting the newly
            'created dimension to the current...
            acCurDb.Dimstyle = acDimStylTbl("English")
        End Using
    End Sub

 

Message 4 of 4
thedude2008
in reply to: thedude2008

Problem solved... after setting the newly created dimension style to the current style as shown below... the overrides are merged with the dimension style by using the "SetDimStyleData" method as shown below... (this code should be incorporated with the code posted above.

 

acCurDb.Dimstyle = acDimStylTblRec.ObjectId
acCurDb.SetDimstyleData(acDimStylTblRec)

 

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