Parameters not updating

Parameters not updating

mike
Enthusiast Enthusiast
855 Views
2 Replies
Message 1 of 3

Parameters not updating

mike
Enthusiast
Enthusiast

Trying to rename views that have been placed on sheets to include the sheet and number as a prefix.  This will make it easier for architects to look in past projects for details and use "Insert 2D elements from file".  It seems simple enough.  I can get the data I need and build the new strings.  My code generates no errors (anymore), but the parameter values do not change.  I'm trying to change "View Name" and "Title on Sheet".  See code below.  It is based on code form the SDK samples folder.

 

//
// (C) Copyright 2003-2013 by Autodesk, Inc. All rights reserved.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.

//
// AUTODESK PROVIDES THIS PROGRAM 'AS IS' AND WITH ALL ITS FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Revit.SDK.Samples.DuplicateViews.CS
{
/// <summary>
/// Rename all views that are placed on sheets with the sheet/number as prefix.
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
class DuplicateAcrossDocumentsCommand : IExternalCommand
{
#region IExternalCommand Members

/// <summary>
/// The command implementation.
/// </summary>
/// <param name="commandData"></param>
/// <param name="message"></param>
/// <param name="elements"></param>
/// <returns></returns>
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
Autodesk.Revit.ApplicationServices.Application application = commandData.Application.Application;
Document doc = commandData.Application.ActiveUIDocument.Document;


// Collect schedules and drafting views
FilteredElementCollector collector = new FilteredElementCollector(doc);

List<Type> viewTypes = new List<Type>();
viewTypes.Add(typeof(ViewSection));
viewTypes.Add(typeof(ViewDrafting));

ElementMulticlassFilter filter = new ElementMulticlassFilter(viewTypes);
collector.WherePasses(filter);

collector.WhereElementIsViewIndependent(); // skip view-specfic schedules (e.g. Revision Schedules);

string dn="";
string sn="";
string sTitle = "";
string sNewName = "";
char[] delimiterChars = { '_' };

// Transaction
using (Transaction t = new Transaction(doc, "Rename views on sheets"))
{

foreach (Element ve in collector)
{
//View view = (View)ve;
if (ve.get_Parameter("Detail Number") != null && ve.get_Parameter("Sheet Number") != null)
{

dn = ve.get_Parameter("Detail Number").AsString();
sn = ve.get_Parameter("Sheet Number").AsString();
string[] words = ve.get_Parameter("View Name").AsString().Split(delimiterChars);
if (words.Count() == 1)
sTitle = words[0];
else
sTitle = words[1];

sNewName = sn + "/" + dn + "_" + sTitle;

t.Start();
// set title on sheet to original view name
//ve.get_Parameter("Title on Sheet").SetValueString(sTitle);
Parameter p1 = ve.get_Parameter("Title on Sheet");
if (!p1.IsReadOnly)
{ p1.SetValueString(sTitle); }

//change view name to include sheet
//ve.get_Parameter("View Name").SetValueString(sNewName);
Parameter p2 = ve.get_Parameter("View Name");
p2.SetValueString(sNewName);

//TaskDialog.Show("info", sNewName + " " + sTitle);
t.Commit();

}

}

t.Dispose();
}


return Result.Succeeded;
}

#endregion
}
}

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

augusto.goncalves
Alumni
Alumni
Accepted solution

Please try replace

p2.SetValueString(sNewName);

 

With

p2.Set(sNewName);

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 3 of 3

mike
Enthusiast
Enthusiast

Yes!  Thank you.  I found this page to be exceedingly helpful in this regard.

 

http://spiderinnet.typepad.com/blog/2011/04/parameter-of-revit-api-14-set-parameter-value.html

 

-mjm

0 Likes