Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ARES Commander provides .NET API that lets you author third party Plugin Software for ARES Commander.

...

Code Block
languagec#
themeFadeToGrey
linenumberstrue
        //Method attribute to define lisp callable function 'LispTest' 
        //i.e (setq x (lisptest "Text created by .NET lisp function" 1.0 '(10 10 0)))
        [LispFunction("lisptest")]
        public ResultBuffer DoIt(ResultBuffer args)
        {
            // Get the database of the active document.
            Database db = HostApplicationServices.WorkingDatabase;
            TypedValue[] argsVal = new TypedValue[3];
            if (args != null)
            {
                argsVal = args.AsArray();
            }
            else
            {
                argsVal[0] = new TypedValue((int)LispDataType.Text, "Default Text");
                argsVal[1] = new TypedValue((int)LispDataType.Double, .2);
                argsVal[1] = new TypedValue((int)LispDataType.Point3d, new Point3d(0, 0, 0));
            }
            // Set up transaction manager.
            Teigha.DatabaseServices.TransactionManager tm = db.TransactionManager;
            using (Transaction tr = tm.StartTransaction())
            {
                try
                {
                    Point3d pPosition = new Point3d(0, 0, 0);

                    // Create a new MText object and set properties.
                    DBText pText = new DBText();
                    pText.TextString = (String)argsVal[0].Value;
                    pText.Height = Convert.ToDouble(argsVal[1].Value);
                    pText.Position = (Point3d)argsVal[2].Value;

                    // Get model space to add the MText object.
                    BlockTable pBlockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                    BlockTableRecord pModelSpace = (BlockTableRecord)tr.GetObject(pBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    // Add the object to the model space.
                    ObjectId id = pModelSpace.AppendEntity(pText);
                    tr.AddNewlyCreatedDBObject(pText, true);

                    // Commit changes to database.
                    tr.Commit();
                    //return created text entity to lisp
                    return new ResultBuffer(new TypedValue((int)LispDataType.ObjectId, id));
                }
                finally
                {
                    // delete tr , managed by c# with garbage collection
                }

            }
        }

Migrating AutoCAD® .NET Classic Application to ARES Commander

You can migrate .NET applications running on AutoCAD® platform to ARES Commander with minimal changes.

  • Replace AutoCAD® .NET assemblies with ARES .NET assemblies.
  • Replace Autodesk.AutoCAD namespace with Teigha namespace in the source code.

Advance Migration

If you do not want to maintain separate source code for AutoCAD® and ARES Commander, then additional steps are necessary. A single project with two build configuration solves the issue.

Step 1: Create a new build configuration for AutoCAD® and ARES Commander.

 Image Removed

Step 2: Using project Properties, select all configurations one by one and define Symbol “AutoCAD” or “ARES” for the corresponding configurations.

For AutoCAD_Release configuration:

 Image Removed

For ARES_Release:

 Image Removed

 Step 3: Add Conditional reference assemblies to the project using Symbols. Modify csproj file manually in the text editor to add condition for all references as in the following example.

Code Block
languagexml
themeFadeToGrey
linenumberstrue
<ItemGroup>

    <Reference Include="accoremgd" Condition="$(DefineConstants.Contains('AutoCAD'))">

      <HintPath>C:\Program Files\Autodesk\AutoCAD 2018\accoremgd.dll</HintPath>

    </Reference>

    <Reference Include="acdbmgd" Condition="$(DefineConstants.Contains('AutoCAD'))">

      <HintPath>C:\Program Files\Autodesk\AutoCAD 2018\acdbmgd.dll</HintPath>

    </Reference>

    <Reference Include="acmgd" Condition="$(DefineConstants.Contains('AutoCAD'))">

      <HintPath>C:\Program Files\Autodesk\AutoCAD 2018\acmgd.dll</HintPath>

    </Reference>

    <Reference Include="FxCoreMgd_4.03_14" Condition="$(DefineConstants.Contains('ARES'))">

      <HintPath>C:\Program Files\Graebert GmbH\ARES Commander 2018\BIN\FxCoreMgd_4.03_14.dll</HintPath>

    </Reference>

    <Reference Include="TD_Mgd_4.03_14" Condition="$(DefineConstants.Contains('ARES'))">

      <HintPath>C:\Program Files\Graebert GmbH\ARES Commander 2018\BIN\TD_Mgd_4.03_14.dll</HintPath>

    </Reference>

  </ItemGroup>

Step 4: Changes in the source code add using directives for both the application conditionally and Replace Autodesk.AutoCAD to CADApp in *.cs source files which is defined conditional declaration below.

 

Code Block
languagec#
themeFadeToGrey
linenumberstrue
#if  ARES

using Teigha.DatabaseServices;

using Teigha.Runtime;

using Teigha.Geometry;

using Teigha.ApplicationServices;

using Teigha.EditorInput;

using CADApp = Teigha;

#elif  AutoCAD

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using CADApp = Autodesk.AutoCAD;

#endif

//If we define using statement as above then while porting no need to write as below
#if ARES
Teigha.Colors.Color acadColor = Teigha.Colors.Color.FromRgb(color.R, color.G, color.B);
#else
Autodesk.AutoCAD.Colors.Color acadColor = Autodesk.AutoCAD.Colors.Color.FromRgb(color.R, color.G, color.B);
#endif

//ported code will be

CADApp.Colors.Color acadColor = Teigha.Colors.Color.FromRgb(color.R, color.G, color.B);

Step 5:

Specify separate Output folders for both configurations.

Build both configurations one by one. The builds will work with their corresponding applications.

...