CAD software discussion forum > CAD Tutorial & Tips > ZWCAD+ COM interface elementary guidance

ZWCAD+ COM interface elementary guidance

Rank: 5Rank: 5

Viola

posts: 10

Registered: 2013-7-12

Message 1 of 1

 ZWCAD+ COM interface elementary guidance
12-07-2013 05:24 . pm | View his/her posts only
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_01.jpg
2013-7-12 17:27


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_02.jpg
2013-7-12 17:27


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_03.jpg
2013-7-12 17:27


The result should be like in the following image.

ZWCAD COM API

zwcad_COM_API_04.jpg
2013-7-12 17:27


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_05.jpg
2013-7-12 17:27


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_06.jpg
2013-7-12 17:27



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




Try ZWCAD+ free for 30 days:
http://www.zwsoft.com/zwcad+/
See also