Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit failed to execute.

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
mr.engineer.aec
1126 Views, 10 Replies

Revit failed to execute.

 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

10 REPLIES 10
Message 2 of 11
so-chong
in reply to: mr.engineer.aec

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.

Message 3 of 11
mr.engineer.aec
in reply to: so-chong

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;
        }
    }
Message 4 of 11
so-chong
in reply to: mr.engineer.aec

 

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;

 

 
Message 5 of 11
mr.engineer.aec
in reply to: so-chong

 Thank for your quick help.

My issue is solved by your code.

Message 6 of 11

 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.

Message 7 of 11
so-chong
in reply to: mr.engineer.aec

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!

Message 8 of 11
mr.engineer.aec
in reply to: so-chong

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

Message 9 of 11
so-chong
in reply to: mr.engineer.aec

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

Message 10 of 11
mr.engineer.aec
in reply to: so-chong

 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?

Message 11 of 11
so-chong
in reply to: mr.engineer.aec

Yes, you can do it.

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

Thank you @jeremytammik  for sharing your solution.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community