CwAPI3D.Net.Bridge 0.0.4

dotnet add package CwAPI3D.Net.Bridge --version 0.0.4
                    
NuGet\Install-Package CwAPI3D.Net.Bridge -Version 0.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CwAPI3D.Net.Bridge" Version="0.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CwAPI3D.Net.Bridge" Version="0.0.4" />
                    
Directory.Packages.props
<PackageReference Include="CwAPI3D.Net.Bridge" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CwAPI3D.Net.Bridge --version 0.0.4
                    
#r "nuget: CwAPI3D.Net.Bridge, 0.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CwAPI3D.Net.Bridge@0.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CwAPI3D.Net.Bridge&version=0.0.4
                    
Install as a Cake Addin
#tool nuget:?package=CwAPI3D.Net.Bridge&version=0.0.4
                    
Install as a Cake Tool

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

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.

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.4 208 4/29/2024
0.0.3 172 4/29/2024
0.0.2 175 4/11/2024
0.0.1 159 4/11/2024