GstarCAD 2020 .NET Development Guide

Contents

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/4f89f35d85e54a7d72b708d4

Brief Introduction

.NET is the latest application development package introduced by GstarCAD®, which provides a series of Managed Wrapper Class, Object-oriented development environment and API on the basic of .NET. Developers can use the languages which support .NET language, such as VB.NET, C# on GstarCAD application development.

Development Environment

  • Microsoft Visual Studio Enterprise 2017(Version 15.9.17)

  • CPU:

Basic Requirement:1.6 GHz CUP,Recommend:3.0 GHz CPU and above

  • RAM:

Basic Requirement:2 GB,Recommend:8 GB and above

  • Operation System

Windows 10 version 1507 and advanced version:Including home version, professional version, education version and enterprise version(not support LTSC and Windows 10 S)

Windows 8.1(with updated 2919355): Core version, professional version and enterprise version

Windows 7 SP1(with latest Windows updated): Including home version, professional version, enterprise version and Ultimate version

  • Monitor Resolution:

Traditional monitor:1028 x 800 and above CRT monitor, High resolution and 4K (3840 x 2160) monitor

  • GRX SDK 2020

  • GstarCAD 2020

  • .NET Framework 4.8 and above

Install .NET SDK

Download GstarCAD SDK package from our official website: https://www.gstarcad.net/download/

After you get the GRXSDK.ZIP file, please extract it to your disk directory, for instance, C:\grxsdk. Afterwards you will get 6 files, which they are inc,inc-x64,inc-x86,lib-x64,lib-x86 and samples.

  • The Inc file includes header files

  • The inc-x64 file includes the files used in COM and .NET for 64 bit

  • The inc-x86 file includes the files used in COM and .NET for 32 bit

  • The lib-x64 file includes the files referenced from GRX library

  • The lib-x86 file includes the files referenced from GRX library

  • Samples includes project files, they are dotnet,fact_dg,HelloADS,HelloARX,SimplePalette, etc.

The instruction of sample projects:

  • Dotnet includes multiple dotnet samples,including addline,hello,vbhello, etc.
  1. Addline includes .NET example for adding solid line.

  2. Hello includes .NET example for prompting the information of output.

  3. Vbhello includes VB.NET example for how to develop with .NET API.

  • fact_dg includes example for defining LSP function.

  • HelloADS includes the project for how to develop the type of ADS.

  • HelloARX includes includes the example for how to develop with ARX API.

  • SimplePalette includes the example for how to develop the type modules for palette.

VS2017 C# .NET Development Sample

The following takes the creation of the "Hello" project as an example to illustrate the creation process. And assumes that the GstarCAD SDK is installed in the “c:\grxsdk”directory.

Create .Net Project

Run Microsoft Visual Studio 2017

Please click [File] → [New] → [Project]. After clicked the menu Project, the New Project dialog box will pops out. Then select Visual C# in the catalogue Installed Templates and click [Class Library (.Net Framework)].

Input Project Saved Path and Project Name

Type "Hello" at the name label in "New Project" dialog box and choose .NET Framework4.8, as shown below:

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/eac286580ff331e2b7c8822f

Remark:Please choose .NET Framework 4.8 at the frame pull-down list.

Finish to Create a New Project

After finished operation above, click OK button in the dialog to finish the new project creating.

Set the Reference Library

Add Reference

In VS 2017, find the Hello project you have been created on the solution explorer. Select the Hello project and right click to select Add Reference. After the "Reference Manager" dialog box pops out, click Browse button as shown below.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/e2af9cc67c4d5d12ef73c173 Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/4b8274690bd922dd14a764ce

Choose and Add Reference Files

Find the GstarCADSDK installation path, for example, “C:\grxsdk\inc”. Select gmap.dll and gmdb.dll files in “c:\grxsdk\inc-x86” and add them by clicking Add button(If you use GstarCAD 64-bit version, please select GrxCAD.Interop.dll in inc-x64).

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/ebb3fc8c4e444c74d8826a5a Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/97f5959c4a8298b4858c6df3

Remark:gmap.dll and gmdb.dll have to be added but file GrxCAD.Interop.dll is optional.

After adding the files, right click each added reference file, click Property at the context menu, then the "Reference Properties" palette pops up, change the "Copy Local" property from True to False. The following image shows how to change "Copy Local" property for gmap.dll file. Please take it as reference to change gmdb.dll file's Copy Local property.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/50b2177b8a4705a6fb41adf7 Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/7ef055b60d6b015ffcf55652
  • gmap.dll file includes the following name space:
Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/1c5c2c62606c89ad92825fdd
  • gmdb.dll file includes the following name space:
Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/be51ba4f77a257fffab21096
  • GrxCAD.Interop.dll files shows the com corresponding .NET interface.

Add Codes

Using the code below to replace the existing code in Class1.cs file in Hello project.

using System;

using GrxCAD.Runtime;
using GrxCAD.ApplicationServices;

