Custom guide of Dynamo node-packages developer (from .NET API)

Hello all developers, who have been write or only will write any code via .NET API to Dynamo’s environmental. In this article I wanted talk about principal features about developing to Dynamo’s environmental (by myself experience to developing packages for Civil 3D and for some non-Autodesk software via COM API). It can be prevented you of some knows errors when compiled library imported to Dynamo (unable to load library without concrete reasons). Info about will useful in any Dynamo packages (for ProtoGeometry , Civil 3D, Revit and other platforms).

  • Dynamo’s nodes libraries support object-oriented conception of programming and there will a best practice, if your package will contains Classes, Fields, Methods;

  • The main idea of new package - to minimize logic of some standard nodes and your created Classes and Methods must have functionality to it;

  • With .NET API you have full-access to target application (f.e. to Revit or Civil 3D and can write code without any limitations, as in Python-scripts (problems with casting, new statements, nested functions and etc.);

  • Because of Dynamo is user-orientated environmental, all arguments in Constructors and Methods (and returned values) are must casted to standard types or types by it’s package (you must no use all ‘standard’ classes such as FileInfo, Directory, DBObject and etc.);

  • You must remove from source code (arguments) all ref, out instructions, because it can contradicts Dynamo’s logic;

  • Don’t afraid to use object and dynamic types, in some cases it’s good idea;

  • There are no logic of inheritance in Dynamo and for each “parent” class you need have a static Constructor that have argument with dynamic typization (for nested classes casting);

  • There are no necessity to create Dictionaries or Lists with any used Enums. It’s enough to write one of Enum values in arguments and all other values are catch up too;

  • If you create new package as wrapper of any Autodesk Software .NET API objects, you should not use in internal or private fields the opened objects without Transactions, because it can create a Fatal error; if you use any other .NET library, you can place original class in public field and mark it with that instructions to don’t show in Dynamo’s tree:

[Autodesk.DesignScript.Runtime.IsVisibleInDynamoLibrary(false)]

If you create a wrapper of COM-server, you may no use attribute above, because Interfaces are no showing in Dynamo’s tree;

  • The great approach, if you adding at least in Class Constructors auxiliary instructions to Cast classes to need type (to prevent any errors);

  • Also the good practice using standard C# Exceptions f.e. throw new System.Exception("Invalid casting");

  • (!) If you create a wrapper of COM-Server and one of method contains an argument with optional flag, parent interface need have a dynamic type, because Dynamo can’t read optional arguments (that have object or dynamic typization);

If you want create a node library as wrapper of any COM server, you can use that my librarythat my library (read instructions in it’s readme). One of packeges that I create with that logic is Link_COM_Acad.

  • [update on 05.10.2023] There must no predefined enum-type arguments!;
  • [update on 05.10.2023] If there is a necessity to set null-value of one of arguments; create new function without that argument, because Dynamo’s null is not a null in C#;
  • [update on 05.10.2023] there are no properties in Dynamo: code below need split to two functions (names are free):
// In snandard library
public string Text {get; set}
// In wrapper-library
private string _text;
public void SetText (string text) => this._text = text;
public string GetText => this._text;

About updating packages.

A long time the only way to update user’s packages - it’s run any Autodesk product with integrated Dynamo’s environmental (Revit, Civil 3D and etc) and publish versions by manual mode. In newest DynamoSandbox versions there are authentication mechanism that let do it without other Autodesk’s software, but I couldn’t successfully try it. You can edit Post build events for your node-package source code (via VS 2022 as example) and copy binary data in Release-mode to packages directory for target Autodesk’s software what used as ‘host’-product.

6 Likes

I don’t know if this is accurate. What is the issue you see with it?

If I create next form of class constructor (https://github.com/GeorgGrebenyuk/Dyn_ActiveX_ACAD_and_C3D/blob/36b9d73643ab4eeb4419eea75be25ee60a6cef61/src/Link_COM_Acad/ACAD/AcadHatch.cs#L36C7-L36C7):

I’m getting next error in Dynamo’s console:

IronPythonExtension (id: D7B449D7-4D54-47EF-B742-30C7BEDFBE92) extension is added
Build error for library: C:\Users\user\AppData\Roaming\Autodesk\C3D 2023\Dynamo\2.13\packages\Link_COM_Acad\bin\Link_COM_Acad.dll
Invalide Input type to make AST node
Failed to load library: C:\Users\user\AppData\Roaming\Autodesk\C3D 2023\Dynamo\2.13\packages\Link_COM_Acad\bin\Link_COM_Acad.dll
notification:Dynamo.Exceptions.LibraryLoadFailedException: Failed to load library: C:\Users\user\AppData\Roaming\Autodesk\C3D 2023\Dynamo\2.13\packages\Link_COM_Acad\bin\Link_COM_Acad.dll:
Failed to load library: C:\Users\user\AppData\Roaming\Autodesk\C3D 2023\Dynamo\2.13\packages\Link_COM_Acad\bin\Link_COM_Acad.dll:
Build error for library: C:\Users\user\AppData\Roaming\Autodesk\C3D 2023\Dynamo\2.13\packages\Link_COM_Acad\bin\Link_COM_Acad.dll
Invalide Input type to make AST node
Dynamo.Exceptions.LibraryLoadFailedException:
Failed to load library: C:\Users\user\AppData\Roaming\Autodesk\C3D 2023\Dynamo\2.13\packages\Link_COM_Acad\bin\Link_COM_Acad.dll

There you can see Invalide Input type to make AST node that inform about that (I found that only in manual mode)

I think you have to call for the enumerator via the default argument parameter instead of setting it with equality - the equivalent of [DefaultArgument("Vector.ByCoordinates(0,0,0);")] inputVector, but for the design script means of calling your enumerator and your variable name.

Hmmmm, I read that a few times, but unfortunately can’t understand that. It’s not a problem for me (for case with predefined enum-data),I only reported it as ‘problem place’ where Dynamo crashes in process of initialize library