.NET

BricsCAD (Windows) Pro, Platinum


 

The BricsCAD .NET API exposes BricsCAD functionality and allows to build managed code: code that runs under the .NET Common Language Runtime CLR.

 

Runtime

With BricsCAD V16, the supported .NET framework version is 4.5.1 with CLR version 4.

Since the new framework is highly compatible to the .NET Framework 4, existing modules compiled for older BricsCAD versions should keep running, unless version-dependent P/invoke signatures were used (see further).

Compiler version

For new developments on V16, developers need to use Visual Studio 2013. While modules compiled with VS2010/.NET 4 for older BricsCAD versions will continue to run on V16, the problem is Visual Studio 2010 itself will not recognize v16's BrxMgd and TD_Mgd reference DLLs, since VS2010 is not .NET 4.5.1 aware.

For .NET based developments, in particular VB.NET, C#, F#, C++/CLI (pure), it should be sufficient to use the free Visual Studio 2013 express compiler.

To setup a project with Visual Studio

Create a class library using the class library wizard under your preferred .NET language. There are currently two DLLs that need to be referenced, BrxMgd.dll and TD_Mgd.dll (+ optional TD_MgdBrep.dll (BREP API)). These DLLs are located in your BricsCAD installation folder. Important note: when referencing these DLLs, its important to set the 'Copy Local' property to False. All other DLLs such as referenced COM DLLs or satellite DLLs. can have their 'Copy Local' property to true, or as needed by your project.

 

Sample projects can be found in the BricsCAD install folder, subfolder \API\dotNet.

Changes in V16

BRX15.DLL has been updated as BRX16.DLL, P/Invoke signatures depending on this file will need to be updated accordingly.

 

Code compatibility

It's generally possible to use the same source code to build assemblies targeting both BricsCAD and AutoCAD. A common technique for resolving differences in namespaces is to use short namespace aliases that are different depending on the target application:

C#
VB.NET

#if BRX_APP
  using _AcAp = Bricscad.ApplicationServices;
  using _AcBr = Teigha.BoundaryRepresentation;
  using _AcCm = Teigha.Colors;
  using _AcDb = Teigha.DatabaseServices;
  using _AcEd = Bricscad.EditorInput;
  using _AcGe = Teigha.Geometry;
  using _AcGi = Teigha.GraphicsInterface;
  using _AcGs = Teigha.GraphicsSystem;
  using _AcPl = Bricscad.PlottingServices;
  using _AcBrx = Bricscad.Runtime;
  using _AcTrx = Teigha.Runtime;
  using _AcWnd = Bricscad.Windows;
#elif ARX_APP
  using _AcAp = Autodesk.AutoCAD.ApplicationServices;
  using _AcBr = Autodesk.AutoCAD.BoundaryRepresentation;
  using _AcCm = Autodesk.AutoCAD.Colors;
  using _AcDb = Autodesk.AutoCAD.DatabaseServices;
  using _AcEd = Autodesk.AutoCAD.EditorInput;
  using _AcGe = Autodesk.AutoCAD.Geometry;
  using _AcGi = Autodesk.AutoCAD.GraphicsInterface;
  using _AcGs = Autodesk.AutoCAD.GraphicsSystem;
  using _AcPl = Autodesk.AutoCAD.PlottingServices;
  using _AcBrx = Autodesk.AutoCAD.Runtime;
  using _AcTrx = Autodesk.AutoCAD.Runtime;
  using _AcWnd = Autodesk.AutoCAD.Windows;
#endif

#If BRX_APP Then
Imports _AcAp = Bricscad.ApplicationServices
Imports _AcBr = Teigha.BoundaryRepresentation
Imports _AcCm = Teigha.Colors
Imports _AcDb = Teigha.DatabaseServices
Imports _AcEd = Bricscad.EditorInput
Imports _AcGe = Teigha.Geometry
Imports _AcGi = Teigha.GraphicsInterface
Imports _AcGs = Teigha.GraphicsSystem
Imports _AcPl = Bricscad.PlottingServices
Imports _AcBrx = Bricscad.Runtime
Imports _AcTrx = Teigha.Runtime
Imports _AcWnd = Bricscad.Windows
#ElseIf ARX_APP Then
Imports _AcAp = Autodesk.AutoCAD.ApplicationServices
Imports _AcBr = Autodesk.AutoCAD.BoundaryRepresentation
Imports _AcCm = Autodesk.AutoCAD.Colors
Imports _AcDb = Autodesk.AutoCAD.DatabaseServices
Imports _AcEd = Autodesk.AutoCAD.EditorInput
Imports _AcGe = Autodesk.AutoCAD.Geometry
Imports _AcGi = Autodesk.AutoCAD.GraphicsInterface
Imports _AcGs = Autodesk.AutoCAD.GraphicsSystem
Imports _AcPl = Autodesk.AutoCAD.PlottingServices
Imports _AcBrx = Autodesk.AutoCAD.Runtime
Imports _AcTrx = Autodesk.AutoCAD.Runtime
Imports _AcWnd = Autodesk.AutoCAD.Windows
#End If

 

Known differences

There are some known differences that developers should be aware of.

 

Access DBObject after transaction ends

In AutoCAD, objects belonging to a transaction remain accessible in some cases even after the transaction has ended. In BricsCAD, all transaction resident objects are closed when the transaction ends. For example:

using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
{
  _AcDb.DBObject space = tr.GetObject(db.CurrentSpaceId, _AcDb.OpenMode.ForRead);
  tr.Commit();
  //now 'space' is closed and no longer transaction resident
  _AcDb.ObjectId idXDict = space.ExtensionDictionary; //works in Acad; eInvalidOperation in Teigha
}

If this situation is encountered, there are two common solutions:

 

 


For further assistance please contact Bricsys Support.


 

Tell me about...

Copying Code Examples from the BricsCAD Programmer’s Reference


© Menhirs NV. All rights reserved.