[assembly: CommandClass(typeof(hello.HelloCmd))]

namespace hello
{
    public class HelloCmd
    {
        [CommandMethod("Hello")]
        static public void DoIt()
        {

            try
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello dotnet");
            }
            catch (System.Exception ex)
            {
                String str = ex.ToString();
            }
        }
    }
}
Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/becaff7109cb46eb2c6e93a8

Compile Program

Click Visual Studio 2017 menu item [Build] » [Build solution], then you will get a “Hello.dll” file from D:\test\Hello\Hello\bin\Release directory.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/9cded5a2ec8617a31292ccb6

Run Program

Run GstarCAD and input "netload" at command line, there will a "Select .Net Assembly" dialog box pops out, select the "Hello.dll" file and click Open button to load it.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/35c2ba220615da7b03aa6171 Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/dc87ccb292aac39944aa7a9c

Input "hello" command at command line, “Hello dotnet” will display in the command line.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/f4c6c256fd92f137d68a0aab Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/3a66e614473d84e75a270606

VS2017 VB .NET Development Sample

The following takes the creation of the "Hello" project as an example to illustrate the creation process. And assumes that the GstarCAD SDK is installed in the “c:\grxsdk” directory.

Create a .NET Project

Run Microsoft Visual Studio 2017 (2)

Please click [File] → [New] → [Project]. After clicked the menu Project, the New Project dialog box will pops out. Then select Visual C# in the catalogue Installed Templates and click [Class Library (.Net Framework)].

Input Project Saved Path and Project Name (2)

Type "Hello" at the name label in "New Project" dialog box and choose .NET Framework4.8, as shown below:

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/059dcae0ed5c849437214239

Remark:Please choose .NET Framework 4.8 at the frame pull-down list.

Finish to Create a New Project (2)

After finished operation above, click OK button in the dialog to finish the new project creating.

Set the Reference Library (2)

Add Reference (2)

In VS 2017, find the Hello project you have been created on the solution explorer. Select the Hello project and right click to select Add Reference. After the "Reference Manager" dialog box pops out, click Browse button as shown below.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/9f817454365ef1e6f1c92fd1 Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/84d3a778c0cd04bc70e2137b

Choose and Add Reference Files (2)

Find the GstarCADSDK installation path, for example, “C:\grxsdk\inc”. Select gmap.dll and gmdb.dll files in “c:\grxsdk\inc-x86” and add them by clicking Add button (If you use GstarCAD 64-bit version, please select GrxCAD.Interop.dll in inc-x64).

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/ebb3fc8c4e444c74d8826a5a Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/800008dd9ae77f30360588d3

Remark: gmap.dll and gmdb.dll have to be added but file GrxCAD.Interop.dll is optional.

After adding the files, right click each added reference file, click Property at the context menu, then the "Reference Properties" palette pops up, change the "Copy Local" property from True to False. The following image shows how to change "Copy Local" property for gmap.dll file. Please take it as reference to change gmdb.dll file's Copy Local property.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/14868ba54383847ec7b9f18d Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/32fbc44b20dfce02bba30897
  • gmap.dll includes the following name space::
Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/1c5c2c62606c89ad92825fdd
  • gmdb.dll includes the following name space:
Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/be51ba4f77a257fffab21096
  • GrxCAD.Interop.dll shows the com corresponding .NET interface.

Add Codes (2)

Using the code below to replace the existing code in Class1.vb file in Hello project.


Imports System
Imports GrxCAD

Imports GrxCAD.Runtime

Imports GrxCAD.DatabaseServices
Imports GrxCAD.Geometry

Imports GrxCAD.ApplicationServices
Imports GrxCAD.EditorInput

' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(GRXTest.MyCommands))>

Namespace GRXTest
Public Class MyCommands

<CommandMethod("vbhello", CommandFlags.Modal)> _
Public Sub RunMRLCommand() ' This method can have any name
Dim doc As GrxCAD.ApplicationServices.Document
doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
doc.Editor.WriteMessage("hello vb.NET")
End Sub

End Class
End Namespace

Compile Program (2)

Click Visual Studio 2017 menu item [Build] » [Build solution], then you will get a “Hello.dll” file from D:\test\Hello\Hello\bin\Release directory.

Run Program (2)

Run GstarCAD and input "netload" at command line, there will a "Select .Net Assembly" dialog box pops out, select the "Hello.dll" file and click Open button to load it.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/35c2ba220615da7b03aa6171 Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/dc87ccb292aac39944aa7a9c

Then run GstarCAD, input "vbhello" command at command line, “hello vb.NET” will show in the command line.

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/59da8b742eec34996727ef6f

图5.9

Literature/GSTARCAD/2020/03 API Guides/NET/assets/NET Development Guide assets/5d1fe45a33422db0ac7e79f0

DotNet Development Special Usage

Some differences between GstarCAD DotNet and AutoCAD DotNet:

Using

