ViewPrinter sample

ViewPrinter sample

miketurpin_innovatingfutures
Enthusiast Enthusiast
2,169 Views
18 Replies
Message 1 of 19

ViewPrinter sample

miketurpin_innovatingfutures
Enthusiast
Enthusiast

Bump following this thread

 

Does anyone know if there is some additional code needed in the ViewPrinter sample?

It doesnt appear to do anything in the ViewSheetSetForm.cs once the form is Ok'ed

I would expect it to take "item.checked" from "viewSheetSetListView" and somehow set these to the "<In-Session>"ViewSheetSetting

 

im stuck in a hole and my only way out so far is to create a new named view sheet set and then delete it at the end but this is less than ideal.

2,170 Views
18 Replies
Replies (18)
Message 2 of 19

Anonymous
Not applicable

This drove me insane for a long long time, I ended up being forced to create a new viewsheet set for my application and using that. couldnt find any way around problems caused by the insession set, this is what i did but it doesn't solve the problem.

                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 == "APPNAME - 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("APPNAME - Printing Set");
                    }
                    catch { }
                    printManager2.Apply();
                    needToCreateNewSet = false;
                }

 

If you find a solution or some way of improving on it I would love to see it. 

Cheers

0 Likes
Message 3 of 19

miketurpin_innovatingfutures
Enthusiast
Enthusiast

Thanks Mendo123,

Thats the same solution i am currently using which works but isnt great.

 

Shurely there must be a way to update / modify / save the <In-Session> set???

 

Mike

0 Likes
Message 4 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike and Mendo123,

 

Thank you for your query and sorry this is such an issue for you.

 

Not being a printer kind of person myself, I have no idea what the problem might be, nor do I know what 'is-session' set you are talking about.

 

Could you describe a possibility for me to reproduce the problem you are observing?

 

A step-by-step description of exactly what you do, what you observe as a result, and what you would prefer to see?

 

We obviously defininitely want the ViewPrinter sample to do what it is supposed to, in a useful manner.

 

Does it fulfil its stated mission at all, i.e. "Print user selected printable views"?

 

By the way, is your query related at all to the ViewPrinter sample, or are you in fact simply asking how to "update / modify / save the <In-Session> set?"

 

Once again, then, what is that set, and how can I reproduce and test the erroneous behaviour versus what you would like to see happening?

 

Sorry for asking such a simple question, that is apparently so totally clear to you two...

 

Thank you!

 

Best regards,

 

Jeremy



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

0 Likes
Message 5 of 19

miketurpin_innovatingfutures
Enthusiast
Enthusiast

Hi Jeremy,

Many thanks for your reply.

 

