'Arc' is a type which is not valid in the current context

'Arc' is a type which is not valid in the current context

Anonymous
Not applicable
1,111 Views
7 Replies
Message 1 of 8

'Arc' is a type which is not valid in the current context

Anonymous
Not applicable

Hey guys I am running a test to see if the geometry element I have, is an 'Arc'. 

The code I have at the moment is below: 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using DoorTag;

namespace DoorTag
{
    internal static class DoorArcExtensions
    {
        // get list of doorSwingarcs
        public static List<GeometryElement> GetListOfDoorArcs(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            // have some options 
            Autodesk.Revit.DB.Options opt = new Options();

            // Create a new empty list of arcs
            List<GeometryElement> ListOfDoorArcs = new List<GeometryElement>();

            // Get the list of the geometry objects 
            Autodesk.Revit.DB.GeometryElement geomElem = door.get_Geometry(opt);

            // for each geometry element that is an arc, add that to the list of door arcs
            foreach (GeometryElement geomObj in geomElem)
            {

                if (geomElem == Arc)
                {
                    ListOfDoorArcs.Add(geomElem);
                }

                List<GeometryElement> tempList = ListOfDoorArcs;

                GeometryElement doorArc = tempList[0];

                
            }
            return ListOfDoorArcs;
        }

        // get list of doorSwingarcs
        public static GeometryElement GetDoorArc(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            List<GeometryElement> tempList = DoorArcExtensions.GetListOfDoorArcs(tag);
            GeometryElement doorArc = tempList[0];
                // count the number of items in the list
                int countOfDoorArcs = tempList.Count;
                if (countOfDoorArcs <= 1)
                {
                    if (countOfDoorArcs == 0) // it must be a sliding door or panel
                    {
                        doorArc = tempList[0]; // do nothing 
                    }
                    else // it must be a single door
                    {
                        doorArc = tempList[0];
                    }
                    return doorArc;
                }
                // Test for double or leaf and a half
                else
                {
                     
                    doorArc = tempList[0];

                }
            return doorArc;
        }
    }
}

How ever I am getting the following error message: "'Arc' is a type which is not valid in the current context"

How should I change my code to make sure the it recognises 'Arc' as a type for a geometry element and can test for it?

Kind regards
0 Likes
Accepted solutions (1)
1,112 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

geometryelement.png

From revit SDK,Arc is not inherited from GeometryElement,but Curve is. in the meanwhile, Arc is inherited from Curve,

Now,conclusion is obvious.

we should change "if(geometryEle is Arc)"  to "if(geometry is Curve)"  ,if true, then jude "(geometryEle as Curve) is Arc"

Message 3 of 8

Anonymous
Not applicable

do you mean the I need to change also GeometryElement to GeometryObject? as the screenshot might suggest (very helpful by the way). 

This is what I have so far. 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using DoorTag;

namespace DoorTag
{
    internal static class DoorArcExtensions
    {
        // get list of doorSwingarcs
        public static List<GeometryObject> GetListOfDoorArcs(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            // have some options 
            Autodesk.Revit.DB.Options opt = new Options();

            // Create a new empty list of arcs
            List<GeometryElement> ListOfDoorArcs = new List<GeometryElement>();

            // Get the list of the geometry objects 
            Autodesk.Revit.DB.GeometryElement geomElem = door.get_Geometry(opt);

            // for each geometry element that is an arc, add that to the list of door arcs
            foreach (GeometryElement geomObj in geomElem)
            {

                if (geomElem == Curve)
                {
                    ListOfDoorArcs.Add(geomElem);
                }

                List<GeometryElement> tempList = ListOfDoorArcs;

                GeometryElement doorArc = tempList[0];

                
            }
            return ListOfDoorArcs;
        }

        // get list of doorSwingarcs
        public static GeometryElement GetDoorArc(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            List<GeometryElement> tempList = DoorArcExtensions.GetListOfDoorArcs(tag);
            GeometryElement doorArc = tempList[0];
                // count the number of items in the list
                int countOfDoorArcs = tempList.Count;
                if (countOfDoorArcs <= 1)
                {
                    if (countOfDoorArcs == 0) // it must be a sliding door or panel
                    {
                        doorArc = tempList[0]; // do nothing 
                    }
                    else // it must be a single door
                    {
                        doorArc = tempList[0];
                    }
                    return doorArc;
                }
                // Test for double or leaf and a half
                else
                {
                     
                    doorArc = tempList[0];

                }
            return doorArc;
        }
    }
}

I am not exactly sure how I would tell the curve to be an arc in my list of arc. 

0 Likes
Message 4 of 8

Anonymous
Not applicable

Ok worked on it a little further but still stuck:

 

 // get list of doorSwingarcs
        public static List<GeometryObject> GetListOfDoorArcs(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            // have some options 
            Autodesk.Revit.DB.Options opt = new Options();

            // Create a new empty list of arcs
            List<GeometryElement> ListOfDoorArcs = new List<GeometryElement>();

            // Get the list of the geometry objects 
            Autodesk.Revit.DB.GeometryObject geomObj = door.get_Geometry(opt);

            // for each geometry element that is an arc, add that to the list of door arcs
            foreach (GeometryElement geometry in geomObj)
            {
                if (geometry == Curve)
                {
                    if (geometry == Arc)
                    {
                        ListOfDoorArcs.Add(geomElem);
                    }
                }

                List<GeometryElement> tempList = ListOfDoorArcs;                
            }
            return ListOfDoorArcs;
        }
