Create a Family Instance Python errors

Hello,

I am using a package node of Springs ꟿ FamilyInstance.ByGeometry
image

with geometry input: Surfaces and Meshes, and I understand it does not like Meshes but Surfaces.

Traceback (most recent call last):
File “”, line 424, in NewForm_background
TypeError: Error in IEnumeratorOfTWrapper.Current. Could not cast: Autodesk.DesignScript.Geometry.Geometry in Autodesk.DesignScript.Geometry.Mesh

Also I got this Python warning:

File “”, line 523, in NewForm_background
UnboundLocalError: Local variable ‘famdoc’ referenced before assignment.

Any workaraound for that?

An UnboundLocalError is raised when a local variable is referenced before it has been assigned. In most cases this will occur when trying to modify a local variable before it is actually assigned within the local scope. Python doesn’t have variable declarations, so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local.

Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they’re declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can’t modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. However, to modify a global variable inside a function, you must use the global keyword.

1 Like