Translate

quinta-feira, 7 de setembro de 2023

Manual VB.net para ZWCAD : HATCH

 Criação do Hatch "solid"



Temos então o código:

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

Public Class HatchRec
    <CommandMethod("NewHatch")> _ 
    Public Sub NewHatch()

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

        Dim Largura As Double = ZWEd.GetDouble(vbCr & "Qual a Largura do retangulo ?").Value
        Dim Altura As Double = ZWEd.GetDouble(vbCr & "Qual a Altura do retangulo ?").Value

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

            Dim ZWBlkTbl As BlockTable = ZWTrans.GetObject(ZWCurDb.BlockTableId, OpenMode.ForRead)
            Dim ZWBlkTblRec As BlockTableRecord = ZWTrans.GetObject(ZWBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

            Dim ZWPoly As New Polyline()
            ZWPoly.SetDatabaseDefaults()
            ZWPoly.AddVertexAt(0, New Point2d(0, 0), 0, 0, 0)
            ZWPoly.AddVertexAt(1, New Point2d(Largura, 0), 0, 0, 0)
            ZWPoly.AddVertexAt(2, New Point2d(Largura, Altura), 0, 0, 0)
            ZWPoly.AddVertexAt(3, New Point2d(0, Altura), 0, 0, 0)

            ZWPoly.Closed = True

            ZWBlkTblRec.AppendEntity(ZWPoly)
            ZWTrans.AddNewlyCreatedDBObject(ZWPoly, True)

            Dim dot As DrawOrderTable = CType(ZWTrans.GetObject(ZWBlkTblRec.DrawOrderTableId, OpenMode.ForWrite), DrawOrderTable)

            Dim ZWHatchSet As New Hatch()
            ZWHatchSet.SetDatabaseDefaults()
            ZWHatchSet.SetHatchPattern(HatchPatternType.PreDefined, "Solid")
            Dim ZWHatchRect As ObjectId = ZWBlkTblRec.AppendEntity(ZWHatchSet)
            ZWTrans.AddNewlyCreatedDBObject(ZWHatchSet, True)
            Dim idsZWHatchRect As New ObjectIdCollection()
            idsZWHatchRect.Add(ZWPoly.ObjectId)
            dot.MoveToBottom(idsZWHatchRect)
            ZWHatchSet.Associative = True
            ZWHatchSet.Layer = "0"
            ZWHatchSet.Color = Color.FromColorIndex(ColorMethod.ByAci, 253)
            ZWHatchSet.AppendLoop(HatchLoopTypes.Outermost, idsZWHatchRect)
            ZWHatchSet.EvaluateHatch(True)
            ZWBlkTblRec.DowngradeOpen()
            idsZWHatchRect.Add(ZWHatchRect)

            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: NewHatch.

Vamos lá experimentar.
Cumprimentos. 

Sem comentários:

Enviar um comentário