GstarCAD 2022 .NET Tips

Contents

4639d81454ee94412d4bca2c

When the dialog box returns to GstarCAD, the user exchange is abnormal

Phenomenon:

When the user uses the dialog box to return to GstarCAD for user interaction, the window in GstarCAD won't be closed or switch to the opening drawing to remind user to select a block.

Possible Reason:

In AutoCAD, the code that defines the range of interaction can be omitted. But in GstarCAD, when returning with a dialog box for user interaction, GstarCAD must use code to clarify the range of user interaction. So errors will occur when the user directly copy the original code to GstarCAD.

Suggestion:

Modify the code to clarify the range of user interaction.

For example:

privatevoid BtnSelect_Click(object sender,EventArgs e)
        {
            BlockUpdateClass BlkupdateCls = new BlockUpdateClass();
            BlkupdateCls.SelectObjToUpdate();
            TxtBxBlkName.Text = BlkupdateCls.UpdateblockName;
        }

Change:

BlkupdateCls.SelectObjToUpdate();

To:

using (var edUI = Doc.Editor.SartUserinteraction(this))
            {
                BlkUpdateCls.SelectObjToUpdate();
            }

GrxCAD.NET reports an error when defining objects

Phenomenon:

GrxCAD.NET reports an error when defining objects in VS. Such as “var mapping = new IdMapping()”

Possible Reason:

The code which is similar to "var mapping = new IdMapping()" needs to use "using" in GrxCAD.NET

Suggestion:

Add ”using” when migrate the code.

For example:

Change:

var mapping = new IdMapping()

To:

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

Report an error when migrating "TraceBoundary"

Phenomenon:

Met errors when migrating TraceBoundary (Autodesk.AutoCAD.Geometry.Point3d, bool) from AutoCAD.

Error message like: There is no “TraceBoundary” type in “Editor".

Possible Reason:

Currently, “Autodesk.AutoCAD.EditorInput.Editor.TraceBoundary(Autodesk.AutoCAD.Geometry.Point3d, bool)” is unavailable in GrxCAD.NET.

Suggestion:

Please refer to the following example and adjust your original code:

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

Report an error when editing “ResultBuffer.UnmanagedObject” in GrxCAD.NET

Phenomenon:

Error reported when editing the program in GrxCAD.NET with "ResultBuffer.UnmanagedObject".

Error message like: There is no type of "UnmanagedObject" in "ResultBuffer".

Possible Reason:

“ResultBuffer.UnmanagedObject” belongs to “OdDbResbuf” type. Currently, GrxCAD.NET can’t support this type.

Suggestion:

Use “ResultBuffer.ResbufObject” replace “ResultBuffer.UnmanagedObject”.

For example:

Change “ResultBuffer(IntPtr,bool)” to “ResultBuffer.Create(IntPtr,bool)”

GrxCAD.NET reports an error when importing ARX unmanaged functions

Phenomenon:

When editing the program in GrxCAD.NET, if importing ARX unmanaged functions such as “acedCmd, acedCommand”, the editor prompts that the function does not exist.

Possible Reason:

acedCmd is a function of ARX. Currently, GrxCAD.NET does not support it.

Suggestion:

Replace relative functions with “GrxCAD.EditorInput.Editor.Command”.

For example:

Replace “acedCommand(params object[]);” with “GrxCAD.EditorInput.Editor.Command(params object[]);”

GrxCAD.NET met an error when adding reference namespace

Phenomenon:

When editing a program in GrxCAD.NET, if using a namespace such as "Autodesk.AutoCAD", the editor prompts that "the namespace does not exist".

Possible Reason:

“Autodesk.AutoCAD” is the name space of AutoCAD. The name space need to be adjusted when migrate AutoCAD programs to GrxCAD.NET.。

Suggestion:

If it is a VB.net program, please change the content after "import" from "Autodesk.AutoCAD" to "GrxCAD".

If it is a C#.net program,please change the content after "using" from "Autodesk.AutoCAD" to "GrxCAD"

If based on COM:

In VB.net,please add “Imports GcadVbaLib”

In C#.net,please add “using GcadVbaLib”

Meanwhile, please delete “Autodesk.AutoCAD.Interop.Common”.

On the other hand, some COM objects like "AcadLWPolyline", need to change their prefix to "Gcad", such as "GcadLWPolyline".

For some uncertainties, please check it in the object browser first. For example, "ACAD_COLOR", please first check whether there is "GCAD_COLOR" in the object browser, and replace it if you find it.

For example:

Replace “using Autodesk.AutoCAD.ApplicationServices;” with “using GrxCAD.ApplicationServices;”.

ae1f7929e6e0649f73433bc1