How to filter and assign View Template

How to filter and assign View Template

Arciviz
Advocate Advocate
5,876 Views
5 Replies
Message 1 of 6

How to filter and assign View Template

Arciviz
Advocate
Advocate

How to filter User Specified View Template ID?

I Have my own view template named "KJRebarSection"

How to find "KJRebarSection" 's Template ID as Element ID.

 

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

aignatovich
Advisor
Advisor

Hi!

 

First of all, take a look at Revit API starter materials: http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

You'll see, how to search anything in Revit model, using FilteredElementCollector class.

 

Cheers!

0 Likes
Message 3 of 6

Arciviz
Advocate
Advocate

I have try But No use

 

ViewSection viewsec = KJU.CreateSectionAtBottomAndRight(doc , elem, 2, 2 );

BuiltInParameter viewtemppara = BuiltInParameter.VIEW_TEMPLATE;
ParameterValueProvider pvp = new ParameterValueProvider(new ElementId((int)viewtemppara));

// "Structural Section" is my own view templatet 
FilterStringRule strrule = new FilterStringRule(pvp , new FilterStringEquals(), "Structural Section" , true);

ElementParameterFilter epf = new ElementParameterFilter(strrule);

FilteredElementCollector Collector3 = new FilteredElementCollector(doc);

IList<Element> ViewTempelem = Collector3.WherePasses(epf).ToElements();

ElementId ViewTempid = ViewTempelem[0].Id;

viewsec.ViewTemplateId = ViewTempid;

0 Likes
Message 4 of 6

FAIR59
Advisor
Advisor
Accepted solution

a view template is a view, with property IsTemplate.

 

IEnumerable<View> views = new FilteredElementCollector(document)
				.OfClass(typeof(View))
				.Cast<View>()
				.Where( v=> v.Name.Equals(templateName));
View template = views.FirstOrDefault();
ElementId templateId = template.Id;

  

 

Message 5 of 6

Arciviz
Advocate
Advocate

Thanks for your replay. I will try it.

Regards,

Sudhna 

0 Likes
Message 6 of 6

Arciviz
Advocate
Advocate

Hi FAIR59,

The code creates the section with template.

Thanks Lot Dear

Regards,

Sudhan

0 Likes