Code like “var mapping = new IdMapping()” need to add “using” function first.

For example “var mapping = new IdMapping()” in GstarCAD should be:

using( var mapping = new IdMapping())
{
	...
}

ResultBuffer

Use ResultBuffer.ResbufObject to replace ResultBuffer.UnmanagedObject;

ResultBuffer.UnmanagedObject is the type of OdDbResbuf;

ResultBuffer.ResbufObject is the type of resbuf;

Use ResultBuffer.Create(IntPtr,bool) to replace ResultBuffer(IntPtr,bool)

Alternative method to import Unmanaged ARX Function

The alternative method to import unmanaged arx function acedCmd,acedCommand:

Use GrxCAD.EditorInput.Editor.Command(params object[]) to replace original functions.

Alternative Method

Autodesk.AutoCAD.EditorInput.Editor.TraceBoundary(Autodesk.AutoCAD.Geometry.Point3d, bool) alternatvie method:

GrxCAD.EditorInput.Editor.

If TraceBoundary(Autodesk.AutoCAD.Geometry.Point3d, bool) has not been provided,you can use the following method to replace.

[CommandMethod("TESTCMD")]
public void TestCommand()
{
    var db = Application.DocumentManager.MdiActiveDocument.Database;
    var ed = Application.DocumentManager.MdiActiveDocument.Editor;
    //new a DBObjectCollection for boundary set
    DBObjectCollection objColl = new DBObjectCollection();
    using (var tr = db.TransactionManager.StartTransaction())
    {
	var curSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
	var drawOrderTable = tr.GetObject(curSpace.DrawOrderTableId, OpenMode.ForRead) as DrawOrderTable;
	ObjectIdCollection coll = drawOrderTable.GetFullDrawOrder(0);
	ObjectId entLast =  coll[coll.Count-1];
	//use "Y" or "N" whether or not to detect islands
	//instead of "0,0" when using another seed point
	ed.Command("-BOUNDARY", "A", "I", "Y", "", "0,0", "");
	coll = drawOrderTable.GetFullDrawOrder(0);
	int nIndex = coll.IndexOf(entLast);
	for (int i = nIndex; i >= 0; --i)
	{
	    coll.RemoveAt(i);
	}
	//clone the boundaries created by -BOUNDARY command to DBObjectCollection
	foreach (ObjectId id in coll)
	{
	    DBObject obj = tr.GetObject(id, OpenMode.ForRead) as DBObject;
	    DBObject tmp = (DBObject)obj.Clone();
	    objColl.Add(tmp);
	}
	//abort the transaction to avoid the boundaries created by -BOUNDARY command posting to db
	tr.Abort();
    }
    //this is a test code to post the cloned boundaries to current space
    using (var tr = db.TransactionManager.StartTransaction())
    {
	var curSpace = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
	foreach (DBObject obj in objColl)
	{
	    curSpace.AppendEntity((Entity)obj);
	    tr.AddNewlyCreatedDBObject(obj, true);
	}
	tr.Commit();
    }
    //dispose the DBObjectCollection after used it,and dispose the item in it if necessary,here we do
    //not dispose the DBOjbect in DBObjectCollection because we post it to current space before
    objColl.Dispose();
}

C# .NET and VB .NET Name Space Modification

  • VB.NET:

The content after Imports,change Autodesk.AutoCAD to GrxCAD

  • C#.NET:

The content after using,change Autodesk.AutoCAD to GrxCAD

  • If use COM:

With VB.net, add Imports GcadVbaLib

With C#.net, add using GcadVbaLib

Delete Autodesk.AutoCAD.Interop.Common

For the COM object name in the code, such as AcadLWPolyline, please change the prefix Acad to Gcad, for example AcadLWPolyline should be change to GcadLWPolyline.

If some codes not sure, you can check from the object browser. For example ACAD_COLOR, you can check from the browser whether there is GCAD_COLOR, if there is, just replace it.

Copyright reserved: Xi’an Gstarsoft Co.,Ltd

Usage License: Allows copying, quote any part of this document. Changes of any part of this document are forbidden without authorization. Please keep this statement when copying and quoting it, otherwise it will be held liable.

  • AutoCAD® is a product of Autodesk® Company which is one of the CAD software solution providers. ARX is an abbreviated name of ObjectARX, which is AutoCAD® Runtime eXtension, and C++ SDK provided by Autodesk®.

PDF page 3 — additional source text

6.4. 
Alternative Method ................................................................ 20

PDF page 3 — additional source text

6.5. 
C# .NET and VB .NET Name Space Modification ................. 22

PDF page 3 — additional source text

7. 
Copyright ........................................................................................ 23

PDF page 11 — additional source text

11

PDF page 12 — additional source text

12

PDF page 13 — additional source text

13

PDF page 14 — additional source text

14

PDF page 18 — additional source text

18

PDF page 22 — additional source text

22

PDF page 23 — additional source text

23