GstarCAD 2024 .NET Programming Guide

Contents

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/61a817742322af510a3ae5dc
6.4.Method of Selecting in Current Drawing after Clicking Button in Modal Dialog Box … 23
6.5.C# .NET and VB .NET Namespace Modification … 24
7.
Copy
right … 25

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 2024

  • GstarCAD 2024

  • .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: Header files used for programming the GRX

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

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

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/5c1af5eae0db25ef7ceb7d1f

4.2.2. Choose and Add Reference File

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

button.

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/0de25a138125c186415e2430 Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/d2b31b1235ac472f9a9fa8da Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/4a2d7b4e51f9571e3f100932
NOTE

' GcCoreMgd.dll', 'GcDbMgd.dll' and 'GcMgd.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 ' GcCoreMgd.dll', 'GcDbMgd.dll' and 'GcMgd.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 ' GcCoreMgd.dll '.

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/4bcfc0fc7e4b782455c03d98 Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/670b7584f73aa1d7ea79f410

 ' GcCoreMgd.dll ' includes the following namespaces: Gssoft.Gscad.ApplicationServices Gssoft.Gscad.ApplicationServices.Core Gssoft.Gscad.EditorInput Gssoft.Gscad.GraphicsSystem Gssoft.Gscad.Internal Gssoft.Gscad.PlottingServices Gssoft.Gscad.Publishing Gssoft.Gscad.Runtime Gssoft.Gscad.Windows

 ' GcDbMgd.dll ' includes the following namespaces: Gssoft.Gscad Gssoft.Gscad.Colors Gssoft.Gscad.ComponentModel Gssoft.Gscad.DatabaseServices Gssoft.Gscad.DatabaseServices.Filters Gssoft.Gscad.DatabaseServices.Internal Gssoft.Gscad.Geometry Gssoft.Gscad.GraphicsInterface Gssoft.Gscad.GraphicsSystem Gssoft.Gscad.Internal Gssoft.Gscad.LayerManager Gssoft.Gscad.Runtime

'GcMgd.dll' includes the following namespaces: Gssoft.Gscad.ApplicationServices Gssoft.Gscad.EditorInput Gssoft.Gscad.Internal Gssoft.Gscad.Internal.Calculator Gssoft.Gscad.Internal.DatabaseServices Gssoft.Gscad.Internal.Forms Gssoft.Gscad.Internal.PreviousInput Gssoft.Gscad.Internal.PropertyInspector Gssoft.Gscad.Internal.Reactors Gssoft.Gscad.Internal.Render.RapidRT Gssoft.Gscad.Internal.Windows Gssoft.Gscad.Windows Gssoft.Gscad.Windows.Data Gssoft.Gscad.Windows.Data.Render.RapidRT Gssoft.Gscad.Windows.ToolPalette

  • 'GrxCAD.Interop.dll' shows the corresponding .NET APIs of COM.

4.3. Add Code

Add the following codes to 'Class1.cs':

using System;

using Gssoft.Gscad.Runtime;
using Gssoft.Gscad.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/2024/03 API Guides/assets/NET Programming Guide assets/b9a1acaf75cd2bf6c5b0c1ea

4.4. Compile Program

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

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/56a76407356b5d3ae414bb96

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/2024/03 API Guides/assets/NET Programming Guide assets/83d578896ee1cf6fb31a9931 Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/36fa8fa4bce860d606cd82f0

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

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/87bdc0489085b9b197b96dc9

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 'vbHello' 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/2024/03 API Guides/assets/NET Programming Guide assets/e68a80326278aa319f9f56b8

5.1.3. Finish Creating New Project

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

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

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

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/35924dd1ac6602b5813e3777

5.2.2. Choose and Add Reference File

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

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/60dfff036889a8eab0b07043 Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/728f77a4b730e51cdde000ea Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/9b573eac8818c119016bbf5f
NOTE

