Test the type of geometry

Hello, I have a list [p, c, []] where p is a point, and c is a curve
How can I get create a Boolean condition to get [true, false, false]?
Also, are there other tests that can filter different geometries? Thanks!

@marcusqwj You can use Object.Type to get the type and then you can filter based on your requirements. Here is the sample…

Thank you!

Is there a way to test it in Python Script?
Is Dynamo’s Python syntax is slightly different from the usual Python syntax? I’m usually able to use ‘type(a)’ to output the type, but it doesn’t seem to work in Dynamo

In python it may actually work faster than to convert to some text showing the type name and then testing on that. You could do the same thing there, but there’s a better alternative.

Standard python comes with the isinstance function. As an example:

In that the Python Code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.

#Assign your output to the OUT variable.
OUT = map(lambda val: isinstance (val, Point), IN[0])

Notice I’m using the map function to run across the input list. And I’m sending it a function I write directly there as a lambda. I could have done it this way instead:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.

def isPoint (val):
    return isinstance (val, Point)

#Assign your output to the OUT variable.
OUT = map(isPoint, IN[0])\

Otherwise I could also used a more imperative way to loop over the values, generating a new list. E.g.:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.

result = list()
for val in IN[0]:
    result.Add(isinstance(val, Point))

#Assign your output to the OUT variable.
OUT = result
1 Like

You’re correct. The issue is in Dynamo’s Python you’re actually using IronPython. And the type function there actually returns a IronPython.Runtime.Types.PythonType.

BTW, it is rather sad that DesignScript does not include the is or typeof keywords. In many ways DesignScript is very similar to C#, but those two omissions means this particular problem doesn’t work as easily as it could have.

1 Like