0 Likes
Message 5 of 8

Anonymous
Not applicable
   public static List<GeometryObject> GetListOfDoorArcs(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            // have some options 
            Autodesk.Revit.DB.Options opt = new Options();

            // Create a new empty list of arcs
            List<GeometryElement> ListOfDoorArcs = new List<GeometryElement>();

            // Get the list of the geometry objects 
            Autodesk.Revit.DB.GeometryObject geomObj = door.get_Geometry(opt);

            // for each geometry element that is an arc, add that to the list of door arcs
            foreach (GeometryElement geometry in geomObj)
            {
                Curve curve=geometry as Curve;   //change
                if ( curve!=null&&curve is Arc)         //change
                {
                   
                    ListOfDoorArcs.Add(geomElem);
                    
                }

                List<GeometryElement> tempList = ListOfDoorArcs;                
            }
            return ListOfDoorArcs;
        }

My English is poor, I'm so sorry i don't express my idea. I modify your code.This is the result code that follows  annotation.I hope you can understand

0 Likes
Message 6 of 8

Anonymous
Not applicable

Thankyou for the new code but I a still getting errors. perhaps the conversion from GeometryObject to GeometryElement is causing the trouble. 

 

I have edited the class even further, but it still needs work. What do you think I should do to make it work? It is saying that the geomElem is not recognised in the context. 

 

public static List<GeometryObject> GetListOfDoorArcs(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            // have some options 
            Autodesk.Revit.DB.Options opt = new Options();

            // Create a new empty list of arcs
            List<GeometryElement> ListOfDoorArcs = new List<GeometryElement>();

            // Get the list of the geometry objects 
            Autodesk.Revit.DB.GeometryElement geomObj = door.get_Geometry(opt);

            // for each geometry element that is an arc, add that to the list of door arcs
            foreach (GeometryElement geometry in geomObj)
            {
                Curve curve = geometry as Curve;   //change
                if (curve != null && curve is Arc)         //change
                {

                    ListOfDoorArcs.Add(geomElem);

                }

                List<GeometryElement> tempList = ListOfDoorArcs;
            }
            return ListOfDoorArcs;
        }

        // get list of doorSwingarcs
        public static GeometryObject GetDoorArc(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            List<GeometryObject> tempList = DoorArcExtensions.GetListOfDoorArcs(tag);
            GeometryObject doorArc = tempList[0];
                // count the number of items in the list
                int countOfDoorArcs = tempList.Count;
                if (countOfDoorArcs <= 1)
                {
                    if (countOfDoorArcs == 0) // it must be a sliding door or panel
                    {
                        doorArc = tempList[0]; // do nothing 
                    }
                    else // it must be a single door
                    {
                        doorArc = tempList[0];
                    }
                    return doorArc;
                }
                // Test for double or leaf and a half
                else
                {
                     
                    doorArc = tempList[0];

                }
            return doorArc;
        }
    }
}

 

 

0 Likes
Message 7 of 8

Anonymous
Not applicable
Accepted solution

Ok so I worked it out. It was just a matter of renaming some of the various GeometryObject and GeometryElement. 

 

using System.Text;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using DoorTag;

namespace DoorTag
{
    internal static class DoorArcExtensions
    {
        public static List<GeometryElement> GetListOfDoorArcs(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            // have some options 
            Autodesk.Revit.DB.Options opt = new Options();

            // Create a new empty list of arcs
            List<GeometryElement> ListOfDoorArcs = new List<GeometryElement>();

            // Get the list of the geometry objects 
            Autodesk.Revit.DB.GeometryElement geomObj = door.get_Geometry(opt);

            // for each geometry element that is an arc, add that to the list of door arcs
            foreach (GeometryObject geometry in geomObj)
            {
                Curve curve = geometry as Curve;   //change
                if (curve != null && curve is Arc)         //change
                {

                    ListOfDoorArcs.Add(geomObj);

                }

                List<GeometryElement> tempList = ListOfDoorArcs;
            }
            return ListOfDoorArcs;
        }

        // get list of doorSwingarcs
        public static GeometryObject GetDoorArc(this IndependentTag tag)
        {
            FamilyInstance door = IndependentTagExtensions.GetTaggedLocalElement(tag);
            List<GeometryElement> tempList = DoorArcExtensions.GetListOfDoorArcs(tag);
            GeometryObject doorArc = tempList[0];
                // count the number of items in the list
                int countOfDoorArcs = tempList.Count;
                if (countOfDoorArcs <= 1)
                {
                    if (countOfDoorArcs == 0) // it must be a sliding door or panel
                    {
                        doorArc = tempList[0]; // do nothing 
                    }
                    else // it must be a single door
                    {
                        doorArc = tempList[0];
                    }
                    return doorArc;
                }
                // Test for double or leaf and a half
                else
                {
                     
                    doorArc = tempList[0];

                }
            return doorArc;
        }
    }
}

            
0 Likes
Message 8 of 8

Anonymous
Not applicable

congratulations on you!!!