Problem with get_element in API 2016

Problem with get_element in API 2016

Anonymous
Not applicable
488 Views
2 Replies
Message 1 of 3

Problem with get_element in API 2016

Anonymous
Not applicable

Hi!

 

I'm new programming with REVIT API. I'm trying transform this code who was made with the API 2014 to API 2016.

 

This is the code:

 

public bool AllowElement(Element elem)
{
  return elem.get_Category().get_Id().get_IntegerValue() == -2000051;
}

 

The undelined word marks an error.

 

Can someone help me please!.

 

Best!

0 Likes
Accepted solutions (1)
489 Views
2 Replies
Replies (2)
Message 2 of 3

rosalesduquej
Alumni
Alumni
Accepted solution

Dear Carlos, 

 

Could you help me out explaining a bit on what are you trying to return ? or what does that method returns? 

If I understand it is returning an element id with the integervalue = -2000051, 

 

I don't think I've seen the use of Category like that before. You can take a look at this post by Jeremy Tammik, who is one of my teammates and an expert with Revit API, which could help you a lot with the development of Revit API for future reference. 

http://thebuildingcoder.typepad.com/blog/2010/05/categories.html

 

Can you try something like this 

 

public bool AllowElement(ElementId elem)

        {

            return elem.IntegerValue == -2000051;

        }

 

Just notice that now in the parameter the ElementId is what is getting passed. 

 

or 

 

public bool AllowElement(Element elem)

        {

            return elem.Id.IntegerValue == -2000051;

        }

 

So you don't have to change the parameter that is getting passed. 

 

Try it and confirm with me that my assumption was correct please. 

 

Hope this helps you out. 

 

 

Ps. here is a couple of links for the start of your revip API development that can come in handy 🙂 

 

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=16849339

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

http://adndevblog.typepad.com/aec/

 

Cheers,



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
0 Likes
Message 3 of 3

Revitalizer
Advisor
Advisor

Hi Jaime,

 

Carlos wants to filter Elements by category, he does not want to filter a single Element having this special Id value.

As you can see, it is a negative value (because he compares a BuiltInCategory enum value).

 

I think the error occurrs because the Category of an Element may be null.

 

It would be helpful if Carlos could verify that by specifying the exception.

Thus, the solution would be to check if an element's Category property is not null before acessing its Id and IntegerValue.

 

 

Revitalizer

 

P.S.: Why tagging a posting as "solution" if you write at the same time:

 

"Try it and confirm with me that my assumption was correct please. Hope this helps you out."

 

Has Carlos already confirmed this working as expected ?




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes