Translate

segunda-feira, 18 de setembro de 2023

Manual VB.net para ZWCAD : NEW LAYER

 Criação de uma nova "Layer"

Temos então o código:

Imports ZwSoft.ZwCAD.ApplicationServices
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.EditorInput
Imports ZwSoft.ZwCAD.Colors

Public Class LayersNew

    <CommandMethod("NewLayer")> _ 
    Public Sub NewLayer()

        Dim ZWDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ZWEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim ZWCurDb As Database = ZWDoc.Database

        Using ZWTrans As Transaction = ZWCurDb.TransactionManager.StartTransaction()

            Dim ZWBlkTblRec As BlockTableRecord = ZWTrans.GetObject(ZWCurDb.CurrentSpaceId, OpenMode.ForWrite)
            Dim ZWLayerTable As LayerTable = ZWTrans.GetObject(ZWCurDb.LayerTableId, OpenMode.ForRead)

            Dim ZWNewLayer As String = "ZWCad_1"

            If ZWLayerTable.Has(ZWNewLayer) = False Then
                Dim ZWZWNewLayer_1 As New LayerTableRecord
                ZWZWNewLayer_1.Name = ZWNewLayer
                ZWZWNewLayer_1.Color = Color.FromColorIndex(ColorMethod.ByAci, 1)
                ZWZWNewLayer_1.LineWeight = LineWeight.LineWeight009
                ZWLayerTable.UpgradeOpen()
                ZWLayerTable.Add(ZWZWNewLayer_1)
                ZWTrans.AddNewlyCreatedDBObject(ZWZWNewLayer_1, True)
            End If

            ZWTrans.Commit()
        End Using
    End Sub
End Class


Após escrever o código, deve-se criar o dll. No  ZWCad, na linha de comando: netload carregar o dll criado. na linha de comando chamamos então o comando criado neste caso: NewLayer.

Vamos lá experimentar.
Cumprimentos. 

Sem comentários:

Enviar um comentário