Creating and editing dimension styles (types) with API

Creating and editing dimension styles (types) with API

WhiteSharx
Contributor Contributor
3,291 Views
5 Replies
Message 1 of 6

Creating and editing dimension styles (types) with API

WhiteSharx
Contributor
Contributor

Hello, everybody!

 

Could, please, anyone help me with understanding the workflow for creating a new dimension style and editing an existing one with API?

 

My guess was trying to set a lookup parameter (e. g. Color) of DimensionType object like this

 

            

DT.LookupParameter("Color").Set(125);

 

 

but since there is no constructor for DimensionType object I tried to make an instance of it like this

 

 

Object oDT = new Object();            
DimensionType DT = oDT as Autodesk.Revit.DB.DimensionType; 

Unfortunatelly this cast fails. All the code examples I've seen used an existing DimensionType object getting it from an already placed instance of a dimension. So I'm stuck. My question is how does one obtain the collection of present dimention types (or styles) and change the parameters to needed?

0 Likes
Accepted solutions (1)
3,292 Views
5 Replies
Replies (5)
Message 2 of 6

Mustafa.Salaheldin
Collaborator
Collaborator

Have you tried ElementType.Duplicate Method ??

 

For any system family you have to duplicate a type and customize the new clone.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 3 of 6

WhiteSharx
Contributor
Contributor

Thanks for suggestion Mustafa, but to duplicate smth you have to already have smth, i.e, an instance of ElementType to be duplicated. In other words there is no duplicate method given by intellisence after I put the dot after DimesionType.

 

Some kind of wrong solution would be creating a dimension by method with no explicit DimentionType (then the default one style is used) and use after that the instance to created Dimension and its property Dimension.DimesionType as usual. But some auxiliary references and lines ("garbage") have to be created for this and I belive it's not the genteel way of solving the problem.

0 Likes
Message 4 of 6

Mustafa.Salaheldin
Collaborator
Collaborator
Accepted solution

I guess I should have declared that.

 

please find hereinafter what should have been done:

                FilteredElementCollector DimesionTypeCollector = new FilteredElementCollector(CachedDoc);
                DimesionTypeCollector.OfClass(typeof(DimensionType));

                DimensionType dimesionType = DimesionTypeCollector.Cast<DimensionType>().ToList().FirstOrDefault();
                DimensionType newdimesionType = dimesionType.Duplicate("new dimesionType") as DimensionType;
                newdimesionType.LookupParameter("Color").Set(125);

If this code satisfies your need please don't forget to mark this reply as an answer.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 5 of 6

WhiteSharx
Contributor
Contributor

Thanks a lot, Mustafa! It really works like a charm (inside a transaction)!

 

Little things I'm still worried about:

 

a) according to API documentation using Parameter.LookUp("Parameter Name") method is not a "safe" approach as there could be more than one parameter with such a "Parameter Name"

 

b) Parameter.LookUp() method won't find corresponding "Parameter Name" for local versions of Revit (another language I mean)

 

So the next question is there a more reliable and versatile way to customize DimensionType parameters or is this the only one?

0 Likes
Message 6 of 6

Mustafa.Salaheldin
Collaborator
Collaborator

Try to separately get the GUID of the parameters then in your code use the Element.get_Parameter(Guid).


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes