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
Solved! Go to Solution.
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
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.
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.