User
 Forgot password?
 Register
Search
Post time 2013-7-12 17:24:51
ZWCAD+ COM interface elementary guidance


Operating environments

CAD platform: ZWCAD+
IDE: Visual studio 2010
.NET framework: .NET Framework 4.0
Development language: VB.NET or C# etc.

Create a project and set properties
1. Create a project
Start Visual studio 2010. Go to menu File, and then select File-> New Project. Here you can select Windows Forms Application to produce a stand alone .exe file that allows your application to automate ZWCAD+.

ZWCAD COM API

ZWCAD COM API


2. Add reference
Now, at the Solution Explorer window, double click the project’s name to go to project properties.

ZWCAD COM API

ZWCAD COM API


Select the “References” tab and click on “Add” from the project properties, and select “Browse”. Add reference to ZWCAD.exe at the installation folder of ZWCAD+, like the image below.

ZWCAD COM API

ZWCAD COM API


The result should be like in the following image.

ZWCAD COM API

ZWCAD COM API


We need to import the namespace we want to use. The code inside class1.vb will look like the following code:
Imports ZWCAD

3. Specify the version of framework
Select the “Compile” tab and click on “Advance Compile Options” from the project properties. Specify the version of framework from “Target framework (all configurations)” option at the “Advanced Compiler Settings” window.

ZWCAD COM API

ZWCAD COM API


Sample code

The following example program is launching ZWCAD+ application automatically and then creating a line in the drawing.
Steps:

1. Follow the steps above to create a project and add reference. And then add a button control to the Form1.

2. Copy and paste the bellow codes to the Class1.vb file. Overwrite the original code.

Imports ZWCAD

Public ClassForm1

    Private SubButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click

        Dim myDoc As ZcadDocument

        Dim ss As ZcadApplication

        Dim myspace As ZcadModelSpace

        ss =CreateObject("zwcad+.application")

        myDoc =ss.ActiveDocument

        myspace= myDoc.ModelSpace

       ss.Visible = True

        Dim myline As ZcadLine

        Dim startpoint(2) As Double

       startpoint(0) = 0 : startpoint(1) = 0 : startpoint(2) = 0

        Dimendpoint(2) As Double

       endpoint(0) = 10 : endpoint(1) = 200 : endpoint(2) = 0

        myline= myspace.AddLine(startpoint, endpoint)

       myline.Update()

       ss.ZoomExtents()

    End Sub

End Class


3. Go to menu File, and then select Debug->Start Debugging to debug the project.

ZWCAD COM API

ZWCAD COM API



4. ZWCAD+ application will be launched after clicking the button on the window.


Try ZWCAD+ free for 30 days:
http://www.zwsoft.com/zwcad/ZWCAD_Overview/
New
You have to log in before you can reply Login | Register