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: 

Delete PrintSetup and ViewSheetSettings

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
1718 Views, 7 Replies

Delete PrintSetup and ViewSheetSettings

Hi all,

 

TL;DR

Is there a way of deleting a specific PrintSetup and ViewSheetSetting programatically if i know its name?

 

 

Long version:

I'm writing a function that can print a large set of sheets in various paper sizes to separate/combined PDFs. To be able to apply the PrintSetup, it needs to be set in an "in-session" state and saved using SaveAs() (to my knowledge). But after saving an "in-session"-PrintSetup to a new PrintSetup, I cannot find a way of deleting said new PrintSetup. After the PrintManager has printed the sheets, I'm stuck with lots of temporary PrintSetups. The same goes for ViewSheetSettings.

 

            try
            {
                pMgr.PrintSetup.Delete();
                pMgr.ViewSheetSetting.Delete();
            }
            catch (Exception ex)
            {
                //Shows 'The <in-session> print setup cannot be deleted'
                TaskDialog.Show("REVIT", ex.Message);
            }

 

So the problem is: I'm not able to apply the PrintSetup and ViewSheetSettings unless i'm using them "in-session" and saving them using SaveAs, and i'm not able to delete the PrintSetup and ViewSheetSettings afterwards.

 

Has anyone experiences similar issues, or found a way to solve it? 

 

 

Cheers,

Eirik Aasved Holst

7 REPLIES 7
Message 2 of 8
jeremytammik
in reply to: Anonymous

Dear Eirik,

 

This discussion makes one brief mention of deleting a print setting, afaik can tell:

 

http://stackoverflow.com/questions/14946217/setting-viewsheetsetting-insession-views-property

 

This discussion appears to suggest a similar approach:

 

http://forums.autodesk.com/t5/revit-api/printermanager-printsetup-do-not-apply-settings/td-p/3676618

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 8
Anonymous
in reply to: jeremytammik

Jeremy,

 

Thank you for the links. Unfortunatley they do not help much. It would be nice if it was possible to loop through the saved PrintSetup's, or at least get a PrintSetup if you knew it's name, so that you can delete it.

 

In the thread PrinterManager PrintSetup do not apply settings, the user aricke mentions:

 

Note that once you have done the saveas, you can then delete the newly saved printsetup.

I cannot seem to get that to work. even the following code will raise an exception

pSetup.SaveAs("tmp");
pSetup.Delete();

 

I appreciate any suggestions as to how to overcome/bypass this issue.

 

 

Cheers,

Eirik Aasved Holst

Message 4 of 8
Anonymous
in reply to: Anonymous

No worries, i finally managed to create a CleanUp-method that works. If others are interested, here it goes 

 

        private void CleanUp(Document doc)
        {
            var pMgr = doc.PrintManager;
            using (var trans = new Transaction(doc))
            {
                trans.Start("CleanUp");
                CleanUpTemporaryViewSheets(doc, pMgr);
                CleanUpTemporaryPrintSettings(doc, pMgr);
                trans.Commit();
            }
        }

        private void CleanUpTemporaryPrintSettings(Document doc, PrintManager pMgr)
        {
            var printSetup = pMgr.PrintSetup;
            foreach (var printSettingsToDelete in (from element in new FilteredElementCollector(doc).OfClass(typeof(PrintSetting)).ToElements()
                                                   where element.Name.Contains(_tmpName) && element.IsValidObject
                                                   select element as PrintSetting).ToList().Distinct(new EqualElementId()))
            {
                printSetup.CurrentPrintSetting = pMgr.PrintSetup.InSession;
                printSetup.CurrentPrintSetting = printSettingsToDelete as PrintSetting;
                pMgr.PrintSetup.Delete();
            }
        }

        private void CleanUpTemporaryViewSheets(Document doc, PrintManager pMgr)
        {
            var viewSheetSettings = pMgr.ViewSheetSetting;
            foreach (var viewSheetSetToDelete in (from element in new FilteredElementCollector(doc).OfClass(typeof(ViewSheetSet)).ToElements()
                                                  where element.Name.Contains(_tmpName) && element.IsValidObject
                                                  select element as ViewSheetSet).ToList().Distinct(new EqualElementId()))
            {
                viewSheetSettings.CurrentViewSheetSet = pMgr.ViewSheetSetting.InSession;
                viewSheetSettings.CurrentViewSheetSet = viewSheetSetToDelete as ViewSheetSet;
                pMgr.ViewSheetSetting.Delete();
            }
        }
Message 5 of 8
jeremytammik
in reply to: Anonymous

Dear Eirik,

 

Congratulations on solving this!

 

Thank you for sharing!

 

You have my kudo.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 8
jeremytammik
in reply to: Anonymous

Dear Eirik,

 

Thank you again for sharing this.

 

I published an edited version of this thread now:

 

http://thebuildingcoder.typepad.com/blog/2016/03/index-reloading-curves-distance-and-deleting-prints...

 

Cheers, 

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 8
jeremytammik
in reply to: Anonymous

Dear Eirik,

 

Two comments on this from The Building Coder, by Arif and Matt:

 

  1. by Arif Hanif: This is awesome, I was working on a solution that involved a similar workflow for print setup but was running into issues. This helped solve my issue of creating and print panel schedules from the MEP model.

 

  1. by Matt Taylor: Rolling back the transaction would nullify the need for this, wouldn't it?

 

Would you care to respond?

 

Thank you!

 

Cheers,

 

Jeremy

 


Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 8
Anonymous
in reply to: jeremytammik

Sure!

 

Arif, I'm very glad it helped! This issue (and similar) has been arround for a while it seems. The PrintManager is in genral rather unintuitive.

 

Matt, rolling back a transaction would indeed undo/remove saved PrintSettings and SheetSets made in the current transaction, but it is not given that the scope of the event is within the same transaction throughout the event. Nor is it given that one want to undo/remove all changes made to the document during the transaction. One might event want to run a separate function which sole purpose is to remove certain PrintSetups, SheetSets, etc. However, use of sub-transactions might nullify the need for this CleanUp-method. Thank you for your comment.

 

 

Cheers,

Eirik

Edit: Typo

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

Post to forums  

Autodesk Customer Advisory Groups


Rail Community