GstarCAD 2023 .NET Migration Guide

Contents

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/a2f41c31b51f52ba406cabe3

1. Introduction

There are a large number of .NET applications based on AutoCAD® . With GstarCAD SDK, it is easy to migrate .NET application programs running on AutoCAD® to GstarCAD with little change to the original source codes, keeping the source-code-level compatibility.

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. Requirement on Original Source Code

The original source codes should be .NET application source codes of .NET ObjectARX 2010 or higher versions.

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

5. Visual Studio 2017 C# .NET Program Migration Process

The following illustrates the migration process by taking the ' Hello ' project as an example, and assumes that the

GstarCAD SDK is installed in ' C:\grxsdk '.

5.1. Change Reference File

5.1.1. Remove Reference

From Solution Expore r of Visual Studio 2017, find project ' Hello ' and remove relevant ARX reference files, as shown below.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/6d698a919db65dfaf71adc26

5.1.2. Add Reference

In Solution Exporer of Visual Studio 2017, right-click on project ' Hello ' and select Add Reference . After the Reference Manager dialog window pops out, click Browse… button as shown below.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/c3ffe2bbf1289d3acfeb55ee Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/f79706fffe31399defc2fae2

5.1.3. Load Reference File

From the installation path of GstarCAD SDK, 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 Migration Guide assets/48b71c070b5756c021fdf3be Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/7faf98b83bc5f0005699f517
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 Migration Guide assets/1fc26d50c9a474b70e382f43 Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/db2263e522e946175023fa28

5.2. Change Target Framework

In Solution Exporer of Visual Studio 2017, right-click on project ' Hello ' and select Properties . After the dialog window pops out, select Application and change the Target framework to .NET Framework 4.8 from the pull-down list.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/c549bf9e3e618cbf6a731e54 Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/8bdad5f85b74c0cdaab9fd58

5.3. Modify Name in Namespace

Replace the ' Autodesk.AutoCAD ' with corresponding ' GrxCAD ' in .NET source codes.

5.4. Compile Program

In Visual Studio 2017, click Build → Build Solution to regenerate the DLL file in corresponding directory. Run GstarCAD and input ' netload ' at command line, select the relative DLL file from Select .Net Assembly dialog window and click Open button to load it.

6. Visual Studio 2017 VB .NET Program Migration Process

The following illustrates the migration process by taking the ' Hello ' project as an example, and assumes that the

GstarCAD SDK is installed in ' C:\grxsdk' .

6.1. Change Reference File

6.1.1. Remove Reference

From Solution Exporer of Visual Studio 2017, find project ' Hello ' and remove relevant ARX reference files, as shown below.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/33e7a15c7abe250909180dd9

6.1.2. Add Reference

In Solution Exporer of Visual Studio 2017, right-click on project ' Hello ' and select Add Reference . After the Reference Manager dialog window pops out, click Browse… button as shown below.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/4c897f71638fe2d9a9e58e8d Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/32726ab28ad6c1466255e434

12

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/f79706fffe31399defc2fae2

6.1.3. Load Reference File

From the installation path of GstarCAD SDK, 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 Migration Guide assets/750dc66f6cdbbea56da75481 Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/7e935896b3141346de09b25d
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 Migration Guide assets/71235f581f600f944689d03c Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/f50e9b219d5b6619b36e87ad

6.2. Change Target Framework

In Solution Exporer of Visual Studio 2017, right-click on project ' Hello ' and select Properties . After the dialog window pops out, select Application and change the Target framework to .NET Framework 4.8 from the pull-down list.

Literature/GSTARCAD/2023/03 API Guides/assets/NET Migration Guide assets/fb4610347c2749e46a12239f

6.3. Modify Name in Namespace

Replace the ' Autodesk.AutoCAD ' with corresponding ' GrxCAD ' in .NET source codes.

6.4. Compile Program

In Visual Studio 2017, click Build → Build Solution to regenerate the DLL file in corresponding directory. Run GstarCAD and input ' netload ' at command line, select the relative DLL file from Select .Net Assembly dialog window and click Open button to load it.

7. Special Usage of GstarCAD .NET Programming

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

programming.

7.1. How to Use 'using'

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

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

7.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)'

7.3. Alternative Method of Importing Unmanaged ARX Function

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

and acedCommand.

7.4. Other Usage

7.4.1. Abtain GCAD Application Object under Visual Basic Environment

By adding 'C:\grxsdk\arx\inc-x64\acax.tlb' as reference, it is possible to obtain GCAD application objects with

following codes.

Imports GrxCAD.Runtime
Imports GcadVbaLib

Public Class Class1
    <CommandMethod("GetGcadApplication")>

    Public Sub GetGcadApplication()
        'Define abtain GcadApplication object, the object is null
        Dim GCadApp As GcadApplication

        ' Abtain the object address through the process name.
        GCadApp = GetObject(, "gcad.application")

        'Minimize the abtained process window
        GCadApp.WindowState = GcWindowState.acMin
    End Sub
End Class

7.4.2. C# .NET and VB .NET Namespace Modifaction

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

7.5. Sample of Replacement

7.5.1. Sample of Namespace Replacement

AutoCAD®GstarCAD
Autodesk.AutoCAD.ApplicationServicesGrxCAD.ApplicationServices
Autodesk.AutoCAD.EditorInputGrxCAD.EditorInput
Autodesk.AutoCAD.GraphicsSystemGrxCAD.GraphicsSystem
Autodesk.AutoCAD.PlottingServicesGrxCAD.PlottingServices
Autodesk.AutoCAD.PublishingGrxCAD.Publishing
Autodesk.AutoCAD.RuntimeGrxCAD.Runtime
Autodesk.AutoCAD.WindowsGrxCAD.Windows
Autodesk.AutoCAD.ColorsGrxCAD.Colors
Autodesk.AutoCAD.DatabaseServicesGrxCAD.DatabaseServices
Autodesk.AutoCAD.DatabaseServices.FiltersGrxCAD.DatabaseServices.Filters
Autodesk.AutoCAD.GeometryGrxCAD.Geometry
Autodesk.AutoCAD.GraphicsInterfaceGrxCAD.GraphicsInterface
Autodesk.AutoCAD.LayerManagerGrxCAD.LayerManager

7.5.2. Sample of Class Name and Property Name Replacement

AutoCAD®GstarCAD
Autodesk.AutoCAD.Interop.Common.ACAD_COLORGcadVbaLib.GCAD_COLOR
Autodesk.AutoCAD.Interop.Common.AcadEntityGcadVbaLib.GcadEntity
Autodesk.AutoCAD.Interop.Common.AcSelectGcadVbaLib.GcSelect
_Autodesk.AutoCAD.Interop.Common.AcadRasterImage __GcadVbaLib.GcadRasterImage _
Autodesk.AutoCAD.Interop.Common.AcadTextGcadVbaLib.GcadText
Autodesk.AutoCAD.Interop.Common.AcadMTextGcadVbaLib.GcadMText
Autodesk.AutoCAD.Interop.Common.AcWindowStateGcadVbaLib.GcWindowState

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 Migration Guide assets/6dc2835feaf1b8a9c5af289f