(This is my first Revit API command). I am attempting to create a command that can select multiple doors, and then number them sequentially given a starting number, in the order they were selected. I am just attaching the code that seems necessary, all this is inside the Execute command. I have two partially working options:
DoorFilter selDoor = new DoorFilter();
DoorTest.Form1 revitForm = new DoorTest.Form1();
revitForm.ShowDialog(); //my form is very basic, one text box and OK button
string input_num = revitForm.textBox1.Text;
int number = Convert.ToInt16(input_num);
string numWrite;
//this all works fine, dialog opens and number is assigned
//Solution A
IList<Reference> doorList = rvtUIdoc.Selection.PickObjects(ObjectType.Element, selDoor, "pick doors");
foreach (Reference door in doorList)
{
numWrite = Convert.ToString(number);
Element thisDoor = myRVTdoc.GetElement(door);
thisDoor.get_Parameter("Mark").Set(numWrite);
number++;
}
// this does exactly what I want, except that selection order is not retained, and doors are numbered sequentially based on order of their creation
// I need to do more research about possibly retaining selection order with PickObjects
//Solution B
while (!quitToggle)
{
Transaction trans = new Transaction(myRVTdoc);
trans.Start("start");
Reference userSelect = rvtUIdoc.Selection.PickObject(ObjectType.Element, selDoor, "pick doors");
Element pickedElem = myRVTdoc.GetElement(userSelect);
numWrite = Convert.ToString(number);
pickedElem.get_Parameter("Mark").Set(numWrite);
trans.Commit();
number++;
}
// I know while loops should be used very sparingly, as evidenced here. This code works great until you need to quit the command, doors are numbered as you click, but pressing escape cancels all changes. My thought was to use a key Press or click to turn the quitToggle bool to true, but I think the code gets stuck in while loop.
Using PickObject like Solution B seems to work better, but I don't know how to loop back to this until the command is exited.
Thanks for you time,
Seth
(P.S. to you and Autodesk, overall awesome job with documentation and examples of the Revit API, all the online material makes it quite simple for an amateur coder like myself to start writing commands. Thanks.)