Hi everyone,
I’ve a problem related to my custom dynamo package. I have separated the package into 2 DLLs, one for Zero touch nodes and other for UI nodes, But I want to use the created methods and classes in my Zero touch DLL inside my UI nodes project. I tried to add my zero touch DLL as a reference to my UI nodes project and I actually managed to use the methods I want. However, this makes my packages not appear in dynamo, although I already install it in dynamo and dynamo actually read it as installed package.
Before I referenced my Zero touch node inside UI project, Dynamo was working fine and my package appeared and worked well.
Could any one help me?
Are they in the same solution in Visual Studio? Is the reference set to copy local? If you manually add the DLL does it show up? Anything in your Dynamo log? When you ported things over were they marked as private on implementation? Are you creating a PKG.JSON or just adding the DLLs manually or via build event? If you create a package from the DLLs in Dynamo do thing show up?
You may want to introduce a 3rd class that contains the common methods and allow both the ZT node class and UI node class to call that common class (how I would recommend working if this were something outside of Dynamo), as that will simplify the code a good bit. All 3 DLLs will need to be packaged though.
Hi Jacob,
My 2 DLLs file are in two separate projects. All things were going well until I decided to reference my Zero touch DLL into my UI nodes DLL. when I did that my packages nodes didn’t appear. However, if I open Dynamo while debugging my Zero touch file all nodes appear and work well. but if I open Dynamo while debugging my UI nodes DLL, nothing appears!!
If I tried to load my dll manually through import library command, an error message came up telling me that my request couldn’t be done say “Failed to load library:…”
UI nodes are processed in a different way by Dynamo, it makes it quite complex to work in a ‘normal’ way with Dynamo.
One thing I can imagine what could have happen, is that if your node library is referenced in the UI node library, Dynamo might refuse to load the node library because the found classes are already loaded. Maybe it can help if you change the order in the pkg.json, but I am not sure. I’ve not tested it. Another way is to dynamically load your library in your UI library, so you don’t need references.
Loading an UI library manually in Dynamo, does indeed not work. But what you could do (also not tested) is to build the UI node to the package location where it gets loaded the package way. If that happens in a debug session, or if you attach the acad.exe process to your VS, it might be possible to debug your UI nodes.
Sounds like you’re up against the cross referencing which is causing duplicate loads (as noted by @Anton_Huizinga). I’d recommend moving them to one project if you can as this will simplify things; you may also have to create that ‘shared’ or ‘common’ class library and reference it from each project to simplify the effort.
Thanks all for your reply, actually I tried to change the DLLs order inside the pkg.json file. But, this didn’t change anything. I didn’t get you when you said to dynamically load my library in my UI library., could you clarify more?
if you mean to import my libraries as a package via dynamo, this is actually what I do. I don’t import my libraries manually as UI won’t work that way as you mentioned.
I think the main issue is actually the cross reference as you and @jacob.small mentioned. But I have no idea how to solve it.
Not something I have played with for real so this might not work, but I would start by trying this:
Move to one solution instead of two first. Call it YourPackageName
and that will be your kickoff point for everything in the package.
Then build a common class which both the nodes and the UI will call, call it YourPackageName.Common
.
Then build your UI class (called YourPackageName.UI
), and add a reference to the common class.
THen build the zero touch nodes and call it YourPackageName.ZeroTuch
and add a reference to YourPackageName.Common
.
Then setup your pkg.json to include the YourPackageName.UI
and YourPackageName.ZeroTouch
classes. Then setup your post build event to copy the pkg.json, and all the DLLs over to your Dynamo environment.
If on publish you find that any of your common nodes or the class are visible in the library, use the you can use a [IsVisibleInDynamoLibrary(false)]
flag to suppress exposure.
The Dynamo Unchained tutorial is still my favorite ‘how to’ on this topic: GitHub - teocomi/dug-dynamo-unchained: Dynamo User Group Computational Design Workshop
You can use the Assembly.LoadFrom() method.
Basically, you do something like this:
System.Type assemblyClass = Assembly.LoadFrom(yourFileName).GetType(yourClassName);
MethodInfo methodInfo = assemblyClass.GetMethod(yourMethodName);
object instance = null;
object[] parameters = new object[2]; // If you need two parameters for the method, or null in case none are needed
parameters[0] = ...;
parameters[1] = ...;
object returnValue = methodInfo.Invoke(instance, parameters);
The object which is returned, can be casted as the object you need (string, double, your custom type). This way you load the library dynamically instead of referencing it.
I don’t know what is the impact in Dynamo or on the performance, but you can (should) always test it.
1 Like
can you share a github repo (with build instructions etc) that minimally reproduces the problem?
Big Thanks for this approach. it worked fine!
1 Like
Great to hear! Sort of thing that would be good to get better documentation on @emrullah.yildiz, @solamour, and @achintya_bhat.
2 Likes
Actively working on this right now
1 Like
A half step ahead as always!
1 Like