1
Table of Contents
1. Brief Introduction .............................................................................. 4
2. Development Environment ............................................................... 5
3. Install .NET SDK .............................................................................. 6
4. VS2017 C# .NET Development Sample ........................................... 7
4.1. Create .Net Project ................................................................. 7
4.1.1. Run Microsoft Visual Studio 2017 .................................. 7
4.1.2. Input Project Saved Path and Project Name .................. 7
4.1.3. Finish to Create a New Project ....................................... 7
4.2. Set the Reference Library ....................................................... 8
4.2.1. Add Reference ............................................................... 8
4.2.2. Choose and Add Reference Files ................................... 9
4.3. Add Codes ............................................................................ 11
4.4. Compile Program .................................................................. 12
4.5. Run Program ........................................................................ 13
5. VS2017 VB .NET Development Sample ........................................ 14
5.1. Create a .NET Project ........................................................... 14
5.1.1. Run Microsoft Visual Studio 2017 ................................ 14
5.1.2. Input Project Saved Path and Project Name ................ 14
5.1.3. Finish to Create a New Project ..................................... 15
5.2. Set the Reference Library ..................................................... 15
5.2.1. Add Reference ............................................................. 15
5.2.2. Choose and Add Reference Files ................................. 16
5.3. Add Codes ............................................................................ 18
5.4. Compile Program .................................................................. 18
5.5. Run Program ........................................................................ 19
6. DotNet Development Special Usage .............................................. 20
6.1. Using..................................................................................... 20
6.2. ResultBuffer .......................................................................... 20
6.3. Alternative method to import Unmanaged ARX Function ...... 20
2
6.4. Alternative Method ................................................................ 20
6.5. C# .NET and VB .NET Name Space Modification ................. 22
7. Copyright ........................................................................................ 23
3
1. Brief Introduction
.NET is the latest secondary development package introduced by GstarCAD®, which
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# on GstarCAD secondary development.
4
2. 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
: Including home version, professional
Windows 7 SP1(with latest Windows updated)
version, enterprise version and Ultimate version
Monitor Resolution:
Traditional monitor:1028 x 800 and above CRT monitor, High resolution and 4K (3840 x
2160) monitor
GRX SDK 2020
GstarCAD 2020
.NET Framework 4.8 and above
5
3. Install .NET SDK
Download GstarCAD SDK package from our official website:
[Link]
After you get the [Link] 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 includes .NET example for adding solid line.
2) Hello includes .NET example for prompting the information of output.
3) Vbhello includes [Link] example for how to develop with .NET API.
fact_dg includes example for defining LSP function.
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.
6
4. VS2017 C# .NET Development Sample
4.1. Create .Net Project
4.1.1. Run Microsoft Visual Studio 2017
Please click [File] → [New] → [Project]. After clicked the menu Project, the New Project
dialog box will pops out. Then select Visual C# in the catalogue Installed Templates and
click [Class Library (.Net Framework)].
4.1.2. Input Project Saved Path and Project Name
Type "Hello" at the name label in "New Project" dialog box and choose .NET
Framework4.8, as shown below:
Remark:Please choose .NET Framework 4.8 at the frame pull-down list.
4.1.3. Finish to Create a New Project
After finished operation above, click OK button in the dialog to finish the new project
creating.
7
4.2. Set the Reference Library
4.2.1. 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.
8
4.2.2. Choose and Add Reference Files
Find the GstarCADSDK installation path, for example, “C:\grxsdk\inc”. Select [Link]
and [Link] files in “c:\grxsdk\inc-x86” and add them by clicking Add button(If you use
GstarCAD 64-bit version, please select [Link] in inc-x64).
9
Remark:[Link] and [Link] have to be added but file [Link] 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
[Link] file. Please take it as reference to change [Link] file's Copy Local property.
[Link] file includes the following name space:
[Link] file includes the following name space:
[Link] files shows the com corresponding .NET interface.
10
4.3. Add Codes
Using the code below to replace the existing code in [Link] file in Hello project.
using System;
using [Link];
using [Link];
[assembly: CommandClass(typeof([Link]))]
namespace hello
{
public class HelloCmd
{
[CommandMethod("Hello")]
static public void DoIt()
{
try
{
[Link]("Hello
dotnet");
}
catch ([Link] ex)
{
String str = [Link]();
}
}
}
}
11
4.4. Compile Program
Click Visual Studio 2017 menu item [Build] » [Build solution], then you will get a “[Link]”
file from D:\test\Hello\Hello\bin\Release directory.
12
4.5. Run Program
Run GstarCAD and input "netload" at command line, there will a "Select .Net Assembly"
dialog box pops out, select the "[Link]" file and click Open button to load it.
Input "hello" command at command line, “Hello dotnet” will display in the command line.
13
5. VS2017 VB .NET Development Sample
The following is a sample to create a "Hello" project, describe the creation process and
suppose GstarCAD SDK installed in c:\grxsdk dictionary.
5.1. Create a .NET Project
5.1.1. Run Microsoft Visual Studio 2017
Please click [File] → [New] → [Project]. After clicked the menu Project, the New Project
dialog box will pops out. Then select Visual C# in the catalogue Installed Templates and
click [Class Library (.Net Framework)].
5.1.2. Input Project Saved Path and Project Name
Type "Hello" at the name label in "New Project" dialog box and choose .NET
Framework4.8, as shown below:
Remark:Please choose .NET Framework 4.8 at the frame pull-down list.
14
5.1.3. Finish to Create a New Project
After finished operation above, click OK button in the dialog to finish the new project
creating.
5.2. Set the Reference Library
5.2.1. 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.
15
5.2.2. Choose and Add Reference Files
Find the GstarCADSDK installation path, for example, “C:\grxsdk\inc”. Select [Link]
and [Link] files in “c:\grxsdk\inc-x86” and add them by clicking Add button (If you use
GstarCAD 64-bit version, please select [Link] in inc-x64).
16
Remark: [Link] and [Link] have to be added but file [Link] 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
[Link] file. Please take it as reference to change [Link] file's Copy Local property.
[Link] includes the following name space::
[Link] includes the following name space:
[Link] shows the com corresponding .NET interface.
17
5.3. Add Codes
Using the code below to replace the existing code in [Link] file in Hello project.
Imports System
Imports GrxCAD
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link]
Imports [Link]
' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType([Link]))>
Namespace GRXTest
Public Class MyCommands
<CommandMethod("vbhello", [Link])> _
Public Sub RunMRLCommand() ' This method can have any name
Dim doc As [Link]
doc = [Link]
[Link]("hello [Link]")
End Sub
End Class
End Namespace
5.4. Compile Program
Click Visual Studio 2017 menu item [Build] » [Build solution], then you will get a “[Link]”
file from D:\test\Hello\Hello\bin\Release directory.
18
5.5. Run Program
Run GstarCAD and input "netload" at command line, there will a "Select .Net Assembly"
dialog box pops out, select the "[Link]" file and click Open button to load it.
Then run GstarCAD, input "vbhello" command at command line, “hello [Link]” will show
in the command line.
图 5.9
19
6. DotNet Development Special Usage
Some differences between GstarCAD DotNet and AutoCAD DotNet:
6.1. 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())
{
...
}
6.2. ResultBuffer
Use [Link] to replace [Link];
[Link] is the type of OdDbResbuf;
[Link] is the type of resbuf;
Use [Link](IntPtr,bool) to replace ResultBuffer(IntPtr,bool)
6.3. Alternative method to import Unmanaged ARX Function
The alternative method to import unmanaged arx function acedCmd,acedCommand:
Use [Link](params object[]) to replace original
functions.
6.4. Alternative Method
[Link]([Link]
ry.Point3d, bool) alternatvie method:
[Link].
If TraceBoundary([Link].Point3d, bool) has not been provided,
you can use the following method to replace.
[CommandMethod("TESTCMD")]
public void TestCommand()
{
var db = [Link];
var ed = [Link];
20
//new a DBObjectCollection for boundary set
DBObjectCollection objColl = new DBObjectCollection();
using (var tr = [Link]())
{
var curSpace = [Link]([Link], [Link]) as
BlockTableRecord;
var drawOrderTable = [Link]([Link],
[Link]) as DrawOrderTable;
ObjectIdCollection coll = [Link](0);
ObjectId entLast = coll[[Link]-1];
//use "Y" or "N" whether or not to detect islands
//instead of "0,0" when using another seed point
[Link]("-BOUNDARY", "A", "I", "Y", "", "0,0", "");
coll = [Link](0);
int nIndex = [Link](entLast);
for (int i = nIndex; i >= 0; --i)
{
[Link](i);
}
//clone the boundaries created by -BOUNDARY command to DBObjectCollection
foreach (ObjectId id in coll)
{
DBObject obj = [Link](id, [Link]) as DBObject;
DBObject tmp = (DBObject)[Link]();
[Link](tmp);
}
//abort the transaction to avoid the boundaries created by -BOUNDARY command
posting to db
[Link]();
}
//this is a test code to post the cloned boundaries to current space
using (var tr = [Link]())
{
var curSpace = [Link]([Link], [Link]) as
BlockTableRecord;
foreach (DBObject obj in objColl)
{
[Link]((Entity)obj);
21
[Link](obj, true);
}
[Link]();
}
//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
[Link]();
}
6.5. C# .NET and VB .NET Name Space Modification
[Link]:
The content after Imports,change [Link] to GrxCAD
C#.NET:
The content after using,change [Link] to GrxCAD
If use COM:
With [Link], add Imports GcadVbaLib
With C#.net, add using GcadVbaLib
Delete [Link]
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.
22
7. Copyright
Copyright reserved: Xi’an 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®.
23