Hello!
I'm trying to create some ViewSheets:
string pn = projectNumberTextbox.Text;
string sn = sheetNumberTextbox.Text;
int n = Convert.ToInt32(sheetCountTextbox.Text);
using(Transaction tx = new Transaction(doc))
{
tx.Start("Create Sheets");
for (int i = 0; i < n; i++)
{
FilteredElementCollector fec = new FilteredElementCollector(doc);
fec.OfCategory(BuiltInCategory.OST_TitleBlocks);
fec.WhereElementIsElementType();
ElementId tbId = fec.FirstElementId();
string shNumber = pn + '-' + sn + '-' + (n+1).ToString() + ' ' + '-' + ' ';
string shName = "Construction drawings";
ViewSheet vs = ViewSheet.Create(doc, tbId);
vs.SheetNumber = shNumber;
vs.Name = shName;
}
tx.Commit();
}
but at the vs.Name = shName; I get an error: Autodesk.Revit.Exceptions.ArgumentException: 'Name must be unique. Parameter name: name'.
Why is it so and how can I create some sheets with the same names and different numbers?
I would be grateful for answer.
Technically speaking in the UI you can duplicate the sheet name but not the sheet number: SHEET_NUMBER (-1007401).
The property ViewSheet.Name is derived from View.Name and ordinarily for views you can't duplicate names. Try instead changing the equivalent parameter:
SHEET_NAME (-1007400) which is not exactly the same as VIEW_NAME (-1005112).
I'm guessing class logic is mistaken somehow in trying to change wrong one or more likely falsely checks it is wrong because it generally is (except for sheets).
Omg, my stupid mistake. Instead of string shNumber = pn + '-' + sn + '-' + (n+1).ToString() + ' ';
it must be string shNumber = pn + '-' + sn + '-' + (i+1).ToString() + ' ';
Thank you for answer! It works!
for (int i = 0; i < n; i++)
{
ViewSheet vs = ViewSheet.Create(doc, ElementId.InvalidElementId);
vs.LookupParameter("Drawing number").Set(sn);
string shNumber = pn + '-' + sn + '-' + (i+1).ToString() + ' ';
vs.LookupParameter("Sheet Number").Set(shNumber);
string shName = "Construction drawings";
vs.LookupParameter("Sheet Name").Set(shName);
}
On English language Revit there are two parameters with name 'Sheet Number'
SHEET_NUMBER (-1007401)
VIEWER_SHEET_NUMBER (-1006601)
So it is always better to use the built-in parameter enum values for BIPs rather than using .LookupParameter.
Can't find what you're looking for? Ask the community or share your knowledge.