Senin, 31 Januari 2011

Knowledge detail

VBA Applications

Q: How can I create a VBA application with ZWCAD?
A: VBA (Visual Basic for Applications) has its own interface environment, and so to work with VBA in ZWCAD, open the VBA environment, as follows: From ZWCAD’s Tools menu, choose Macro and then VisualBasic Editor.
This opens Visual Basic program to display VBA environment window, known as IDE, which is short for “integrated development environment.”
A VBA project is a collection of code modules, classes and forms. A module is a program code segment, like a subroutine in traditional programming languages. A project contains one or more modules. Forms are user interface elements, such as dialog boxes and toolbar. Modules and forms run together to perform given functions.
You add a new modules by selecting Module from the Insert menu in the Visual Basic project window. This opens the module file editor window, in which you can write VBA programming code. The action also adds a new module icon (with the default name of Module1) to the module list in the Project window. 
 Note that ZWCAD continues to run while the VBA environment is open. This allows you to toggle between the VBA IDE and ZWCAD.
The following VBA program draws a donut with an inside diameter of 10 and outside diameter of 15:
 Sub DrawDonut()
       
    Dim CenterPt As New ZwcadPoint
    Dim OutRad As Double
    Dim InRad As Double
   
    CenterPt.x = 10: CenterPt.y = 10: CenterPt.z = 0
   
    OutRad = 15
    InRad = 10
   
    Dim pt1 As New ZwcadPoint
    Dim pt2 As New ZwcadPoint
    Dim pts As New ZwcadPoints
   
    pt1(0) = CenterPt(0) - InRad - Abs(OutRad - InRad) / 2
    pt1(1) = CenterPt(1)
    pt1(2) = 0
    pts.Add pt1(0), pt1(1), pt1(2), 0
   
    pt2(0) = CenterPt(0) + InRad + Abs(OutRad - InRad) / 2
    pt2(1) = CenterPt(1)
    pt2(2) = 0
    pts.Add pt2(0), pt2(1), pt2(2), 1
   
    Dim PolyObj As ZwcadLWPolyline
    Set PolyObj = ThisDocument.ModelSpace.AddLightWeightPolyline(pts)
    PolyObj.Closed = True
   
    For i = 0 To 1
        PolyObj.SetBulge i, 1
        PolyObj.SetWidth i, Abs(OutRad - InRad), Abs(OutRad - InRad)
    Next i
       
    PolyObj.Update
   
    ThisDocument.Regen
   
End Sub

Tidak ada komentar:

Posting Komentar