GstarCAD 2023 .NET Programming Guide

Contents

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/b55c2095fb6964470e9e3560

1. Introduction

GstarCAD .NET API 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# to develop application on GstarCAD.

2. Programming Environment

  • Microsoft® Visual Studio Enterprise 2017 (Version 15.9.17)

  • Windows SDK 10.0.17763.0

  • CPU:

Basic: 1.6 GHz CUP

Recommended: 3.0 GHz CPU and above

  • RAM:

Basic: 2 GB

Recommended: 8 GB and above

  • Operation System (OS)

Windows 11

Windows 10 (version 1507 and above):

Home, Professional, Education and Enterprise (not support LTSC and Windows 10 S)

Windows 8.1 (with 2919355 update):

Core, Professional and Enterprise

Windows 7 SP1 (with the latest update):

Home, Professional, Enterprise and Ultimate

  • Monitor Resolution:

1028x800 and above true color display, including 4K (3840x2160) display

  • GstarCAD SDK 2023

  • GstarCAD 2023

  • .NET Framework 4.8 and above

3. Install GstarCAD SDK

Download GstarCAD SDK (' GRXSDK.ZIP ' file) from GstarCAD website:

https://www.gstarcad.net/download/

Unzip GRXSDK.ZIP file to the local disk (e.g. 'C:\grxsdk' ) and there will be 5 directories generated (in 'C:\grxsdk' ) which are: arx , inc , inc-x64 , lib-x64 and utils .

arx contains the header files, library files and sample programs used for porting ARX programs to GRX

programs. It contains the following directories:

  • Inc: Header files used for porting from ARX to GRX

  • inc-x64 : Files used by COM and .NET (for 64-bit)

  • lib-x64 : GRX libraries (for 64-bit)

  • Samples : Sample projects, including Dotnet, fact_dg, HelloADS, HelloA and SimplePalette.

  • Dotnet : .NET programming samples

    1. Addline : .NET programming sample of adding solid lines
    1. Hello : .NET programming sample of outputting prompt information
    1. Vbhello : Sample of .NET programming with VB .NET
  • fact_dg : Sample of LISP function definition

  • HelloADS : Sample of ADS programming

  • HelloARX : Sample of GRX programming

  • SimplePalette : Programming sample of how to create a set Palette windows

  • Utils : Directory contains sub-directories of GRX extended applications, including APIs for extended

function development, e.g. BREP for boundary representation.

  • inc-x64 : Files used by COM and .NET (for 64-bit)

  • lib-x64 : GRX libraries (for 64-bit)

  • Utils : Directory contains subdirectories of GRX extended applications, including APIs for extended

function development, e.g. BREP for boundary representation.

4. Visual Studio 2017 C# .NET Programming Sample

The following is an example of how to create a project called ' Hello ', assuming that the GstarCAD SDK is installed in the ' C:\grxsdk '.

4.1. Create .NET Project

4.1.1. Run Microsoft® Visual Studio 2017

Click File → New → Project to launch the New Project dialog window. Select Visual C# in the Installed on the left side and click Class Library (.NET Framework) in the middle window.

4.1.2. Input Project Save Path and Project Name

Input 'Hello' at the Name field in the New Project dialog window and choose .NET Framework 4.8 at the Framework field, as shown below:

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/440b022392693c72ec49b8b1

4.1.3. Finish Creating New Project

Click OK button to finish creating the new project ' Hello '.

4.2. Set Reference Library

4.2.1. Add Reference

In Visual Studio 2017, find the ' Hello ' project in the Solution Explorer , right-click on it and select Add → Reference .

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/456a7f9ffdc555deb150097e

After the Reference Manager dialog window pops out, click Browse as shown below.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/8227164c64d4d25d4d1e469d

4.2.2. Choose and Add Reference File

From the GstarCAD SDK installation directory, e.g. ' C:\grxsdk ', select ' gmap.dll ' and ' gmdb.dll ' in ' \arx\inc ' and 'GrxCAD.Interop.dll '(or ' acax.tlb ') in ' \arx\inc-x64 ', and add them by clicking Add button.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/98b8075a10f0120854f81c87 Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/133cd1a50e210b3b12aefab7 Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/3491fb560ce3ec9a98133108
NOTE

' gmap.dll ' and ' gmdb.dll ' must be added while 'GrxCAD.Interop.dll ' (or ' acax.tlb ') is optional (needed when COM is used in the program).

After adding the files, right-click added ' gmap.dll ' and ' gmdb.dll ' files one by one and select Properties at the context menu, the Reference Properties palette pops up. Set the value of Copy Local property to False . The following screenshot shows how to change Copy Local property of ' gmap.dll '.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/87fefed8a8b07ee04cea8c2b Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/f15f4f6e4a66cac840c21a1f
  • ' gmap.dll ' includes the following namespaces:
Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/13d060cec24eb5aac2767888
  • ' gmdb.dll ' includes the following namespaces:
Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/fa20836f6b6a6fe1a3e0a17b
  • ' GrxCAD.Interop.dll ' shows the corresponding .NET APIs of COM.

4.3. Add Code

Add the following codes to 'Class1.cs':

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/2023/03 API Guides/assets/NET Programming Guide assets/eb781736f467125b3d28671c

4.4. Compile Program

In Visual Studio 2017, click Build → Build Solution to generate 'Hello.dll ' file.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/6281940713f12ca468f99684

4.5. Run Program

