Thanks for replying Revitalizer.
I had encountered your other post regarding this same thing:
Hi tssserg,
first, I set the existing value for element parameter BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS to oldvalue + mySeparatorSign + elementId.
Then I duplicate an existing ViewSchedule.
If it doesn't contain a ScheduleField for the parameter yet, I add this.
After that, I can analyze each row, splitting the value of the comments cell by mySeparatorSign to get the ElementId.
Finally, I rollback the Transaction.
In fact, I used two Transactions inside a TransactionGroup.
That's all.
Of course you could add another parameter to hold the ElementId.IntegerValue and use this one instead of hijacking the comments parameter.
So I was taking the route of creating my own parameter to hold the Element.UniqueId. Are you saying I can't use a new parameter in this way and add it to the Schedule as a column? (The new parameter type I created was of ParameterType.Text, so I'm not sure why when I check the bodySection.GetCellType() for this new column it returns CellType.Parameter, but it does.)
Here is the code that creates the parameter, fills it with each element's UniqueId and inserts it as a new field in the schedule:
public static ViewSchedule createTempSchedule( ViewSchedule origVs, int scheduleFieldIdInt, out Guid idParamGuid, out ScheduleField vsSF )
{
Document doc = origVs.Document;
idParamGuid = Guid.Empty;
vsSF = null;
//duplicate the schedule so that the original is not modified
ElementId newVsId = origVs.Duplicate( ViewDuplicateOption.Duplicate );
ViewSchedule vs = doc.GetElement( newVsId ) as ViewSchedule;
//get the category
CategorySet cs = new CategorySet();
Category cat = doc.Settings.Categories.get_Item( (BuiltInCategory)vs.Definition.CategoryId.IntegerValue );
cs.Insert( cat );
//take the first element of the schedule's category and either get or create the uniqueId parameter
string uniqueIdParamName = "Schedule_Unique_Id";
FilteredElementCollector catFec = new FilteredElementCollector( doc ).OfCategory( (BuiltInCategory)cat.Id.IntegerValue).WhereElementIsNotElementType();
Element testElem = catFec.ToList<Element>()[ 0 ];
if (testElem.get_Parameter( uniqueIdParamName ) == null)
{
idParamGuid = RawCreateProjectParameter( doc.Application, uniqueIdParamName, ParameterType.Text, false, cs, BuiltInParameterGroup.PG_TEXT, true );
}
else
{
idParamGuid = testElem.get_Parameter( uniqueIdParamName ).GUID;
}
foreach (Element elem in catFec)
{
elem.get_Parameter( idParamGuid ).Set( elem.UniqueId );
}
//add uniqueId to the schedule as a new field (column)
SchedulableField ableSf = null;
foreach (SchedulableField thisSf in vs.Definition.GetSchedulableFields())
{
if (thisSf.GetName( doc ).Equals( uniqueIdParamName ))
{
ableSf = thisSf;
break;
}
}
if (ableSf == null) //extra precaution
{
TaskDialog.Show( "Revit", "Didn't find new idParam as Schedulable Field" );
return null;
}
try
{
vs.Definition.InsertField(( ableSf, 0 );
}
catch { }
//remove all other fields except the one with the calculated value in it
for (int i = vs.Definition.GetFieldCount() - 1; i > 0; i--)
{
ScheduleField sf = vs.Definition.GetField( i );
if (sf.FieldId.IntegerValue.Equals( scheduleFieldIdInt ))
{
vsSF = sf;
}
else
{
vs.Definition.RemoveField( sf.FieldId );
}
}
vs.RefreshData();
return vs;
}