How to use BimorphNodes in Python?

Hi everyone,

I want to use @Thomas_Mahon 's BimorphNodes package within a python node. The issue is that I cannot use any nodes of this package.

To access the package, I appended the path similar to what @Konrad_K_Sobon did here: Access Dynamo's Package Paths from Python
for testing, I just hardcoded the path. I also tried the “\extra” folder.

import sys
import clr
clr.AddReference('ProtoGeometry') 
sys.path.append(r'C:\Users\username\OneDrive\packages\bimorphNodes\bin') #folder path for package 
import BimorphNodes2018 as bm

When I return “bm”, I get a “Python.Runtime.ModuleObject”, which is similar to the output for other packages. However, if I want to use a function (Curve.IntersectAll()), I get the error: "name ‘Curve’ is not defined "(1.Option) and “AttributeError: Curve” (2.Option).

l1 = IN[0][0] # line 1
l2 = IN[0][1] # line 2
intp = Curve.IntersectAll([l2,l1])       #1.option
intp = bm.Curve.IntersectAll([l2,l1])      #2.option

I discovered that there is no namespace defined in this package, and I’m not sure if this is causing the problem. Is there a way to use the function without a namespace, or am I doing it wrong anyway?

I hope you can help me.
Thanks in advance.

Hi @philipp.stuhler

Change your import statement to this:

sys.path.append(r'C:\Users\username\OneDrive\packages\bimorphNodes\bin')
import BimorphNodes
from BimorphNodes import *
  • Use BimorphNodes namespace for anything in the top level of the node library.
  • BimorphNodes.Results namespace for the results types.
  • BimorphNodes.Revit namespace for the Revit types.
6 Likes

Hi @Thomas_Mahon
thanks for your fast reply.

I changed the import statement and tried it again, but I get the same error.
“name ‘Curve’ is not defined”.

sys.path.append(r'C:\Users\username\OneDrive\packages\bimorphNodes\bin')
import BimorphNodes
from BimorphNodes import *
l1 = IN[0][0] # line 1
l2 = IN[0][1] # line 2
intp = Curve.IntersectAll([l1,l2])

For Revit and result types it works, but I cannot use the IntersectAll() function. I don’t know what I’m doing wrong.

1 Like

Try qualifying the class:
intp = BimorphNodes.Curve.IntersectAll([l1,l2])

Sorry for replying so late. I tried it like this too. And it is still not working.
Error: “AttributeError: Curve”

@philipp.stuhler

You need to:

  1. Import the class directly. This is because the class has no namespace (which is not good but Dynamo creates the menu items from namespaces in zero touch libraries, so I had to omit it to prevent superfluous menu categories from appearing).
  2. Give it an alias so it doesn’t clash with Curve in ProtoGeometry or the RevitAPI.
  3. Declare a C# list.
  4. Call Curve.IntersectAll and pass in the C# list. Just remember to replace Curve with your alias.
import clr
import sys

clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from System.Collections.Generic import *

sys.path.append(r"C:\Users\[USER NAME]\AppData\Roaming\Dynamo\Dynamo Revit\2.10\packages\bimorphNodes\bin")
clr.AddReference("BimorphNodes")
import BimorphNodes as bm
import Curve as bmCurve

#Uncomment the line below to enable the first input
l1 = IN[0]
l2 = IN[1]
# "Start" the transaction
#TransactionManager.Instance.EnsureInTransaction(doc)

# "End" the transaction
#TransactionManager.Instance.TransactionTaskDone()

#Uncomment the line below to output an object

list = List[Curve]()
list.Add(l1)
list.Add(l2)

OUT = bmCurve.IntersectAll(list)
4 Likes

Thankyou for your response @Thomas_Mahon but while using the same how do we access CAD functions??


i was using the same as u mentioned above but getting error no module with that name so if u could shed some light…??

Because you imported BiMorphNodes as ‘bm’, now you have to call it using ‘bm’.

So use OUT = dir(bm) and you should be all set.

@jacob.small as bm that’s commented out and even in the dir u can see the output here

1 Like

And under nodes you see?

OUT = dir(bm.Nodes)

Repeat until you have a handle on how the codebase is structured.

3 Likes

It does not load for me, why? I am using Dynamo 2+ of Revit 2021

Have you updated your user name in the path?

EDIT, your screenshot does show your name. Make sure bimorphNodes is installed in the 2.6 folder.

Yes, the screenshot shows where is the dll file installed in my computer for the dynamo version and package version, file path is different than the example in this post as you can see because i didn’t find any folder in my computer with the package, i think should work as it is