Our problem is that the ViewPrinter sample doesnt do what it is supposed to do and we have had to come up with workarounds to make it work (As Medo's code above)

 

When you run the ViewPrinter sample the print dialog box comes up and then if the user chooses "Selected views / sheets" and presses the "Select" button the "ViewSheetSetForm" pops up and this is where the problem lies....

The ViewSheetSetForm loads up with the <In-Session> sheet set selected in the ComboBox at the top. The user should now be able to select a variety of views from the ListView and on clicking the OK button it should update the <In-Session> set with the users choices however the ViewPrinter sample doesnt appear to do anything with them and if you click on the "Select" button to launch the ViewSheetSetForm again then it has forgotten all of your choices.

 

We would like to see the same behaviour as inside Revit that when you choose <In-Session> it remembers the last views you selected to print.

 

Hopefully the above makes sense?... any other questions please let me know.

 

Mike

0 Likes
Message 6 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike,

 

Thank you for the clarification.

 

I submitted the issue REVIT-74039 [API and SDK: ViewPrinter should save to in-session viewsheet set] to the development team for you for further analysis.

 

Cheers,

 

Jeremy



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

Message 7 of 19

miketurpin_innovatingfutures
Enthusiast
Enthusiast

Cheers Jeremy much appreciated!

 

Will they post back here if a solution is found?

0 Likes
Message 8 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike,

 

What do you smoke?  🙂

 

I will let you know as soon as I hear back from them, e.g., if there is an immediate solution.

 

If it takes longer, your best bet will be to keep track of the issue number REVIT-74039, check back after a while and ask how we are getting on with it.

 

Cheers,

 

Jeremy



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

Message 9 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike and Mendo123,

 

The development team explored the issue REVIT-74039 [API and SDK: ViewPrinter should save to in-session viewsheet set] that I submitted for you and ask:

 

Which version of Revit are you using?

 

I tried the code below in Revit 2015 and it can update the in-session viewsheet set with all 3D views:

 

  public void TestPrinting_InSessionViewSheetSet()
  {
    var document = this.ActiveUIDocument.Document;
    PrintManager pm = document.PrintManager;
    InSessionViewSheetSet isViews = pm.ViewSheetSetting.CurrentViewSheetSet as InSessionViewSheetSet;
    if(isViews == null)
      return;
    StringBuilder sb = new StringBuilder();
    foreach(View v in isViews.Views)
    { sb.AppendLine(v.Name); }
    TaskDialog.Show("Insession views", sb.ToString());
    FilteredElementCollector coll = new FilteredElementCollector(document);
    coll.OfClass(typeof(View3D));
    ViewSet newset = new ViewSet();
    foreach(Element ve in coll.ToElements())
    { View v = ve as View; if(v.CanBePrinted) newset.Insert(v); }
    pm.ViewSheetSetting.CurrentViewSheetSet.Views = newset;
    pm.Apply();
  }

 

In other words, we cannot reproduce the problem you describe, and all seems to be working fine.

 

Cheers,

 

Jeremy



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

Message 10 of 19

Anonymous
Not applicable

Hi Jeremy,

 

2016, That code seems to work perfectly for me.

I'll test further to see if there is any problems and let you know if there is.

 

could our problem have been caused by using doc instead of uidoc?

I based my code on the sample in the SDK

Capture.PNG

 

You are a lifesaver 🙂

Cheers 

0 Likes
Message 11 of 19

Anonymous
Not applicable
not uidoc* but like would using the Document class cause the problem?
0 Likes
Message 12 of 19

jeremytammik
Autodesk
Autodesk

Dear Mendo123,

 

Thahk you very much for the update, appreciation and confirmation.

 

Very glad it works for you now.

 

I guess I'll blog about this to help others find this path to enlightenment as well.

 

I also passed on your feedback to the development team to explore your new question and possibly update and clarify the help file on this topic one of these days.

 

Cheers, Jeremy



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

0 Likes
Message 13 of 19

miketurpin_innovatingfutures
Enthusiast
Enthusiast

Hi Jeremy,

Thanks for the update.

 

I am using Revit 2015 at the moment with VS Express 2013.

 

Unfortunately still no luck for me!

I run through the code and i can collect views into the "newset" but after the line "pMgr.ViewSheetSetting.CurrentViewSheetSet.Views = newset;" where newset contains 7 views my PrintManager CurrentViewSheetSetting and InSession both still has 0 views.

0 Likes
Message 14 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike,

 

Thank you for checking.

 

Sorry it did not help.

 

Oh dear; so now Mendo123 is happy with a resolved issue on Revit 2016, and you are still stuck with it in Revit 2015.

 

I assume you tried out the updated code that solved the issue for Mendo123?

 

Well, I'l pass the news about this unfortunate aspect on to the development team, but they may not have much advice for you, being more focussed on the

future than the past...

 

Cheers,

 

Jeremy



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

0 Likes
Message 15 of 19

Anonymous
Not applicable

The code is still working perfectly, I havent found any issue.

 

unfortunetly I applied the same technique to the Printmanager.Printsetup and I am still having an issue. there is no effect on the insession printsetting

 

here is my code

                printManager.PrintSetup.CurrentPrintSetting = printManager.PrintSetup.InSession;
                InSessionPrintSetting inSessionPrintSetting = printManager.PrintSetup.CurrentPrintSetting as InSessionPrintSetting;
                inSessionPrintSetting.PrintParameters.PaperPlacement = PaperPlacementType.Margins;
                inSessionPrintSetting.PrintParameters.ZoomType = ZoomType.Zoom;
                inSessionPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape;
                printManager.Apply();               
                foreach (PaperSize ps in printManager.PaperSizes)
                {
                    // find the A0 papersize
                    if (ps.Name.Equals("ISO A0"))
                    {
                        inSessionPrintSetting.PrintParameters.PaperSize = ps;
                    }
                }
                printManager.Apply();

This doesnt seem to be a problem if we are able to use PrintSetup.Save() but in the SDK it throws this exception when insession.

 

Capture.PNG 

Cheers

Mendo

0 Likes
Message 16 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike and Mendo,

 

Thank you for confirming that the main issue seems to be reliably resolved, and for reporting the new problem.

 

I'll pass it onto the development team.

 

They also responded to your previous updates and say:

 

Glad to know it solved the issue. I do not think it caused by the uidoc, because we always get the print manager from document. I do not have a chance to go through the SDK print sample, but i think it is a good idea to update it to make it better. I will file an issue for it.

 

I also tried my code in 2015, and it works as expected.

 

Please try again and follow the steps below to isolate the problem:

 

  1. switch the current viewsheetset setting to "in session".
  2. run my code to see if it works.

 

Thank you!

 

Cheers,

 

Jeremy



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

0 Likes
Message 17 of 19

jeremytammik
Autodesk
Autodesk

Dear Mike and Mendo,

 

As said, development team tried to reproduce the issue you described and say that it works in both Revit 2015 and 2016.

 

Regarding the new issue with the insession printer settings, this was already fixed in Revit 2016 SP2. Please update to the newest new version. The issue is now closed as 'Cannot Reproduce'.

 

To round it all off and avoid similar future confusion, we also opened a new issue to improve the ViewPrinter sample:

 

REVIT-74653 [Refine the SDK sample for printer to work align with Revit for in-session settings.]

 

I hope this helps.

 

Thank you!

 

Cheers,

 

Jeremy



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

Message 18 of 19

Anonymous
Not applicable

Hi, 

 

I believe I found the issue with the InSession print sets using this code.


ViewSheetSetting newviewSheetSetting = printManager.ViewSheetSetting; printManager.ViewSheetSetting.CurrentViewSheetSet = printManager.ViewSheetSetting.InSession; InSessionViewSheetSet inSessionViews = printManager.ViewSheetSetting.CurrentViewSheetSet as InSessionViewSheetSet; printManager.ViewSheetSetting.CurrentViewSheetSet.Views = vSet;(vSet is a ViewSet) printManager.Apply();

The problem I found was that it would work pefectly if there was another printing set existing in the document. Even if the the printset that was currently being used was the insession set it would work.

BUT.. the code throws an error if the user doesnt have any sheetsets created in the document. "no viewsheets/views selected".

 

Hope this helps solve this bug.

 

Cheers.

 

 

0 Likes
Message 19 of 19

jeremytammik
Autodesk
Autodesk
Dear Mendo,

Congratulations on finding a solution!

Thank you for letting us know!

Cheers,

Jeremy


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

0 Likes