Saving viewsheetsetting problem. InSession issue.

Saving viewsheetsetting problem. InSession issue.

Anonymous
Not applicable
991 Views
2 Replies
Message 1 of 3

Saving viewsheetsetting problem. InSession issue.

Anonymous
Not applicable

Hi,

I have a problem that i have spent days trying to get working... thinking it is working and then continuously finding bugs with it.

 

I have created a viewsheet that I want to print...

Setup my printmanager...

and selected the print range - print to view/sheets

 

... but I can't get it to save the viewsheetsetting correctly in all cases of weither the user has

             In-Session or a saved print set enabled.

 

The code bellow gets me most of the way but, for some reason i need to manually press "OK" in the image bellow and then run the code to get it to work.

otherwise the viewsheetsettings are not saved when In-Session  is enabled and it returns an error, "No views/sheets selected for printing";

 

Capture.PNG

 

 

  I have looked at the viewprinter sample and cant find anything to solve this problem.

  This has been a nightmare trying to solve so if there is anyone with a working sample of code or any suggestions i would greatly appreciate it.

 

 

 

 

 



FilteredElementCollector printSetFilter = new FilteredElementCollector(doc); printSetFilter.OfClass(typeof(View));
ViewSet vwSet = new ViewSet();// to be assigned to IViewSheetSet foreach (Element item in printSetFilter) { if (item is ViewSheet) { ViewSheet vw = (ViewSheet)item; if (vw.SheetNumber == newSheetNumber)// newSheetNumber is of the sheet i have created. { vwSet.Insert(vw); // place our new viewsheet in set } } } ViewSheetSetting newviewSheetSetting = printManager2.ViewSheetSetting; IViewSheetSet vsheetset = newviewSheetSetting.CurrentViewSheetSet; if (vsheetset.Equals(newviewSheetSetting.InSession))// checking to see if InSession is enabled { // there is no boolean return for insession? vsheetset = newviewSheetSetting.InSession; newviewSheetSetting.InSession.Views = vwSet; try { newviewSheetSetting.Save(); } catch { } vsheetset.Views = vwSet; } else { newviewSheetSetting.CurrentViewSheetSet.Views = vwSet; try { newviewSheetSetting.Save(); } catch { } vsheetset.Views = vwSet; }

 

Thank you

 

0 Likes
Accepted solutions (1)
992 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Update* Apparently this does not determine weither the IViewSheetSet = InSession

 

if (vsheetset.Equals(newviewSheetSetting.InSession))
{

.....

}

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution
                bool needToCreateNewSet = true;
                FilteredElementCollector filteredElementCollectorSets = new FilteredElementCollector(doc);
                filteredElementCollectorSets.OfClass(typeof(ViewSheetSet));
                foreach (Element e in filteredElementCollectorSets)
                {
                    if (e is ViewSheetSet)
                    {
                        ViewSheetSet vSet = (ViewSheetSet)e;
                        if (vSet.Name == "PASS1192 - Printing Set")
                        {
                            vSet.Views = vwSet;
                            newviewSheetSetting.CurrentViewSheetSet = vSet;
                         
                            vsheetset.Views = vSet.Views;
                            
                            try
                            {
                                newviewSheetSetting.Save();
                            }
                            catch { }
                            printManager2.Apply();
                            needToCreateNewSet = false;
                        }
                    }
                }
                if (needToCreateNewSet == true)
                {
                    newviewSheetSetting.CurrentViewSheetSet.Views = vwSet;
                    
                    vsheetset.Views = vwSet;
                    try
                    {
                        newviewSheetSetting.SaveAs("PASS1192 - Printing Set");
                    }
                    catch { }
                    printManager2.Apply();
                    needToCreateNewSet = false;                    
                }

Solved. I could not successfully save Inession viewsheetsettings without using saveas() so i was forced to create a set to use.
I tried deleting the set after use but had a database error.

0 Likes