GstarCAD 2022 .NET Migration Guide

Contents

ae64b4535f5d130c675f16ab

Brief Introduction

Application Developers from various industries have developed a large number of ARX applications based on AutoCAD®, and one of the highlights of GstarCAD GRX is GstarCAD can migrate the ARX program which runs on the AutoCAD platform to GstarCAD with almost no code changing. Realized source-level compatibility with AutoCAD®ARX programs, which means one set of code can be suitable for two platforms. Developers can refer this guide to easily migrate the code to GstarCAD.

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, including 4K (3840 x 2160) monitor

  • GRX SDK 2022

  • GstarCAD 2022

  • .NET Framework 4.8 and above

Original Code

The original code should be DOTNET application source code which is from the DONET ObjectARX 2010 or higher version.

Install GstarCAD 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 is the .NET sample for adding solid line.

  2. Hello is the .NET sample for prompting the information of output.

  3. Vbhello is the VB.NET sample to develop with .NET API.

  • fact_dg is the sample for defining LSP function.

  • HelloADS is the project sample to develop the type of ADS.

  • HelloARX is the sample to develop with ARX API.

  • SimplePalette is the sample to develop the type modules for palette

VS2017 C# .NET Migration Process

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.

Change Reference Files

Remove the Reference

Remove acad reference files, as shown below.

282434b71a1cb67693447e75

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.

1090e26e6bec93aa884d2587 4b3f672aefcf4cabefccdd7b

Load Reference File

Find the GstarCAD SDK 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)

f6339dd30eaa9bc19c5e60b2 903b0465a4519cb58b6893a5

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.

40df6fe47a9bbfdd6fef559d 6173bf8d63b34e5bebd29c67

Change the Target Framework

In VS 2017, find the Hello project you have been created on the solution explorer. Right click to select Properties. After the new page opens, please change the "Target framework" to Framework 4.8 from the pull-down list in Application menu.

6687864c5b55fa6e1542ab62 9489ce2f387db7e03c9183a5

Modify the Name in Name Space

Replace the Autodesk.AutoCAD corresponding Name sapce to GrxCAD.

Compile Program

Click Visual Studio 2017 menu item [Build] » [Build solution], regenerate the dll file in the corresponding directory.

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

VS2017 VB.NET Migration Process

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.

Change Reference Files (2)

Remove the Reference (2)

Remove acad reference files, as shown below.

bb483cc3d9a96c2e64c5c8be

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.

f5d37e98e7aded863c787bf2 4b3f672aefcf4cabefccdd7b

Load 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)

203e1343c88094b2860917c8 8ca7eae32cda27676e2513bf

Remark:gmap.dll and gmdb.dll are necessary,GrxCAD.Interop.dll is alternative.

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.

40df6fe47a9bbfdd6fef559d 6173bf8d63b34e5bebd29c67

Change the Target Frame

In VS 2017, find the Hello project you have been created on the solution explorer. Right click to select Properties. After the new page opens, please change the "Target framework" to Framework 4.8 from the pull-down list in Application menu.

ce9c6524cef72414a051542f 1b13ecbc638e9dab739bd5a1

Modify the Name in Name Space (2)

Replace the Autodesk.AutoCAD corresponding Name sapce to GrxCAD.

Compile Program (2)

Click Visual Studio 2017 menu item [Build] » [Build solution], regenerate the dll file in the corresponding directory.

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

DotNet Application Development Special Usage

DotNet Application Development Special Usage as shown below.

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();
}

Other Usages

Abtain GCAD Application Object under VB enveriment

After adding C:\grxsdk\inc-x86\gcax.tlb (if your GstarCAD is 64-bit, please choose the 64-bit corrosponding file) as reference, you can abtain GCAD Application object.

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
    End Sub
End Class

C#.NET and VB.NET Name space Modifaction

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

Replacement Sample

Namespace Replacement

AutoCADGstarCAD
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

Class Name and Property Name Replacement Sample

AutoCADGstarCAD
Autodesk.AutoCAD.Interop.Common.ACAD_COLORGcadVbaLib.GCAD_COLOR
Autodesk.AutoCAD.Interop.Common.AcadEntityGcadVbaLib.GcadEntity
Autodesk.AutoCAD.Interop.Common.AcSelectGcadVbaLib.GcSelect
Autodesk.AutoCAD.Interop.Common.AcadRasterImageGcadVbaLib.GcadRasterImage
Autodesk.AutoCAD.Interop.Common.AcadTextGcadVbaLib.GcadText
Autodesk.AutoCAD.Interop.Common.AcadMTextGcadVbaLib.GcadMText
Autodesk.AutoCAD.Interop.Common.AcWindowStateGcadVbaLib.GcWindowState

Copyright reserved: 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®
98f00ce4dfbf8838fcf47540

PDF page 3 — additional source text

7.6.1. Namespace Replacement ............................................ 21

PDF page 3 — additional source text

8. 
Copyright ........................................................................................ 22

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