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.
5 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)
1 Like