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: 

Sheet Set will not save

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
1115 Views, 14 Replies

Sheet Set will not save

I had a post up earlier but deleted and reposted for clarity purposes.

 

The problem that I am running into is that my Sheet Sets will not save. However, when I put my code into a try/catch block it does not throw any errors.

 

I pretty much copied the code from the RevitAPI.chm doc found in the "printManager class."

 

To start, I have a viewSet which has the sheets I want to put into a set, called "finalViewSet."

 

 PrintManager printManager = doc.PrintManager;
            printManager.PrintRange = PrintRange.Select;
            ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

            viewSheetSetting.CurrentViewSheetSet.Views = viewSet;
           
              try
            {
                viewSheetSetting.CurrentViewSheetSet.Views.Clear();
                viewSheetSetting.CurrentViewSheetSet.Views = finalViewSet;
                viewSheetSetting.SaveAs("mySheetSet);
                
                
            }
            catch (Exception ex)
            {
                String bob = ex.Message;
            }

 

When I debug, it runs over the SaveAs() part, but does not actually save my sheetSet. It is as if it is being saved, but the viewSheetSetting is not being updated. Not quite sure.

 



         

14 REPLIES 14
Message 2 of 15
saikat
in reply to: Anonymous

I have seen this behavior in the recent past when another API user had reported about this. The CurrentViewSheetSet.Views count was still 0 even though I had passed in four views and the viewsToPrint function was returning tjhose four views. The Development team is aware of this unexpected behavior and will be investigating further.

 

Sorry for the incovenience meanwhile

cheers

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 3 of 15
Anonymous
in reply to: saikat

Thanks for the reply Saikat. You are correct, I just confirmed that my ViewSheetSetting.CurrentViewSheetSet.Views.Size returns 0 as well after passing in 5 sheets.

 

So I take it that there is no current workaround for this?

 

 

Message 4 of 15
saikat
in reply to: Anonymous

Nothing that I know of at the moment. If I see any immediate discussions on this in the Development team and if any of that happen to be about any workarounds, I will keep it in mind and communicate with your accordingly.

 

Sorry about that,

cheers

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 5 of 15
Anonymous
in reply to: Anonymous

Please let me notify me via email a workaround for this problem because i have the same problem too. thx you

 

David

Message 6 of 15
Joe.Ye
in reply to: Anonymous

Hi David

 

Here is the code that can work well to save the ViewSheetSet.

 

[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class RevitCommand4 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{

UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "ExComm");
trans.Start();

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(ViewPlan)).OfCategory(BuiltInCategory.OST_Views);


ViewSet vs = app.Application.Create.NewViewSet();

foreach (Element elem in collector)
{
ViewPlan plan = elem as ViewPlan;
if (plan.IsTemplate == false)
vs.Insert(plan);
}

PrintManager pm = doc.PrintManager;
ViewSheetSetting setting = pm.ViewSheetSetting;

string viewSheetSetName = "asPlans1333355";


setting.SaveAs(viewSheetSetName);
setting.CurrentViewSheetSet.Views = vs;
setting.Save();

//pm.ViewSheetSetting.SaveAs(viewSheetSetName);
//pm.ViewSheetSetting.CurrentViewSheetSet.Views = vs;
//pm.ViewSheetSetting.Save();

ViewSheetSetting setting1 = pm.ViewSheetSetting;
ViewSheetSetting setting2 = pm.ViewSheetSetting;


pm.PrintRange = PrintRange.Select;
pm.CombinedFile = true;
pm.PrintToFile = true;

trans.Commit();

pm.SubmitPrint();

return Result.Succeeded;
}
}

 

Several notes about this code.

 

1. SaveAs ViewSheetSetting, assign views to ViewSheetSet, and save the ViewSheetSetting code should be within a transaction. These actions actually changed the document. So transaction is necessary.

 

2.   The following three line cannot be replaced the three lines after it.

//pm.ViewSheetSetting.SaveAs(viewSheetSetName);
//pm.ViewSheetSetting.CurrentViewSheetSet.Views = vs;
//pm.ViewSheetSetting.Save();

 

setting.SaveAs(viewSheetSetName);
setting.CurrentViewSheetSet.Views = vs;
setting.Save();

 

Reason:  every time we call pm.ViewSheetSetting, it returns a new ViewSheetSetting instance. So for the following three lines, the three actions take place to three different ViewSheetingSetting objects. That is not we expected.

//pm.ViewSheetSetting.SaveAs(viewSheetSetName);
//pm.ViewSheetSetting.CurrentViewSheetSet.Views = vs;
//pm.ViewSheetSetting.Save();

 

