.NET

.NET

Reply
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 1 of 6 (293 Views)
Accepted Solution

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

293 Views, 5 Replies
07-18-2013 11:00 AM

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

Thanks, that worked!

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 6 (274 Views)

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

07-18-2013 02:14 PM 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
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 6 (273 Views)

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

07-18-2013 02:23 PM 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
Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 4 of 6 (270 Views)

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

07-18-2013 02:40 PM 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.

*Expert Elite*
dgorsman
Posts: 5,698
Registered: ‎10-12-2006
Message 5 of 6 (265 Views)

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

07-18-2013 02:55 PM 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.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Valued Contributor
mindofcat
Posts: 55
Registered: ‎05-14-2012
Message 6 of 6 (254 Views)

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

07-18-2013 04:52 PM in reply to: dgorsman

Thanks, that worked!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.