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: 

How to get dimension's types available in a project, using the Revit API

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
yann_geay
497 Views, 7 Replies

How to get dimension's types available in a project, using the Revit API

Hi everyone,

 

My previous post went unanswered, so I turned to a new solution for creating my dimensions, and I have a new problem. I can't select the dimension types present in my Revit project. To be precise, my Revit project is empty, and it's the dimension types I can use that I want to retrieve (there are some in my project), not the potential dimension types that already have an occurrence in my project.
Here's the associated code section:

 

 

 

 

 

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
UIDocument uidoc = revit.Application.ActiveUIDocument;
Document doc = uidoc.Document;

FilteredElementCollector collector = new FilteredElementCollector(doc);
FilteredElementCollector Elements = collector.OfCategory(BuiltInCategory.OST_Dimensions).WhereElementIsElementType();

bool hasElements = Elements.Any();

if (!hasElements)
{
MessageBox.Show("doesn't have elements");
}
else{
MessageBox.Show("Has elements");
}
return Result.Succeeded;
}

 

 

 

 

Revit returns "doesn't have elements", when i run my project.
Is there another way to select my dimension's types ?


Thank you in advance for your help.

7 REPLIES 7
Message 2 of 8
jeremy_tammik
in reply to: yann_geay

Do you see them when you snoop the database using RevitLookup and other db exploration tools?

  

I should expect and hope so.

  

Are they derived from ElementType? Is their category OST_Dimensions?

  

I would expect that also.

  

I do not see anyobvious problem with your code, so it is a mystery, but maybe snooping around a bit will help clear it up.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 8
yann_geay
in reply to: jeremy_tammik

I didn't know the existence of RevitLookup before your answer. But it seems like a realy usefull tool !
After running it, i see my Dimension's Types in RevitLookup indeed.

 

The Revit API seems to say so, yes. But i don't know other way to verify that. OST_Dimensions also exist for the Revit API.

 

Btw, I saw that you had participated in the publication of this plugin, and I also saw that you managed to select faces and corners in it. I'd like to ask permission to look into the code of this plugin to understand how to do this.
(This was partly the reason for my previous post, which I mention at the beginning of this one)

Message 4 of 8
jeremy_tammik
in reply to: yann_geay

Thank you for your appreciation. Glad to hear that you like it. I must say, I am shocked that you were not aware of it previously. Yes, of course you can look into the code and make free use of it in any way you like. It is open source. You need to look at the license agreement. It will tell you all you need to know about such limitations. This applies to all open source code, all code in general, all human activities whatsoever. Copyright, protection, sharing or not.. Long live the creative commons!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 8
FAIR59
in reply to: yann_geay

Yes there is another way to find dimensiontypes.

First get the default dimensiontype, and from that type find the similar ones.

			DimensionType defaulttype = doc.GetElement( doc.GetDefaultElementTypeId(ElementTypeGroup.LinearDimensionType)) as DimensionType;
			foreach(ElementId id in defaulttype.GetSimilarTypes())
                        // similartypes includes the defaulttype
			{
				DimensionType _type = doc.GetElement( id) as DimensionType;
				...
			}

 

Message 6 of 8
mhannonQ65N2
in reply to: yann_geay

Looking at the attached RevitLookup screenshot, the DimensionType's Category property is null. Perhaps this is why your filter fails; the DimensionType doesn't actually have a category. Maybe using the OfClass method with DimensionType instead of the OfCategory method will work.

 

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
	UIDocument uidoc = revit.Application.ActiveUIDocument;
	Document doc = uidoc.Document;

	FilteredElementCollector collector = new FilteredElementCollector(doc);
	FilteredElementCollector Elements = collector.OfClass(typeof(DimensionType));

	bool hasElements = Elements.Any();

	if (!hasElements)
	{
		MessageBox.Show("doesn't have elements");
	}
	else{
		MessageBox.Show("Has elements");
	}
	return Result.Succeeded;
}

 

Message 7 of 8
yann_geay
in reply to: FAIR59

After several tries, I have indeed managed to get a satisfactory result with this method.
It doesn't explain why I can't get my Dimension category using types, but it's a good substitute.

 

Thank you very much for this solution.

Message 8 of 8
yann_geay
in reply to: mhannonQ65N2

The method I was using works with other categories, such as walls. So I thought it would work the same way for dimensions.
I'm happy with FAIR59's solution, but I'm going to try yours too, to give myself a few options and to understand my mistake.
Thanks for your help.

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

Post to forums  

Forma Design Contest


Rail Community