GstarCAD 2027 .NET Programming Guide

Contents

22686fca252c372104b9c86a

Introduction

This .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.

Programming Environment

  • Microsoft® Visual Studio 2022 (version 17.8.0)

  • Windows SDK 10.0 (latest installed version)

  • CPU:

Basic: 1.6 GHz CPU

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)

  • Monitor Resolution:

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

  • GRXSDK

  • Microsoft .NET 8.0

Install SDK

Download SDK.

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, HelloARX and SimplePalette.

  • Dotnet: .NET programming samples

  1. Addline: .NET programming sample of adding solid lines

  2. Hello: .NET programming sample of outputting prompt information

  3. 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.

Visual Studio 2022 C# .NET Programming Sample

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

Create .NET project

Runn Microsoft® Visual Studio 2022

Click File→New→Project to launch the New Project dialog window. Select C# from the drop down list on the right side and click Class Library from the list frame.

ff7b07f3fee67bbbba62e2e8

Input Project Save Path and Project Name

Input 'AddLine' at the Project Name field in the New Project dialog box, enter 'C:\Sample\dotNet” in the Location field, and click Next. As shown below.

5cbe0a9524b208622b4b2b53

Finish Creating New Project

Select .NET 8.0 (Long Term Support) in the drop-down list and click the Create button to finish creating the new project 'AddLine'.

0e89280fea449b50e9126df7

Set Reference Library

Add Reference

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

a5a42a1509b67012b23b6c89

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

bb17ac07434f833273581f27

Choose and Add Reference File

c0cfbfb38244803791e277f9

From the 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/2027/03 API Guides/assets/NET Programming Guide assets/de183d7c8e24d0bd96591c75 34a2483179e2aada5467aded
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 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'.

c3ca7a9cee168fcc76b6256c dfd885f491ca1ba719eddd9c
  • 'GcCoreMgd.dll' includes the following namespaces:

  • Gssoft.Gscad.ApplicationServices

  • Gssoft.Gscad.ApplicationServices.Core

  • Gssoft.Gscad.EditorInput

  • Gssoft.Gscad.GraphicsSystem

  • Gssoft.Gscad.Internal

  • Gssoft.Gscad.PAL.FontUtils

  • 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.PAL.FontUtils

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.PAL.FontUtils

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.

Add Code

Add the following codes to 'Class1.cs':

using Gssoft.Gscad.ApplicationServices;
using Gssoft.Gscad.DatabaseServices;
using Gssoft.Gscad.Geometry;
using Gssoft.Gscad.Runtime;

namespace AddLine
{
    public class Class1
    {
        [CommandMethod("addline")]
        static public void DoIt()
        {
            Point3d st = new Point3d(100.0, 100.0, 0.0);
            Point3d ed = new Point3d(200.0, 200.0, 0.0);
            Line lin = new Line(st, ed);
            Database db = HostApplicationServices.WorkingDatabase;
            Transaction trans = db.TransactionManager.StartTransaction();
            try
            {
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                btr.AppendEntity(lin);
                trans.AddNewlyCreatedDBObject(lin, true);
                trans.Commit();
            }
            catch (System.Exception ex)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
                trans.Abort();
            }
        }
    }
}

Compile Program

In Visual Studio 2022, click Build→Rebuild Solution to generate 'Addline.dll' file.

And AddLine.dll will be generated in the path 'C:\Sample\dotNet\AddLine\bin\Debug\net8.0 '(the path can be set).

Run Program

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

f753aa9b7b46d6b8542319fb c26b1cd0540c69cd74f32165

Input 'AddLine' at command line, there will be a straight line generated.

70ecc9b78cf00119eddbb372 fda20f7629ac4c995d724b5d

Visual Studio 2022 VB .NET Programming Sample

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

Create .NET project (2)

Run Microsoft® Visual Studio 2022

Click File→New→Project to launch the New Project dialog window. Select Visual Basic in the drop down list on the right side and click Class Library from the list frame.

a3ee3ff5518518e9466f4e95

Input Project Save Path and Project Name (2)

Input 'vbAddLine' at the Project Name field in the New Project dialog box, enter 'C:\Sample\dotNet” in the Location field, and click Next. As shown below.

a420ce36221160efcd527093

Finish Creating New Project (2)

Select .NET 8.0 (Long Term Support) in the drop-down list and click the Create button to finish creating the new project 'AddLine'.

b0e0c9f33e1f584371fd3761

Set the Reference

Add Reference (2)

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

18f27bd420e3fd65c5025b62

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

3196be7f786016b70e890717

Choose and Add Reference File (2)

From the 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.

f77d62ba63558ba5b211c83d Literature/GSTARCAD/2027/03 API Guides/assets/NET Programming Guide assets/de183d7c8e24d0bd96591c75 785398d0bfadd3cab5af4092
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 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'.

23a6525fc2aaee4b25c8e991 6bee850edaf9e374b34c8ed1
  • 'GcCoreMgd.dll' includes the following namespaces:

  • Gssoft.Gscad.ApplicationServices

  • Gssoft.Gscad.ApplicationServices.Core

  • Gssoft.Gscad.EditorInput

  • Gssoft.Gscad.GraphicsSystem

  • Gssoft.Gscad.Internal

  • Gssoft.Gscad.PAL.FontUtils

  • 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.PAL.FontUtils

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.PAL.FontUtils

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.

Add code

Add the following codes to 'Class1.vb':

Imports Gssoft.Gscad.ApplicationServices
Imports Gssoft.Gscad.DatabaseServices
Imports Gssoft.Gscad.Geometry
Imports Gssoft.Gscad.Runtime

Public Class Class1
    <CommandMethod("vbAddLine")>
    Public Sub vbAddLine()
        Dim startpt As New Point3d(4.0, 2.0, 0.0)
        Dim endpt As New Point3d(10.0, 7.0, 0.0)
        Dim pLine As New Line(startpt, endpt)
        Dim lineid As ObjectId
        Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
        Dim tm As Gssoft.Gscad.DatabaseServices.TransactionManager = db.TransactionManager
        Dim ta As Transaction = tm.StartTransaction()
        Try
            Dim bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForRead, False)
            Dim btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
            lineid = btr.AppendEntity(pLine)
            tm.AddNewlyCreatedDBObject(pLine, True)
            ta.Commit()
        Finally
            ta.Dispose()
        End Try
    End Sub
End Class

Compile Program (2)

In Visual Studio 2022, click Build→Rebuild Solution to generate 'Addline.dll' file.

And AddLine.dll will be generated in the path 'C:\Sample\dotNet\vbAddLine\bin\Debug\net8.0 '(the path can be set).

Run Program (2)

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

2b708a29bec62a3c6f1676f2 3823cdab71c5e4e44ae25db0

Figure 5.9

aac27799f376dd89e00ed1d9 5afec787fd41b7b039931cff

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.

2ee6f631dd271431f83675a9