I couldn’t find “get_Geometry” method in revitapidocs. But it is functioning in python. From where those codes coming from. Please help.
@shibujoseukken , hi
Dynamo is not pure python, espacily the “get_…” is from C#…
KR
Andreas
check out!
Is there any alternative for get_ functions?
in which context? python, dynamo, designscript ?
python which we can use in Dynamo or where i can find get_ based functions? It is not available in revitapidocs.com.
Hi @shibujoseukken.
As I know get_Geometry
is a method of Revit Python Wrapper
.
def get_element(self, wrapped=True):
""" Element of Reference """
element = self.doc.GetElement(self.id)
return element if not wrapped else Element(element)
def get_geometry(self):
""" GeometryObject from Reference """
ref = self._revit_object
return self.doc.GetElement(ref).GetGeometryObjectFromReference(ref)
https://revitpythonwrapper.readthedocs.io/en/latest/db/reference.html?highlight=get_Geometry
Hello,
The methods prefixed by a lowercase get_
are automatically generated getter methods (properties).
.NET properties are backed by a pair of .NET methods for reading and writing the property.
The C# compiler automatically names them as get_<PropertyName>
and set_<PropertyName>
So, in Python (with .Net), a property that has a parameter can be written like this (2 ways)
opt = Options()
geo_set = element.get_Geometry(opt)
## OR
opt = Options()
geo_set = element.Geometry[opt]
as per revitapidocs, the function name is GeometryElement. But in the example, they eliminated ‘Element’. How do we know whether we need to eliminate it or not.
GeometryElement
is the type of the return value (Geometry
property)
The property is called Geometry
, so that’s what we use when calling it. What that property stores, and what we retrive by using the get_
prefix, is a GeometryElement
.
This is a bit more obvious in the C# example lower down on that page. Specifically this line:
Autodesk.Revit.DB.GeometryElement geomElem = beam.get_Geometry(options);
In C# you have to declare what type of object you are going to assign to a variable, whereas in Python, this is handled for us automatically.
As a result, we can think of that line of code in two steps:
-
Autodesk.Revit.DB.GeometryElement geomElem
We tell the computer that the variablegeomElem
is going to be aGeometryElement
. If we try to assign it a different object type - string, integer, ElementId, etc. - it will throw an error. -
geomElem = beam.get_Geometry(options);
We assign our variablegeomElem
the value stored in thebeam
object’sGeometry
property, which is aGeometryElement
.
Generally speaking, if you see get
in the syntax section of a property like we do here, you can retrieve what that property stores by putting .get_
in front of the name of that property - in our case Geometry
.
You were too fast for me haha