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: 

Trying to retrieve the DimensionType of a Dimension

5 REPLIES 5
Reply
Message 1 of 6
Alexandra.Nelson
737 Views, 5 Replies

Trying to retrieve the DimensionType of a Dimension

I'm trying to build a ZeroTouchNode with C# in Visual Studio that's input is a Dimension element and it's output is the DimensionType of that Dimension element. It seemed simple, but I'm having trouble returning the DimensionType element. Instead, the node is returning "Autodesk.Revit.DB.DimensionType". How do I retrieve the actual element? My code is included below. Thanks in advance for the help! 

 

using System;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using Autodesk.DesignScript.Runtime;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using RevitServices.Persistence;


namespace CustomNodes
{

    public class Dimensions
    {
        private Dimensions()
        {
        }
        public static ElementType GetDimType(Revit.Elements.Element dimensions)
        {

            Document doc = DocumentManager.Instance.CurrentDBDocument;

            Element UnwrappedElement = dimensions.InternalElement;

            ElementId id = UnwrappedElement.GetTypeId();

            ElementType dimType = doc.GetElement(id) as ElementType;

            return dimType;

        }

    }
}
5 REPLIES 5
Message 2 of 6

You code looks perfectly fine to me.

 

Probably, there is a misunderstanding involved.

 

The DimensionType IS the actual element.

 

Maybe your target does not expect an Element instance at all, just the ElementId.

 

Therefore, you might be able to just return `id` and skip the call to `GetElement`.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6

Thank you Jeremy. When I try to return the id, it returned the id of the dimension type, but not the dimension type element. Also, when I tried to return the element using the "Get Element" method and changed the return type to "Element" (as seen below) rather than "ElementType" as I had previously, it still gives me the same output.

 

using System;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using Autodesk.DesignScript.Runtime;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using RevitServices.Persistence;


namespace theWorks
{

    public class Dimensions
    {
        private Dimensions()
        {
        }
        public static Element GetDimType(Revit.Elements.Element dim)
        {

            Document doc = DocumentManager.Instance.CurrentDBDocument;

            Element UnwrappedElement = dim.InternalElement;

            ElementId id = UnwrappedElement.GetTypeId();

            Element dimType = doc.GetElement(id) as Element;

            return dimType;

        }

    }
}

dynamo example.png

Message 4 of 6

Well, if the DimensionType element is wrong, and the element id is wrong, then something else is hopefully right.

 

Unfortunately, I cannot imagine what, and you give no hint either.

 

In desperation, it might be worthwhile to read the documentation (of what, actually? is there any?) and find out what it is we are actually trying to achieve...

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 6
FAIR59
in reply to: Alexandra.Nelson

You can not directly return a Revit class. You need to "wrap" into a Dynamo wrapper class.

see https://forum.dynamobim.com/t/become-a-dynamo-zero-touch-c-node-developer-in-75-minutes/28007 

and download the handout

Message 6 of 6
Alexandra.Nelson
in reply to: FAIR59

Thank you for your help and for sharing the link with me. I worked through the concepts in that handout and got it working.

 

Here's the working script :

using Autodesk.Revit.DB;
using RevitServices.Persistence;
using Revit.Elements;

namespace theWorks
{

    public class Dimensions
    {
        private Dimensions() { }

        public static Revit.Elements.Element GetDimType(Revit.Elements.Element dimension)
        {

            Document doc = DocumentManager.Instance.CurrentDBDocument;

            Autodesk.Revit.DB.Element UnwrappedElement = dimension.InternalElement;

            ElementId id = UnwrappedElement.GetTypeId();

            ElementType dimType = doc.GetElement(id) as ElementType;

            return dimType.ToDSType(false);

        }

    }
}

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community