We want the three actions take place to the same ViewSheetSetting object, so we first get a ViewSheetSetting instance, then operate on this ViewSheetSetting instance.

 

Simillarly, Document.PrintManager returns different PrintManager if you call it one after another. 

So the following two lines take place to two different PrintManager object.

Doc.PrintManager.PrintRange = PrintRange.Select;
Doc.PrintManager..CombinedFile = true;

Make sure to return one PrintManager assign it a a PrintManager variable first, then operate on this variable.

 

Hope this helps!



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Message 7 of 15
babu.rajan
in reply to: Joe.Ye

I try to run this code in Revit 2013 it giving me an error do you have any idea what it is?

 

 [Transaction(TransactionMode.Manual)]

 

publicclassCommands : IExternalCommand

{

publicResult Execute(ExternalCommandData commandData, refstring message, ElementSetelements)

{

UIApplicationapp = commandData.Application;

 

Documentdoc = app.ActiveUIDocument.Document;

 

Transaction trans = newTransaction(doc, "ExComm");

trans.Start();

FilteredElementCollector collector = newFilteredElementCollector(doc).OfClass(typeof(ViewPlan)).OfCategory (BuiltInCategory.OST_Views);

 

ViewSetvs = app.Application.Create.NewViewSet();

 

foreach (Element elem incollector)

{

ViewPlan plan = elem asViewPlan;

 

if (plan.IsTemplate == false)

vs.Insert(plan);

}

PrintManagerpm = doc.PrintManager;

 

ViewSheetSettingsetting = pm.ViewSheetSetting;

 

string viewSheetSetName = "asPlans1333355";

setting.SaveAs(viewSheetSetName);

setting.CurrentViewSheetSet.Views = vs;

setting.Save();

ViewSheetSettingsetting1 = pm.ViewSheetSetting;

 

ViewSheetSettingsetting2 = pm.ViewSheetSetting;

pm.PrintRange =

PrintRange.Select;

pm.CombinedFile =

true;

pm.PrintToFile =

true;

trans.Commit();

pm.SubmitPrint();

returnResult.Succeeded;

}

}

print.jpg

Message 8 of 15
RevitArkitek
in reply to: babu.rajan

Try putting your line:

pm.PrintRange = PrintRange.Select;

before defining your ViewSheetSetting

Message 9 of 15
Moustafa_K
in reply to: Joe.Ye

hi,
i am at the same case which is getting me a bit frustrated. i need to ask what is the purpose of those two line :
ViewSheetSetting setting1 = pm.ViewSheetSetting;
ViewSheetSetting setting2 = pm.ViewSheetSetting;

as long they are not used.

i need to know how to call for name of one of the saved view set and delete.?
does deleting a view set requires to be current?

-----------------------------------------------------
Moustafa Khalil
Message 10 of 15
RevitArkitek
in reply to: Moustafa_K

I believe it does need to be current to delete it, similar to the user interface.  I don't know why they set two ViewSheetSettings.  Something like this should work for you:

 

// get the PrintManger from the current document
PrintManager printManager = doc.PrintManager;

// set this PrintManager to use the "Selected Views/Sheets" option
printManager.PrintRange = PrintRange.Select;

// get the ViewSheetSetting which manages the view/sheet set information of current document
ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;

// search ViewSheetSets for the one we are interested in

foreach (ViewSheetSet set in doc.ViewSheetSets)
{

if (set.Name == "My Sheet Set")

{

viewSheetSetting.CurrentViewSheetSet = set;

}
viewSheetSetting.Delete();

}

Message 11 of 15
Moustafa_K
in reply to: RevitArkitek

Amazing!! that was really helpful... however, i have faced another issue which is i was unable to update an existing sheet set. to cut a long story short, below is what i did:
My aim is ---. to sort all sheetviews in a set relative to paper size of titleblock

1. search for viewsheets in document
2. find the word "A4" in viewsheet blocktitle name.
3. Creat a new set with name A4
4. insert all selected viewsheets in this set.
5. Save set.
6. delete any empty view set.

all above works very fine... after i apply the command i made a change in the document,for example delete one sheet or a title block from one of the sheets. then after rerun the command it gives me error unable to save sheetset.
so i made a trick to delete all sets before the music starts.

did what i do is the correct follow?
"I am happy to show the code" if needed.


-----------------------------------------------------
Moustafa Khalil
Message 12 of 15
RevitArkitek
in reply to: Moustafa_K

I'm not sure what the problem could be without seeing code.  But I don't think you will be able to "sort" a ViewSheetSet.  I believe they are in an order that Revit puts them in, like alphabetically.  After you change the ViewSet, delete the original ViewSheetSetting, and just set the CurrentViewSheetSet to the new ViewSet and do a SaveAs.

