Python node fails to call DesignScript function

When using Dyn nodes in Python nodes, is the function expression the same as DesignScript? When I use Geometry and List, Python nodes often report errors.
Attached is my python code


Py問題.txt (1.6 KB)

Try using len(RoomSur) instead.

Thank you, but the problem of Geometry failure cannot be solved with Python’s own syntax.

I was offering you an alternative. If you want the length of the list, why not use Python’s length?

When there is a Python syntax you should use that instead of the Dynamo equivalent. The reason being is that Python’s methods are optimized for Python, while Dynamo’s methods are optimized for Dynamo and as such Python has to convert everything to a Dynamo object type first by calling a .net method, then make a call to another .net method to do the actual task. You’re asking the computer to do 4x the work.

The geometry issue isn’t with Python failing to load, but with your resulting geometry being invalid. If you test this with nodes does it work well?

At the moment we don’t have the data is coming into the ObsGeo input so we can’t really diagnose anything. Best to provide the full .dyn and a dataset and the community can take a look, but if any geometry becomes invalid your entire method will currently fail based on how you’re building your code. Some degree of error handling for invalid geometry is recommended for robustness.

Hello, all the files are here
But I have a question, why can the result be successfully output using the Dyn node directly, but using Python will cause the resulting geometry to be invalid?
In addition, warnings often appear for element.Geometry nodes, but this should not cause the results of Dyn and Python to be different, right?

Thank you very much

Files

This will cause the results to be different, as Dynamo has built in error handling that you haven’t integrated. This also answers your other question, but less directly.

Depending on how content is generated (sweep vs extrusion), what it’s source is (in the same function vs moved from memory) and how your environment is configured (IronPython3 vs CPython3 vs IronPython2, which version of the geometry library, geometry scaling, etc.) you’ll get different results.

Geometry in design is an art, not a science.

I have quite a few presentations to finish working on, but will try to look into the files later.

1 Like