CAD/CAM discussion forum > CAD Tutorial & Tips > ZWCAD+ .NET elementary guidance

ZWCAD+ .NET elementary guidance

  Subscribe Topic

Rank: 5Rank: 5


posts: 10

Registered: 2013-7-12

Message 1 of 2

 ZWCAD+ .NET elementary guidance
12-07-2013 05:49 . pm   |   View his/her posts only
ZWCAD+ .NET elementary guidance
Operating environments
CAD platform: ZWCAD+ 2012 SP2
IDE: Visual studio 2010
.NET framework: .NET Framework 4.0
.NET library files: ZwManaged.dll and ZwDatabaseMgd.dll
Development language: VB.NET or C# etc.

The official version of ZWCAD+ 2012 does not support the .NET interface. It will be officially supported in the next version, but we can use ZWCAD+ 2012 SP2 version to test the .NET interface. After installing ZWCAD+ 2012 SP2, copy and paste ZwManaged.dll and ZwDatabaseMgd.dll to the installation folder.

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 two kinds of projects: Windows Forms Application or Class Library. The first type will produce a stand alone .exe file that allows your application to automate ZWCAD+. The second type will produce a .dll file that you can load inside ZWCAD+ and register new commands.

ZWCAD dot net elementary

2013-7-12 17:44

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

ZWCAD dot net elementary

2013-7-12 17:44

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

ZWCAD dot net elementary

2013-7-12 17:44

The result should be like in the following image.

ZWCAD dot net elementary

2013-7-12 17:44

Additionally, as we will use some COM features with our project, add reference to ZWCAD.exe in the same folder. The final result should be like in the following image.

ZWCAD dot net elementary

2013-7-12 17:44

In .NET 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 dot net elementary

2013-7-12 17:44

4. Debug Setting
Select the “Debug” tab and specify ZWCAD.exe as the Start external program from the project properties.

ZWCAD dot net elementary

2013-7-12 17:44

Run the DLL file

After building a project, a dll file named as project’s name will be generated in the path of …\bin\Release\. Start ZWCAD+ and run NETLOAD command to load the DLL file. And then you can run commands which are registered in the code.

Sample code
The following example program is executing the AddCircle command in the command line, will create a red circle with radius of 10 in the drawing and center of the circle is (2, 3, 0).

1. Follow the steps above to create a project and add reference. And then copy and paste the bellow codes to the Class1.vb file. Overwrite the original code.


Imports ZwSoft.ZwCAD.Runtime

Imports ZwSoft.ZwCAD.DatabaseServices

Imports ZwSoft.ZwCAD.Geometry

Namespace TEST

Public ClassSHMain


Public SubAddCircle()

DimzcDoc As Document = Application.DocumentManager.MdiActiveDocument

DimzcDB As Database = zcDoc.Database

UsingzcTran As Transaction = zcDB.TransactionManager.StartTransaction

DimzcBLT As BlockTable

zcBLT = zcTran.GetObject(zcDB.BlockTableId, OpenMode.ForRead)

DimzcBLTR As BlockTableRecord

zcBLTR = zcTran.GetObject(zcBLT(BlockTableRecord.ModelSpace),OpenMode.ForWrite)

DimzcCircle As Circle = New Circle

zcCircle.Center = New Point3d(2, 3, 0)

zcCircle.Radius = 10

zcCircle.ColorIndex = 1





End Sub

End Class

End Namespace

2. Go to menu File, and then select Build->Build ClassLibrary1 (the ClassLibrary1 is project’s name) to build the project.

ZWCAD dot net elementary

2013-7-12 17:44

After building the program, the result will be shown in the Output window as shown below.

ZWCAD dot net elementary

2013-7-12 17:44

3. Start ZWCAD+ by manual or select Debug->Start Debugging to launch ZWCAD+ automatically.

4. Run NETLOAD command and load the DLL file.

5. After loading the DLL file, run the AddCircle command and a red circle will be created in the drawing.

Try ZWCAD+ free for 30 days:

Here are some posts about ZWCAD+ .NET that might be useful for you:
ZWCAD+ dot NET migration manual, use your autocad dot net application in ZWCAD+
ZWCAD+ .net tutorials and sample codes summary

Rank: 1



posts: 4

Registered: 2013-9-7

Message 2 of 2

08-09-2013 05:27 . am   |   View his/her posts only
Post Last Edit by ruselgun4821 at 2013-9-8 05:31

How do we get or edit dynamicblock properties.
Neither DynamicBlockReferencePropertyCollection or GetDynamicBlockProperties can not be found in the object model.

ZWCAD+ 2014 Beta2
See also