Message 13 of 15
Moustafa_K
in reply to: RevitArkitek

here is below the code, 

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = commandData.Application.ActiveUIDocument.Document;
UIApplication app = commandData.Application;
string report = "Sheets Arranged Successfully!" + "\r\n";
report += SheetSet(doc, uidoc, app);
TaskDialog.Show("Arrange sheet Set", report);
return Result.Succeeded;
}
/// <summary>
/// Delete sheetset
/// </summary>
/// <param name="doc"></param>
/// <param name="nset"></param>
/// <param name="uidoc"></param>
/// <returns></returns>
public void delset(Document doc, string nset, UIDocument uidoc)
{
using (Transaction t = new Transaction(doc, "Delete ViewSet"))
{
t.Start();
PrintManager PM = doc.PrintManager;
PM.PrintRange = PrintRange.Select;
ViewSheetSetting vs = PM.ViewSheetSetting;
foreach (ViewSheetSet set in doc.ViewSheetSets)
{
if (set.Name == nset)
{

try
{
PM.PrintRange = PrintRange.Select;
vs.CurrentViewSheetSet = set;
vs.Delete();

}
catch (Exception ex1)
{
TaskDialog.Show("Error1", ex1.Message);
}
t.Commit();
}
}

}
}// end of delset
 

/// <summary>
/// SheetSet
/// </summary>
/// <param name="doc"></param>
/// <param name="uidoc"></param>
/// <param name="app"></param>
public string SheetSet(Document doc, UIDocument uidoc, UIApplication app)
{
string report = "";
for (int i = 0; i < 5; i++)
{
report += test(app, uidoc, doc, "A" + i);
}
return report;
}//end of sheetset
 

/// <summary>
/// 
/// </summary>
/// <param name="app"></param>
/// <param name="uidoc"></param>
/// <param name="doc"></param>
/// <param name="PSize"></param>
/// <returns></returns>
public string test(UIApplication app, UIDocument uidoc, Document doc, string PSize)
{
string report = "";
delset(doc, PSize, uidoc);
//Creating a sheetset
ViewSet vs = app.Application.Create.NewViewSet();
foreach (ViewSheet vSheet in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)))
{
foreach (Element e in new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TitleBlocks))
{
if (e.OwnerViewId == vSheet.Id && e.Name.Contains(PSize))
{
vs.Insert(vSheet);
}
}
}
if (vs.Size != 0)
{
using (Transaction t = new Transaction(doc, "Save set"))
{
t.Start();
PrintManager pm = doc.PrintManager;
pm.PrintRange = PrintRange.Select;
ViewSheetSetting vsettings = pm.ViewSheetSetting;
try
{
vsettings.SaveAs(PSize);
vsettings.CurrentViewSheetSet.Views = vs;
vsettings.Save();
report = PSize + " SheetSet---No of sheets " + vs.Size.ToString() + "\r\n";
}
catch (Exception ex3)
{
foreach (ViewSheetSet vset in doc.ViewSheetSets)
{
if (vset.Name == PSize && vs.Size !=0)
{
pm.PrintRange = PrintRange.Select;
vsettings.CurrentViewSheetSet = vset;
vsettings.CurrentViewSheetSet.Views = vs;
try
{
vsettings.Save();
report = PSize + " SheetSet---No of sheets " + vs.Size.ToString() + "\r\n";
}
catch (Exception ex2)
{
//TaskDialog.Show(PSize + " Error2" , ex2.Message);
}

//TaskDialog.Show("Error3", ex3.Message);
}
}
}
t.Commit();
}
}
return report;
}
}//end of class
}//end of namespace

 


-----------------------------------------------------
Moustafa Khalil
Message 14 of 15
RevitArkitek
in reply to: Moustafa_K

Your code is working for me, I copied into the Macro manager in 2014.  I was able to add and delete sheets and the Sheet Set updated.  One thing i did notice is that in your delset method, your t.commit is in the foreach loop.  You should keep them at the same level.  If you are still having problems, I would suggest starting with a macro and copy/paste your code into it.  Your code is a bit of spaghetti also, I'm not sure why you have so many methods.  You only need a method if the code is needed in more than one place.  Hope this helps.

Message 15 of 15
Moustafa_K
in reply to: RevitArkitek

i am happy that you tried the code...yes indeed it works and i am so happy that i have achieved my first code for Revit API.

for the t.commit issue at the delset method, yes you are right i should get it out of the loop... thanks for your help 🙂

-----------------------------------------------------
Moustafa Khalil

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