Getting Arc curve in Family instance

Getting Arc curve in Family instance

mizrachi_amir2
Advocate Advocate
586 Views
9 Replies
Message 1 of 10

Getting Arc curve in Family instance

mizrachi_amir2
Advocate
Advocate

Hello,

 

I have a Detail Item family which is composed of lines, solid, and and an Arc as can be seen in RevitLookup snoop below:

mizrachi_amir2_0-1727861806509.png

 

Using this code ("detail" variable is casted from Element to FamilyInstance):

Options geomOptions = new Options();
geomOptions.DetailLevel = ViewDetailLevel.Fine;
geomOptions.IncludeNonVisibleObjects = true;

FamilyInstance familyInstance = detail as FamilyInstance;
if (familyInstance != null)
{
    GeometryElement symbolGeom = familyInstance.Symbol.get_Geometry(geomOptions);
    if (symbolGeom != null)
    {
        foreach (GeometryObject geomObj in symbolGeom)
        {
            if (geomObj is Solid solid)
            {
                Debug.WriteLine("Solid");
            }
            else if (geomObj is Curve curve)
            {
                if (curve is Line line)
                {
                    Debug.WriteLine("Line");
                }
                else if (curve is Arc arc)
                {
                    Debug.WriteLine("Arc");
                }
            }
        }
    }
}

 

I get the following output:

Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Line
Solid

 

I tried also

GeometryElement instanceGeom = familyInstance.get_Geometry(geomOptions);

but it returns null.

 

What am I doing wrong?

 

Thank you!

 

0 Likes
Accepted solutions (1)
587 Views
9 Replies
Replies (9)
Message 2 of 10

jeremy_tammik
Alumni
Alumni

The safest way to find out is to run RevitLookup in the debugger and step through the code line by line to see which exact API calls and arguments are being used.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 10

mizrachi_amir2
Advocate
Advocate

So I tried to do that as follows (in Revit 2021):

1. Installed Add-In Manager

2. Loaded RevitLookup.dll from my %appdata% Addin folder path

3. It loaded the following

mizrachi_amir2_0-1727970464823.png

 

4. I opened solution of RevitLookup in VS and ran "Attach to Process.."

 

But nothing is triggered in the code (I put some breakpoints) once selecting my family and hit on Add-In manager (Manual Mode) --> RevitLookup.CmdSnoopModScope --> Run

 

 

Anything I am doing wrong? 

 

0 Likes
Message 4 of 10

ewano
Advocate
Advocate

What is the construction of the family?

Are you attempting to extract the defined Type Geometry or Instance Geometry?

Are you able to provide more information on the construction of the Family? Nested items, Visibility Settings, etc?

Cheers,


Ewan



Autodesk ITF 2018-2020 / Senior Project Drafter / Technical & Computational Modelling Specialist / Dynamo Enthusiast

0 Likes
Message 5 of 10

mizrachi_amir2
Advocate
Advocate

Family category is 'Detail Item' so only 2D views are available.

I am trying to extract its Instance Geometry but always receive back a null.

This is how the family looks like in general (sorry but I cannot share it) - I am trying to extract that highlighted circle:

mizrachi_amir2_0-1728245412377.png

 

0 Likes
Message 6 of 10

ewano
Advocate
Advocate

So the Circle is not Visible. 

The setting to 'IncludeNonVisibleObjects' appears to not include the Detail Line in the list of defined Non-Visible items, which you would think was the expected behaviour 🤔, a slight tweak to the construction of the Family may be needed. If this circle is not required to be ever shown then convert it to a 'Reference Line' circle, and this will be able to be extracted as an 'Arc' definition as per your original code.

Cheers,


Ewan



Autodesk ITF 2018-2020 / Senior Project Drafter / Technical & Computational Modelling Specialist / Dynamo Enthusiast

Message 7 of 10

mizrachi_amir2
Advocate
Advocate

Thank, @ewano.

I tweaked the family a bit and now it seems to be working.

 

[EDIT]:

Not working yet.

Obviously I need the Arc of the family instance and not the symbol.

But this line of code (no matter what I do) returns null:

GeometryElement instanceGeom = familyInstance.get_Geometry(geomOptions);

 

I just wanted to know if using the "Attach to process.." using VS and Revit - why I can't see any Debug messages on my VS console?

Breakpoints are reached but Debugs are not printed out. 

0 Likes
Message 8 of 10

ewano
Advocate
Advocate

It is likely that there is an issue with your Family construction. Are you able to provide it? Even if it is a stripped down version. Using your original code within VS gives the expected outputs.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;

namespace RevitTools
{
    [Transaction(TransactionMode.ReadOnly)]
    public class GetElementGeometryCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            try
            {
                // Get the selected element
                Reference selectedRef = uidoc.Selection.PickObject(ObjectType.Element, "Select a family instance");
                Element selectedElement = doc.GetElement(selectedRef);

                if (selectedElement is FamilyInstance familyInstance)
                {
                    GetElementGeometry(familyInstance);
                    TaskDialog.Show("Success", "Element geometry analysis completed. Check the output window for results.");
                    return Result.Succeeded;
                }
                else
                {
                    TaskDialog.Show("Error", "Please select a family instance.");
                    return Result.Failed;
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }

        private void GetElementGeometry(FamilyInstance detail)
        {
            Options geomOptions = new Options
            {
                DetailLevel = ViewDetailLevel.Fine,
                IncludeNonVisibleObjects = true
            };

            GeometryElement symbolGeom = detail.Symbol.get_Geometry(geomOptions);
            if (symbolGeom != null)
            {
                foreach (GeometryObject geomObj in symbolGeom)
                {
                    if (geomObj is Solid)
                    {
                        Debug.WriteLine("Solid");
                    }
                    else if (geomObj is Curve curve)
                    {
                        if (curve is Line)
                        {
                            Debug.WriteLine("Line");
                        }
                        else if (curve is Arc)
                        {
                            Debug.WriteLine("Arc");
                        }
                    }
                }
            }
        }
    }
}

ewano_0-1728423202920.png

As for attachment for Debug output, I think we would need to see your Add-In code setup. Did you developing start your Add-In from an online template you are able to reference?

Cheers,


Ewan



Autodesk ITF 2018-2020 / Senior Project Drafter / Technical & Computational Modelling Specialist / Dynamo Enthusiast

0 Likes
Message 9 of 10

ricaun
Advisor
Advisor
Accepted solution

In the image you are selection the Document.ActiveView, in your code you are not doing that.

 

ricaun_0-1728424071599.png

 

Some detail inside the family is only possible to get the geometry if you have the correct view, like a symbol in a electrical family is only visible in a floor view.

 

Try to change the Options like:

 

Options geomOptions = new Options();
geomOptions.View = uiapp.ActiveUIDocument.ActiveView;

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 10 of 10

mizrachi_amir2
Advocate
Advocate

Thank you, @ewano.

The solution suggested below by @ricaun solved my issue 💪

 

As for my Revit add-in and attachment for debugging - my addin is based on a template of Nice3Point

0 Likes