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

How do I set the color index and layer of newly created dimension style

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mindofcat
679 Views, 5 Replies

How do I set the color index and layer of newly created dimension style

Hi all, I'm having a bit of a problem struggling with creating new dimension style using vee bee dot net, in AutoCAD 2010 environment. I am particularly trying to figure out how to set the newly created dimension style to color white, and to assign it a specific layer (for example, a layer called "test").

 

Does anyone know what the code syntax is to accomplish this?

 

I post the code below for what I have done thus far:

 

Public Shared Sub addDimensionStyle(ByVal strDimStyle As String)

Dim acDb As Database = HostApplicationServices.WorkingDatabase
Using acTrans As Transaction = acDb.TransactionManager.StartTransaction()


Dim dimTbl As DimStyleTable = acDb.DimStyleTableId.GetObject(OpenMode.ForWrite)
Dim dimTblRec As DimStyleTableRecord = Nothing


If dimTbl.Has(strDimStyle) = True Then
dimTblRec = dimTbl(strDimStyle).GetObject(OpenMode.ForRead)
Else
dimTblRec = New DimStyleTableRecord()
dimTblRec.Name = strDimStyle
dimTbl.Add(dimTblRec)

 

' Set the color index of the new dimension style here...

 

' Set the layer of the new dimension style here...


acTrans.AddNewlyCreatedDBObject(dimTblRec, True)
End If
acTrans.Commit()

End Using

End Sub

 

 

Any help is greatly appreciated.

 

Many thanks in advance...

 

Cat

5 REPLIES 5
Message 2 of 6
Hallex
in reply to: mindofcat

Take a look at this article:
http://through-the-interface.typepad.com/through_the_interface/2010/01/creating-an-autocad-layer-usi...
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 6
Hallex
in reply to: mindofcat

Found one in my codes:

        <CommandMethod("hanno")> _
        Public Sub testCreateLayer()
            CreateLayer("H-ANNO-MARK", "HIDDEN2", 14)
        End Sub
        Private Sub CreateLayer(layerName As String, ltpname As String, color As Short)
            Dim layerId As ObjectId
            Dim ltrid As ObjectId = ObjectId.Null
            Dim db As Database = HostApplicationServices.WorkingDatabase
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim lt As LayerTable = DirectCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
                If lt.Has(layerName) Then
                    layerId = lt(layerName)
                Else
                    Dim ltr As New LayerTableRecord()
                    ltr.Name = layerName
                    ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, color)
                    Dim ltt As LinetypeTable = TryCast(tr.GetObject(db.LinetypeTableId, OpenMode.ForRead), LinetypeTable)

                    If ltt.Has(ltpname) Then
                        ltrid = ltt(ltpname)

                        ltt.UpgradeOpen()


                        ltr.LinetypeObjectId = ltrid
                    Else
                        LoadLineType(ltpname)
                        Dim lttr As LinetypeTableRecord = TryCast(tr.GetObject(ltt(ltpname), OpenMode.ForRead, False), LinetypeTableRecord)
                        ltr.LinetypeObjectId = ltt(ltpname)
                    End If
                    lt.UpgradeOpen()
                    layerId = lt.Add(ltr)
                    tr.AddNewlyCreatedDBObject(ltr, True)
                    db.Clayer = layerId
                End If
                tr.Commit()
            End Using
        End Sub

        '----------------------------------------------------------------------

        Public Shared Sub LoadLineType(ltname As String)
            Dim db As Database = HostApplicationServices.WorkingDatabase

            Using tr As Transaction = db.TransactionManager.StartTransaction()


                Dim tbl As LinetypeTable = DirectCast(tr.GetObject(db.LinetypeTableId, OpenMode.ForRead), LinetypeTable)

                If Not tbl.Has(ltname) Then
                    db.LoadLineTypeFile(ltname, "acad.lin")
                End If
                tr.Commit()
            End Using
        End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 6
mindofcat
in reply to: Hallex

Thanks for the quick reply, Hallex... However, my problem is not creating a new layer; my problem is assigning a layer and color index to the dimension style I created in the code I posted.  

 

I looked through the pop up options for the dimension style table record newly created, and I see options like Dimclrd, Dimclre and I don't see an option for Layer (for example dimTblRec.Layer="Test Layer", dimTblRec.colorIndex=7)

 

 

My task is to create a dimension style that will always be on layer "DImension Layer" and will always be on color white.

 

I only came as far as creating the dimension style, then I am stuck. Any ideas?

 

Many thanks in advance.

Message 5 of 6
dgorsman
in reply to: mindofcat

Layer is a property of dimension entities, not dimension styles.  In order for them to always be on a specific layer, you will need to create your own dimension object commands, or react to events fired when they are added to the drawing.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 6
mindofcat
in reply to: dgorsman

Thanks, that worked!

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