Run GstarCAD and input ' netload ' at command line to launch Select .Net Assembly dialog window, select the 'Hello.dll ' and click Open button to load it.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/e8885fb6b9941bc0444c1e90 Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/392025c073132a83d5dfccb4

Input 'hello ' at command line, there will be a message 'Hello dotnet ' displayed in the command line.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/5403b0922f6033eccbc1b9c3

5. Visual Studio 2017 VB .NET Programming Sample

The following is an example of how to create a project called ' Hello ', assuming that the GstarCAD SDK is installed in the ' C:\grxsdk '.

5.1. Create .NET Project

5.1.1. Run Microsoft® Visual Studio 2017

Click File → New → Project to launch the New Project dialog window. Select Visual Basic in the Installed on the left side and click Class Library (.NET Framework) in the middle window.

5.1.2. Input Project Save Path and Project Name

Input 'Hello' at the Name field in the New Project dialog window and choose .NET Framework 4.8 at the Framework field, as shown below:

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/4f60fd35e998d5d19b498fd9

5.1.3. Finish Creating New Project

Click OK button to finish creating the new project ' Hello '.

5.2. Set Reference Library

5.2.1. Add Reference

In Visual Studio 2017, find the ' Hello ' project in the Solution Explorer , right-click on it and select

Add → Reference .

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/769a15fd3e06de5d435fb385

After the Reference Manager dialog window pops out, click Browse as shown below.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/74e90579e8cd0b2e7453bb92

5.2.2. Choose and Add Reference File

From the GstarCAD SDK installation directory, e.g. ' C:\grxsdk ', select ' gmap.dll ' and ' gmdb.dll ' in ' \arx\inc ' and

'GrxCAD.Interop.dll ' (or ' acax.tlb ') in ' \arx\inc-x64 ', and add them by clicking Add button.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/3240e1908f3d6aeed9aa4cf3 Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/15f4bb8479b01a1410ce26af Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/1a3db91dc1e0b4d7c1093af0
NOTE

' gmap.dll' and ' gmdb.dll ' must be added while 'GrxCAD.Interop.dll ' (or ' acax.tlb ') is optional (needed when COM is used in the program).

After adding the files, right-click added ' gmap.dll ' and ' gmdb.dll ' files one by one and select Properties at the context menu, the Reference Properties palette pops up. Set the value of Copy Local property to False . The following screenshot shows how to change Copy Local property of ' gmap.dll '.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/bba9123981b4bdc9b1e7af24 Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/378d3b0b515b92fa44bed4ab
  • ' gmap.dll ' includes the following namespaces:
Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/a1f3a2213533a2a5847e4302
  • ' gmdb.dll ' includes the following namespaces:
Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/8866f3223b10a8bc85f26342
  • ' GrxCAD.Interop.dll ' shows the corresponding .NET APIs of COM.

5.3. Add Code

Add the following codes in 'Class1.vb':

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

5.4. Compile Program

In Visual Studio 2017, click Build → Build Solution to generate 'Hello.dll ' file.

5.5. Run Program

Run GstarCAD and input ' netload ' at command line to launch Select .Net Assembly dialog window, select the

'Hello.dll ' and click Open button to load it.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/9ed7f044f03090999fbebd02 Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/f4f27090e4c3a38bb94760a5

Input 'vbhello ' at command line, there will be a message 'hello vb.NET ' displayed in the command line.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/82bdb814f2b0e51116c831cb

6. Special Usage of GstarCAD .NET Programming

The following describes the differences between GstarCAD .NET programming and AutoCAD® .NET

programming:

6.1. How to Use 'using'

Codes like 'var mapping = new IdMapping()' need to add 'using' function first, e.g.:

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

6.2. How to Use 'ResultBuffer'

Use 'ResultBuffer.ResbufObject' to replace 'ResultBuffer.UnmanagedObject';

Type of ResultBuffer.UnmanagedObject is OdDbResbuf;

Type of ResultBuffer.ResbufObject is resbuf;

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

6.3. Alternative Method of Importing Unmanaged ARX Function

Use 'GrxCAD.EditorInput.Editor.Command(params object[])' to replace the unmanaged ARX functions acedCmd

and acedCommand.

6.4. C# .NET and VB .NET Namespace Modification

  • VB .NET:

Change 'Autodesk.AutoCAD' to 'GrxCAD' after the 'Imports'

C# .NET: -

Change 'Autodesk.AutoCAD' to 'GrxCAD' after the 'using'

COM With VB .NET: -

Add 'Imports GcadVbaLib' and delete 'Autodesk.AutoCAD.Interop.Common'

  • COM With C# .NET:

Add 'using GcadVbaLib' and delete 'Autodesk.AutoCAD.Interop.Common'

For the COM object name in the codes, such as AcadLWPolyline, it is needed to change the prefix 'Acad' to

' Gcad' , e.g. 'AcadLWPolyline ' should be change to 'GcadLWPolyline '.

If it's not sure a COM object exists or not, then first check it from the object browser, e.g. for ACAD_COLOR , check whether there is corresponding GCAD_COLOR first from the browser. Then change ' ACAD_COLOR' to ' GCAD_COLOR' if GCAD_COLOR is found.

Copyright reserved: Gstarsoft Co.,Ltd

Copying and referencing any part of this document is allowed. No part of this document may be changed without permission. Please keep this statement when copying or referencing this document.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Programming Guide assets/1ba16e1e3f793409e648706e