PDA

View Full Version : ApplyTemplate method, anyone used it?



r.howarth
2008-01-31, 04:12 AM
This is in the CHM file, and in intellisense but not much else is documented on it anywhere from what i can tell, not used in SDK sample, not in webcast labs, and nothing on google.

It seems simple, ApplyTemplate(viewtemplate as view). The problem I'm having, is how do I select my viewtemplate?

In revit when you try to apply a view template it shows you a list, how do I create myself a list like that?

Lets say for example, we have a view template called: "BW_Masonry Plan" I can see this as an element, with no category or other information. So I try to cast is as an Autodesk.Revit.Elements.View. This nulls it.

If I loop through all of the View elements in the document, BW_Masonry Plan never shows up.

So how is it that I can define that element as my view template?

Heres some code I've been trial and erroring, it's not well formed I realise that (I will clean it up as per the element efficiency thread) but I'm just trying things to get it to return a view.

private View GetAllViews(Document doc)
{
string ViewsList = " ";

ElementIterator itor = doc.Elements;
itor.Reset();

while (itor.MoveNext())
{
Element curelem = itor.Current as Autodesk.Revit.Element;
// Autodesk.Revit.Elements.View curelem = itor.Current as Autodesk.Revit.Elements.

if (null == curelem)
{
continue;

}
else
{
if (curelem.Name == "BW_Masonry Plan")
{
ViewsList += curelem.Name.ToString();
ViewsList += " ";
if (curelem.Category != null)
ViewsList += curelem.Category.Name.ToString();

ViewsList += " ";
if (curelem.ObjectType != null)
ViewsList += curelem.ObjectType.Name.ToString();
View ViewTemp = curelem as View;
return ViewTemp;
}
}

}
WF.MessageBox.Show("returning null");
return null;

}

Can anyone shed any light? Thanks!

GuyR
2008-01-31, 07:52 AM
Rod,

Yeah, it's a little confusing.

You use a existing view and it applies the graphical overrides etc from that view. It's been a while since I used it but from memory it works OK. I can dig out some code if you don't have any luck.

The element object you found doesn't refer to a view template that you can use currently. There are some parameters for scale etc which you can set on the view you're wanting to apply the template to.

Guy

NKramer
2008-01-31, 03:09 PM
Just a quick caution about view templates. They will dump any of your overrides in the view. I find that they are really only worth wile at the inception of the view and only serve to create problems when applied later.
I am not sure exactly what you are trying to do but it may be easier to set up your view templates in a template file and adjust them there.

I tired applying view templates after we had done some work on interior elevations (so that I wouldn't have to hide everything in each view). Well the short of it is that it un-hid everything in the view (ie we had specifically hid certain walls in views because the room was L shaped, etc), changed all of the scales, and overrode my visibility graphics overrides.

Now We just use view templates at the initial creation of views. As we realize that certain things should be added/ removed from the view template then I go back and edit our template for future use.

Not that this solves your API issue....
HTH

Nick

r.howarth
2008-01-31, 10:12 PM
Rod,

Yeah, it's a little confusing.

You use a existing view and it applies the graphical overrides etc from that view. It's been a while since I used it but from memory it works OK. I can dig out some code if you don't have any luck.

The element object you found doesn't refer to a view template that you can use currently. There are some parameters for scale etc which you can set on the view you're wanting to apply the template to.

Guy

I see, so you can't actually use "View Templates"(which show up in the 'apply view templates' menu) there, you just have to use another "View" as a "template" ?

NKramer, thanks for that warning, I'll have a talk to our drafters and see if view templates are really the way we want to go.

If not, then editing the scale etc of the active view is what I'll continue doing.

Thanks

jamie.casile
2008-02-12, 06:55 PM
Aloha,
I may be way off base here, but just in case... the View Templates can be accessed in the Settings pulldown menu.
you can make a view template from another view, but i believe the theory on that is that you went through the process of changing things so that it is right in one view, and now you want the same changes made to all other similar views. so you save the changes for that view as a view template.
if you check the view properties of a view, the Default View Template is listed there. you can scroll and pick one to apply to the view as well.
whatever view template is 'assigned' in the Default View Template is what is used when you 'update' your view templates. so, if you use the settings menu > View Templates and change the scale of a specific template - this will NOT automatically override everything. you have to reapply it to the view so it updates. if you right-click in the proj browser and Apply View Template, and select the <Default View Template> it will update the view template currently assigned to the view you have selected. if there is no previously selected view template, nothing updates.
Hope this makes sense.
good luck,
jamie

mschroeder
2009-04-01, 03:50 PM
I see, so you can't actually use "View Templates"(which show up in the 'apply view templates' menu) there, you just have to use another "View" as a "template" ?

Have you found a way to use a view template (not just another view) in the ApplyViewTemplate() method? I can't find a view template instance through the API.

mmason.65315
2009-04-01, 08:31 PM
Nope - I'm pretty sure you can't use ViewTemplates. It is technically possible to find them (they are "Element" objects) - but you can't use them.

The ApplyTemplate() only works with existing views.
-Matt

r.howarth
2009-04-03, 04:10 AM
Unfortunately no I didn't find a way, I did hear something from autodesk about them planning on fixing this but I haven't had a good look to see if they did it for 2010 (my guess is no though as its not in the change list)

As Matt Said, You can use another view as a template, but can't apply a viewtemplate as i couldn't find a way to retrieve the viewtemplates as an object that inherits from view.