& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
Hi guys,
I want to use Macro to get area planar of element by pick element.
When build macro in SharpDevelop haven't warning.
But when Run macro, warning visilbe like under picture.
Please help me to solve this issue.
Thank in advanced.
Solved! Go to Solution.
Hi,
This appears to be a runtime error.
You could debug your code or add a try-catch statement to your code to read the error messagebox at which 'line' the error occurs while the macro is running.
The revitdocs shows a nice code example to get faces and edges.
https://www.revitapidocs.com/2020/b45fa881-3077-409c-0ef1-5d42744e7429.htm?section=exampleToggle
Maybe this will point you to the right direction.
I would advise you to post your code inside your message (or use insert 'source code' option) instead of screenshot.
Forum members could help you by testing your code by copy and paste.
Hi @so-chong
Thank for your quick reply, and give me advice when post topic.
The guide in link you give me, i refer and code like under in Visual studio. But when run code, i can't get solid and Message : Don't have any solid visible.
Can you check my code ?
Thank in advanced
[TransactionAttribute(TransactionMode.Manual)] public class CreateEx : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Reference r = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element); ElementId elementId = r.ElementId; Element element = doc.GetElement(elementId); Options opt = new Options(); GeometryObject geoEle = element.get_Geometry(opt); Solid solidEle = geoEle as Solid; if (solidEle != null) { double a = 0; foreach (Face face in solidEle.Faces) { PlanarFace planarface = face as PlanarFace; a += planarface.Area; } } TaskDialog.Show("Message", "Don't have any solid"); return Result.Succeeded; } }
Try this
Reference r = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element); ElementId elementId = r.ElementId; Element element = doc.GetElement(elementId); Options opt = new Options(); GeometryElement geoEle = element.get_Geometry(opt); double a = 0; foreach (GeometryObject geomObj in geoEle) { Solid solidEle = geomObj as Solid; if (solidEle != null) { foreach (Face face in solidEle.Faces) { PlanarFace planarface = face as PlanarFace; a += planarface.Area; } } } TaskDialog.Show("Message", a.ToString()); return Result.Succeeded;
Thank for your quick help.
My issue is solved by your code.
Hi @so-chong
Can you help me to solve this issue.
Now, i can get planarface and origin of planarface of rectangular column.
I want to get planarface, which have Z coordinate value minimum.
I haven't thought of any method yet, can you give me one method to get that planarface ?
Many thanks you.
Hi,
I'm not sure if i understand you correctly.
So basically you would like to have the 'planarface' of a rectangular column, right?
You should be aware that columns are type of family instance, so the geometry is nested one level deeper.
E.g. Walls and floors are not family instances, they have their geometry directly in the first level of the geometry hierachy.
Use the RevitLookup and explore the structure between those types of elements.
So different type of element, different code to approach.
Looking at the Revit API Developer Guide code example (GetAndTransformSolidInfo) you could use the GeometryInstance Class to use the GetSymbolGeometry() Method to obtain the solids from a rectangular column.
Not sure if this is what you are looking for, anyway good luck!
Hi @so-chong
First, many thanks beacause reply my issue.
Sorry because my english isn't good.
I post under picture, under picture have red line, they are the edges of the underside (bottom planarface)
And i want to get only it from all planarfaces of element.
Hope you can help me.
Many thanks
Something like this (macro) ?
public void GetPlanarFace()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
Reference myRef = uidoc.Selection.PickObject(ObjectType.Face,"Select Face" );
Element e = doc.GetElement(myRef);
GeometryObject geomObj = e.GetGeometryObjectFromReference(myRef);
PlanarFace f = geomObj as PlanarFace;
TaskDialog.Show("Element Info",e.Name + Environment.NewLine + f.Area);
}
Hi @so-chong
Your code seem select face.
I want to select element by pick element and return bottom planar face.
Can that be done?
Yes, you can do it.
Check Jeremy's reply to your other topic ("Get planarface under element").
Thank you @jeremytammik for sharing your solution.
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name