GstarCAD 2020 .NET Migration Guide
GstarCAD 2020 .NET Migration Guide
Table of Contents
1. Brief Introduction .............................................................................. 4
2. Development Environment ............................................................... 5
3. Original Code ................................................................................... 6
4. Install GstarCAD SDK ...................................................................... 7
5. VS2017 C# .NET Migration Process ................................................ 8
5.1. Change Reference Files ......................................................... 8
5.1.1. Remove the Reference................................................... 8
5.1.2. Add Reference ............................................................... 8
5.1.3. Choose and Add the Files .............................................. 9
5.1.4. Change the Target Framework ..................................... 11
5.1.5. Modify the Name in Name Space ................................. 12
5.1.6. Compile Program ......................................................... 12
6. VS2017 VB.NET Migration Process ............................................... 13
6.1. Change Reference Files ....................................................... 13
6.1.1. Remove the Reference................................................. 13
6.1.2. Add Reference ............................................................. 13
6.1.3. Choose and Add the Files ............................................ 14
6.1.4. Change the Target Frame ............................................. 16
6.1.5. Modify the Name in Name Space ................................. 16
6.1.6. Compile Program ......................................................... 16
6.2. Using ..................................................................................... 16
6.3. ResultBuffer .......................................................................... 17
6.4. Alternative method to import Unmanaged ARX Function ...... 17
6.5. Alternative Method ................................................................ 17
6.6. Other Usages ........................................................................ 19
6.6.1. Abtain GCAD Application Object under VB enveriment 19
6.6.2. C#.NET and VB.NET Name space Modifaction............ 20
6.7. Replacement Sample ............................................................ 21
2
6.7.1. Namespace Replacement ............................................ 21
6.7.2. Class Name and Property Name Replacement Sample
21
7. Copyright ........................................................................................ 22
3
1. Brief Introduction
Secondary developers from various industries have developed mass of .NET applications
base on AutoCAD®, and one of the highlights of GstarCAD .NET is that GstarCAD
achieves source-level compatibility with AutoCAD® .Net programs. Which means a set of
code suits for two platforms, the developers can migrate the .NET program from AutoCAD
to GstarCAD with almost no code changing. This guide provided for developers migrating
4
2. Development Environment
CPU:
RAM:
Operation System
version, education version and enterprise version(not support LTSC and Windows 10 S)
version
Monitor Resolution:
Traditional monitor:1028 x 800 and above CRT monitor, High resolution and 4K (3840 x
2160) monitor
GstarCAD 2020
5
3. Original Code
The original code should be DOTNET application source code which is from the DONET
6
4. Install GstarCAD SDK
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
SimplePalette, etc.
3) Vbhello includes VB.NET example for how to develop with .NET API.
HelloADS includes the project for how to develop the type of ADS.
HelloARX includes includes the example for how to develop with ARX API.
SimplePalette includes the example for how to develop the type modules for palette
7
5. VS2017 C# .NET Migration Process
the Hello project and right click to select Add Reference. After the "Reference Manager"
8
5.1.3. Choose and Add the 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
9
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.
10
5.1.4. 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
11
5.1.5. Modify the Name in Name Space
Replace the Autodesk.AutoCAD corresponding Name sapce to GrxCAD.
Run GstarCAD and input "netload" at command line, there will a "Select .Net Assembly"
dialog box pops out, select the new generated ".dll" file and click Open button to load it.
12
6. VS2017 VB.NET Migration Process
the Hello project and right click to select Add Reference. After the "Reference Manager"
13
6.1.3. Choose and Add the 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
14
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.
15
6.1.4. 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
6.2. Using
Code like “var mapping = new IdMapping()” need to add “using” function first.
16
{
...
}
6.3. ResultBuffer
functions.
Autodesk.AutoCAD.EditorInput.Editor.TraceBoundary(Autodesk.AutoCAD.Geometr
y.Point3d, bool) alternatvie method:
GrxCAD.EditorInput.Editor.
17
//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();
}
18
6.6. Other Usages
64-bit corrosponding file) as reference, you can abtain GCAD Application object.
Imports GrxCAD.Runtime``
Imports GcadVbaLib
<CommandMethod("GetGcadApplication")>
GCadApp.WindowState = GcWindowState.acMin
End Sub
End Class
End Sub
End Class
19
6.6.2. C#.NET and VB.NET Name space Modifaction
VB.NET:
For the COM object name in the code, such as AcadLWPolyline, please change the
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
20
6.7. Replacement Sample
AutoCAD GstarCAD
Autodesk.AutoCAD.ApplicationServices GrxCAD.ApplicationServices
Autodesk.AutoCAD.EditorInput GrxCAD.EditorInput
Autodesk.AutoCAD.GraphicsSystem GrxCAD.GraphicsSystem
Autodesk.AutoCAD.PlottingServices GrxCAD.PlottingServices
Autodesk.AutoCAD.Publishing GrxCAD.Publishing
Autodesk.AutoCAD.Runtime GrxCAD.Runtime
Autodesk.AutoCAD.Windows GrxCAD.Windows
Autodesk.AutoCAD.Colors GrxCAD.Colors
Autodesk.AutoCAD.DatabaseServices GrxCAD.DatabaseServices
Autodesk.AutoCAD.DatabaseServices.Filters GrxCAD.DatabaseServices.Filters
Autodesk.AutoCAD.Geometry GrxCAD.Geometry
Autodesk.AutoCAD.GraphicsInterface GrxCAD.GraphicsInterface
Autodesk.AutoCAD.LayerManager GrxCAD.LayerManager
AutoCAD GstarCAD
Autodesk.AutoCAD.Interop.Common.ACAD_COLOR GcadVbaLib.GCAD_COLOR
Autodesk.AutoCAD.Interop.Common.AcadEntity GcadVbaLib.GcadEntity
Autodesk.AutoCAD.Interop.Common.AcSelect GcadVbaLib.GcSelect
Autodesk.AutoCAD.Interop.Common.AcadRasterImage GcadVbaLib.GcadRasterImage
Autodesk.AutoCAD.Interop.Common.AcadText GcadVbaLib.GcadText
Autodesk.AutoCAD.Interop.Common.AcadMText GcadVbaLib.GcadMText
Autodesk.AutoCAD.Interop.Common.AcWindowState GcadVbaLib.GcWindowState
21
7. Copyright
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
22