Element.Geometry can not return Solid type ??

3,205 views
Skip to first unread message

Tran Ngoc Hien

unread,
Mar 4, 2016, 8:55:01 AM3/4/16
to RevitPythonShell
When i use python in dynamo, just use method Element.Geometry or Element.Solids to get Solid type from element.
But how to use that method in revit python shell ?? I search in google website, someone use C# code below to get solid from element.

a = element.geometry
Autodesk.Revit.DB.Solid b = a as Autodesk.Revit.DB.Solid

So how to convert that code in revit python shell ???

Thanks !!!

Daren Thomas

unread,
Mar 4, 2016, 9:04:01 AM3/4/16
to revitpyt...@googlegroups.com
Did Element.Geometry not work? or Element.Solid?

--
You received this message because you are subscribed to the Google Groups "RevitPythonShell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to revitpythonshe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tran Ngoc Hien

unread,
Mar 5, 2016, 8:53:18 AM3/5/16
to RevitPythonShell
Hi @Daren Thomas
Because i want to get centroid of element, but in the first i must have get solid from element. In dynamo we have method element.geometry or element.solid.
But when i use in revit python shell, element.geometry the result is :

In revit python shell when i use method element.geometry the result return is :


selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
for i in selection:
    print i.Geometry

result is :  <indexer# object at 0x000000000000002B>

So how to get solid of element in API in revit python shell ??

Anyone has idea ??


Vào 21:04:01 UTC+7 Thứ Sáu, ngày 04 tháng 3 năm 2016, Daren Thomas đã viết:

Tran Ngoc Hien

unread,
Mar 7, 2016, 3:38:51 AM3/7/16
to RevitPythonShell
I found the solution for this, but it success when i use dynamo, but not in revit python shell. I attached image below, please advise me.



Vào 20:53:18 UTC+7 Thứ Bảy, ngày 05 tháng 3 năm 2016, Tran Ngoc Hien đã viết:

DeVen

unread,
Mar 7, 2016, 4:57:44 AM3/7/16
to RevitPythonShell
Tran,

This is getting out of hand. You have pestered not one but two online help communities. Nobody is willing to help you because you're constantly asking for a complete solution for things that are either thoroughly detailed or have been discussed and solved ad infinitum.

If you are facing specific problems, describe them in detail and we'd try to help you solve them. Otherwise, do your research!

Do not expect to be spoon fed every single time. If you want to work with the Revit API, please download the Revit SDK documentation and refer to it before posting any API questions online.

If you had checked the API, you would have already found out everything you need to know. You would have also found out that "Convert()" is not a valid API method but an internal Dynamo call.

First of all, your code is failing because you're trying to use an internal method without referencing its library. Also this is a completely unnecessarily step because it would bring you out of the context of the Revit API.

Secondly, even a google search would have given you more than enough information on how to extract an element's geometry:

http://bfy.tw/4cZX

The first link covers in great detail how to extract the geometry of a family instance(beam):

http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-F092BCCC-77E9-4DA9-9264-10F0DB354BF5

and the second that of a system instance (wall):

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-96A0E5EC-D9AD-42F2-901D-CC902ADD0BED-htm.html

If you're still having difficulties after reviewing all of the above, here's another short summary:
  •     create a geometry options instance
  •     fetch the geometry element collection with element.get_Geometry(your options instance)
  •     iterate through the collection and test the object's type to filter out the solids
  •     if the element is a family instance, first extract the instance's geometry element with a method like "g.GetInstanceGeometry()" and then repeat the original iteration to get the solids

You can ask us about specifics on any of the above steps, but please do not ask us to do all your work for you!

Regards,

Dimitar

Tran Ngoc Hien

unread,
Mar 7, 2016, 9:13:25 AM3/7/16
to RevitPythonShell
Thanks for your help, actually i found a  solution to get solid from API, but i stuck at how to force one variable = solid type in python (sory but i'm new in python)
In C# as we know we use :
solid = obj as Solid
but in python i don't know how to use it, In the picture below, i put b = Solid type, but i can get properties Size of solid type or maybe i missing something ?



Vào 16:57:44 UTC+7 Thứ Hai, ngày 07 tháng 3 năm 2016, DeVen đã viết:

DeVen

unread,
Mar 7, 2016, 9:37:26 AM3/7/16
to RevitPythonShell
Now we're getting somewhere!

Ipy is a dynamic language, so we don't really get to do object casting. What you could try to do instead is check the object's type with type(g) (or g.GetType() if you prefer the c# syntax) and evaluate it to the Solid class. Even better, you could use try to use the "isinstance" method.

Tran Ngoc Hien

unread,
Mar 7, 2016, 12:02:06 PM3/7/16
to RevitPythonShell
Now, i can get the solid from element and get centroid.
from Autodesk.Revit.DB import *
import clr
from operator import itemgetter, attrgetter, methodcaller
import System
import clr



selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]

opt = Options()

for i in selection:
    geo = i.get_Geometry(opt)
    for a in geo:
        geo = a.GetInstanceGeometry()
        for g in geo:
            if ( g != None) & (g.Faces.Size >0):
                print g.ComputeCentroid()

But i still not understand the step number 3 you guided :
 -  iterate through the collection and test the object's type to filter out the solids
When i use geo = i.get_Geometry(opt), the result is one GeometryInstance. In my case, i skip the 3rd step, just use method GetInstanceGeometry() and check solid with  if ( g != None) & (g.Faces.Size >0) , then i get the real solid.

Vào 21:37:26 UTC+7 Thứ Hai, ngày 07 tháng 3 năm 2016, Dimitar đã viết:

Dimitar

unread,
Mar 7, 2016, 9:07:42 PM3/7/16
to RevitPythonShell
Have you tried your method on system objects like walls or floors? How about family instances that contain only face or curve geometry? Play around with it some more and you'll start understanding it.

Tran Ngoc Hien

unread,
Mar 7, 2016, 9:48:06 PM3/7/16
to RevitPythonShell
Ok, i will try with this, thanks you very much


Vào 09:07:42 UTC+7 Thứ Ba, ngày 08 tháng 3 năm 2016, Dimitar đã viết:
Reply all
Reply to author
Forward
0 new messages