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: 

ApplyTemplate() not working?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Tehkaiser
1142 Views, 8 Replies

ApplyTemplate() not working?

Hey, I am having a problem with a recursive file export which applies templates to views prior to exporting.

Not exactly certain why it's not working, but the first recursion of the view seems to always export a 12.0kb file with no contents, and for the second view it seems to export the view properly, but not actually apply the template, so each view is identical...

 

Here is my code:

Autodesk.Revit.DB.ViewSet NewViewSet = new Autodesk.Revit.DB.ViewSet();
            switch (comboBox1.SelectedItem.ToString())
            {
                case "DWG":
                    foreach (Autodesk.Revit.DB.View view in ViewsToExport)
                    {
                        foreach (Autodesk.Revit.DB.View template in Templates)
                        {
                            Application.DoEvents();
                            FileName = textBox2.Text + "_" + textBox3.Text + "_" + "#VWRP#" + "_" + "#TMRP#" + "_" + textBox5.Text + "_" + textBox4.Text;
                            FileName = FileName.Replace("#VWRP#", view.ViewName);
                            FileName = FileName.Replace("#TMRP#", template.ViewName);
                            IList<Autodesk.Revit.DB.ElementId> ExportView = new List<Autodesk.Revit.DB.ElementId>();
                            Autodesk.Revit.DB.View NewView = view;
                            NewView.ApplyTemplate(template);
                            NewViewSet.Insert(NewView);
                            ExportView.Add(NewView.Id);
                            if (ComData.Application.ActiveUIDocument.Document.Export(textBox1.Text, FileName, ExportView, dwgExportOptions))
                            {
                                progressBar1.Value++;
                                continue;
                            }
                            else
                            {
                                MessageBox.Show("Exporting failed on...\nView: " + view.ViewName + "\nTemplate: " + template.ViewName);
                                break;
                            }
                        }
                    }
                    break;

 Any help or information regarding this method, or why my implementation of it is not working would be appreciated.

 

Thanks, Kurt 🙂

8 REPLIES 8
Message 2 of 9
david.rock
in reply to: Tehkaiser

Hello Kurt,

 

I'm not sure if I will be able to help you however I have a similar issue. Can you please include the code where you setup the ExportView collection and the dwgExportOptions?

 

Thanks

David

Message 3 of 9
Tehkaiser
in reply to: david.rock

Hey David, the ExportView collection actually just consists of one view on each iteration because I don't want to make a viewset consisting of up to possibly 200 views, as this would use a lot of memory. Instead, I iterate through a viewset of views, and a viewset of template views, and create a new view each iteration, settings it's default to the view, and then attempting to apply the template to the view. I then add it to the ExportViews List, and singularly export that one view, rinse and repeat.

 

Like I said though, it doesn't seem to be working as I'd hoped. Haha.

 

Picture included shows the code.

Message 4 of 9
david.rock
in reply to: Tehkaiser

Hello,

 

Thanks very much for the code.

 

Perhaps with your issue you could try putting the apply template within a transation and commit before exporting the view.

 

Regards

David

Message 5 of 9
Tehkaiser
in reply to: david.rock

I actually thought maybe that was the issue earlier as well, but when I tried it, it didn't change my results.

Message 6 of 9
Tehkaiser
in reply to: Tehkaiser

Bumping out of desperation. Smiley Sad

Message 7 of 9
MattSiebert
in reply to: Tehkaiser

Not sure if this solves your issue, but the line

 

                            Autodesk.Revit.DB.View NewView = view;

 

doesn't actually create a new view - the 'NewView' variable just gets a reference to the original view object.  So, the following line...

 

                            NewView.ApplyTemplate(template);

 

is actually applying the template to the original view.

Message 8 of 9
Tehkaiser
in reply to: MattSiebert

This has helped me solve one minor issue, thanks a lot!

 

It still however seems to not be applying the actual view template with the method.

Each view exported with different templates applied keeps coming out identically.

In fact, if I make custom templates, and apply them within Revit, it works fine. But, if I apply them through ApplyTemplate(), nothing happens. Here, one picture shows the result of applying the template within Revit, the other picture shows the exported view with the template apparently applied via ApplyTemplate(), though it's clearly not applied.

 

Edit: Perhaps I need to apply the template within a transaction?

Message 9 of 9
Tehkaiser
in reply to: Tehkaiser

I have solved my problem, thanks. If anyone runs into this same issue and needs help, send me a message, or an email @ kurt.schempp.9999@gmail.com

 

Thanks. 🙂

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community