Skip to content

Latest commit

 

History

History
183 lines (132 loc) · 5.18 KB

README.md

File metadata and controls

183 lines (132 loc) · 5.18 KB

CwAPI3D.Net.Bridge

This project serves as a .NET bridge for the C++ API from cadwork 3d. It leverages the power of C++ CLI (Common Language Infrastructure) to provide a seamless integration between the .NET environment and the cadwork 3d API. This allows developers to utilize the robust features of cadwork 3d API within their .NET applications.

Build Solution

Release to NuGet

Getting Started

Clone the repository to your local machine.

git clone https://github.com/Brunner246/CwAPI3D.Net.Bridge.git

Update the macros in CwAPI3D.props to point to the correct paths for cadwork. The macros are used to include the necessary headers and for copying the DLLs as a post-build event into the userprofile directory.

  <PropertyGroup Label="UserMacros">
    <CwAPI3D>./CwAPI3D/includes</CwAPI3D>
    <USERPROFILE_API>D:\cadwork\userprofil_30\3d\API.x64</USERPROFILE_API>
    <AssemblyName>CwAPI3D.Net.Bridge</AssemblyName>
    <API_NAME>CwAPI3D.Net.Bridge</API_NAME>
  </PropertyGroup>

Setup config file for .net assembly

This file must be located in the plugin directory (userprofil_30\3d\API.x64\YourPlugin\library.config)

The file needs the following name library.config

netLibraryName=yourSuperDotNetLibrary
initializerNamespace=yourNamespace

If the file does not exist, the defaults are:

  • netLibraryName=examplelib
  • initializerNamespace=examplelib

In my case, the structure looks like this.

 Directory of D:\cadwork\userprofil_30\3d\API.x64\CwAPI3D.Net.Bridge

29/04/2024  09:48           992,256 CwAPI3D.Net.Bridge.dll          (C++/CLI Library)
29/04/2024  09:33             5,632 yourSuperDotNetLibrary.dll      (Pure C# Library)
29/04/2024  09:33                60 library.config                  (Config File)

Prerequisites

  • Visual Studio 2022 or JetBrains Rider
  • .NET Framework 4.8
  • Install C++/CLI support in Visual Studio (Visual Studio Installer -> Modify -> Individual Components -> C++/CLI support)

C++ CLI

.NET programming with C++/CLI

Walkthrough: Compile a C++/CLI program

C++/CLI Syntax

using namespace System;

////////////////////////// managed C# code //////////////////////////

public ref class Greeter
{
    public:
        Greeter(String^ name)
        {
            this->name = name;
        }

        String^ Greet()
        {
            return "Hello, " + name;
        }
    private:
        String^ name;
}

////////////////////////// native CXX code //////////////////////////

public ref class MyClass
{
    public:

        MyClass()
        {
            mPoint = new C3dPoint();
        }

        explicit MyClass(const double aX, const double aY, const double aZ)
        {
            Console::WriteLine("Hello from C++/CLI!");
            mPoint = new C3dPoint(aX, aY, aZ);
        }
        
        explicit MyClass(const C3dPoint% p)
        {
            mPoint = new C3dPoint(p);
        }

        // Destructor
        ~MyClass()
        {
            this->!MyClass();
        }

        // Finalizer
        !MyClass()
        {
            Console::WriteLine("Finalizer from C++/CLI!");
            delete mPoint;
        }

        property C3dPoint* Point
        {
            C3dPoint* get()
            {
                return mPoint;
            }
        }

    private:
        C3dPoint* mPoint;
};

Design CwAPI3D Controller Implementation (Bridge Pattern)

classDiagram
    IAttributeController-DotNet <|-- AttributeController-DotNet
    IAttributeController-DotNet "1" *-- "1" IAttributeController-CPP : has
    IAttributeController-CPP <|-- AttributeController-CPP
    class IAttributeController-DotNet {
        +GetName()
    }
    class AttributeController-DotNet {
        - instance: IAttributeController-CPP
        +GetName()
    }
    class IAttributeController-CPP {
        +getName()*
    }
    class AttributeController-CPP {
        +getName()
    }

Loading

Debugging

Debugging in Visual Studio

  1. Open the project in Visual Studio.
  2. Set the project to run in 64-bit mode.
  3. Set the project to run in Debug mode.
  4. Attach the debugger to the process 3d.exe.

img.png

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Contributing Back

If you extend or improve the CwAPI3D bridge, please commit your changes back to this repository. This way, all users can benefit from the enhancements. Your contributions help make the CwAPI3D .NET bridge better for everyone.