Revit failed to execute.

mr.engineer.aec
Advocate

Revit failed to execute.

mr.engineer.aec
Advocate
Advocate

 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.

 

 

New Bitmap Image.jpgScreenshot_2.jpg

0 Likes
Reply
Accepted solutions (1)
1,468 Views
10 Replies
Replies (10)

so-chong
Advocate
Advocate

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.

0 Likes

mr.engineer.aec
Advocate
Advocate

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;
        }
    }
0 Likes

so-chong
Advocate
Advocate
Accepted solution

 

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;

 

 

mr.engineer.aec
Advocate
Advocate

 Thank for your quick help.

My issue is solved by your code.

0 Likes

mr.engineer.aec
Advocate
Advocate

 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.

0 Likes

so-chong
Advocate
Advocate

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!

0 Likes

mr.engineer.aec
Advocate
Advocate

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
Screenshot_1.png

0 Likes

so-chong
Advocate
Advocate

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);
    }
 

planarface.png

0 Likes

mr.engineer.aec
Advocate
Advocate

 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?

0 Likes

so-chong
Advocate
Advocate

Yes, you can do it.

Check Jeremy's reply to your other topic ("Get planarface under element").

Thank you @jeremytammik  for sharing your solution.