' GcCoreMgd.dll', 'GcDbMgd.dll' and ' GcMgd.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 ' GcCoreMgd.dll', 'GcDbMgd.dll' and ' GcMgd.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 ' GcCoreMgd.dll '.

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/663153fcb345315a1e940e3a Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/07c83ab2cad206db7d3c2552

 ' GcCoreMgd.dll ' includes the following namespaces: Gssoft.Gscad.ApplicationServices Gssoft.Gscad.ApplicationServices.Core Gssoft.Gscad.EditorInput Gssoft.Gscad.GraphicsSystem Gssoft.Gscad.Internal Gssoft.Gscad.PlottingServices Gssoft.Gscad.Publishing Gssoft.Gscad.Runtime Gssoft.Gscad.Windows

 ' GcDbMgd.dll ' includes the following namespaces: Gssoft.Gscad Gssoft.Gscad.Colors Gssoft.Gscad.ComponentModel Gssoft.Gscad.DatabaseServices Gssoft.Gscad.DatabaseServices.Filters Gssoft.Gscad.DatabaseServices.Internal Gssoft.Gscad.Geometry Gssoft.Gscad.GraphicsInterface Gssoft.Gscad.GraphicsSystem Gssoft.Gscad.Internal Gssoft.Gscad.LayerManager Gssoft.Gscad.Runtime

'GcMgd.dll' includes the following namespaces: Gssoft.Gscad.ApplicationServices Gssoft.Gscad.EditorInput Gssoft.Gscad.Internal Gssoft.Gscad.Internal.Calculator Gssoft.Gscad.Internal.DatabaseServices Gssoft.Gscad.Internal.Forms Gssoft.Gscad.Internal.PreviousInput Gssoft.Gscad.Internal.PropertyInspector Gssoft.Gscad.Internal.Reactors Gssoft.Gscad.Internal.Render.RapidRT Gssoft.Gscad.Internal.Windows Gssoft.Gscad.Windows Gssoft.Gscad.Windows.Data Gssoft.Gscad.Windows.Data.Render.RapidRT Gssoft.Gscad.Windows.ToolPalette

  • 'GrxCAD.Interop.dll' shows the corresponding .NET APIs of COM.

5.3. Add Code

Add the following codes in 'Class1.vb':

Imports System
Imports Gssoft.Gscad

Imports Gssoft.Gscad.Runtime

Imports Gssoft.Gscad.DatabaseServices
Imports Gssoft.Gscad.Geometry

Imports Gssoft.Gscad.ApplicationServices
Imports Gssoft.Gscad.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 Gssoft.Gscad.ApplicationServices.Document
Doc = Gssoft.Gscad.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 'vbHello.dll ' file.

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/14d190a98abcb3dcd1876937

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/2024/03 API Guides/assets/NET Programming Guide assets/1e546e60872111fe2130bb77 Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/b2625e3aea78e021851f9f5c

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

Literature/GSTARCAD/2024/03 API Guides/assets/NET Programming Guide assets/f8c7ceab5c6a5ebbc4251f6e

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 'Gssoft.Gscad.EditorInput.Editor.Command(params object[])' to replace the unmanaged ARX functions

acedCmd and acedCommand.

6.4. Method of Selecting in Current Drawing after Clicking Button in Modal Dialog Box

Select a point or entity in the current drawing after clicking the button in the modal dialog box, using:

using (var edUI = doc.Editor.StartUserInteraction(this)),e.g.:

private void button1_Click(object sender, EventArgs e)
       {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            using (var edUI = doc.Editor.StartUserInteraction(this))
            {
                PromptPointOptions ppo = new PromptPointOptions("\nSelect point:");

                PromptPointResult ppr = ed.GetPoint(ppo);

                PromptSelectionOptions pso = new PromptSelectionOptions();
                PromptSelectionResult psr = ed.GetSelection(pso);
            }
        }

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

  • VB .NET:

Change 'Autodesk.AutoCAD' to 'Gssoft.Gscad' after the 'Imports'

  • C# .NET:

Change 'Autodesk.AutoCAD' to 'Gssoft.Gscad' 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/2024/03 API Guides/assets/NET Programming Guide assets/c969e8068be8b34932f83d3c