- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning all (from Australia),
I work in retail and all our rooms are standardised and carry some data. Once we start a new refurb we need grab the old store 3D model and amongst other things, replace all rooms by the latest we have in our template. We've been doing this manually for many years but I'd like to automate that task by replacing matching room names.
Attempt 1: ElementTransformUtils
I managed to achieve that programatically creating a new project from our template and using ElementTransformUtils to copy the rooms from it. The challenge I had with this approach is that the rooms kept on pasting on the same level (ground) regardless of the active view (probably expected since I used the CopyElements method, doc to doc).
Attempt 2: Change level property
After some research I found an article where someone showed we need to change the level of the elements post pasting but the example was for columns and rooms don't accept level changes once they are placed (why is that by the way?).
Attempt 3: PostableCommand
I then moved on to PostableCommand to try and copy/paste aligned to current view but Revit didn't like it and threw a "Revit does not support more than one command are posted". I'm actually not sure I'm using it right in the way of swapping documents for each action. How would I make a selection in the newDoc below? I'm not sure how to make it the active document and swap back. Thank you for reading.
// Create new file from template
Document newDoc = app.NewProjectDocument(TemplateLocation);
// Make a selection or rooms
var selector = uidoc.Selection; // I doubt this is working as uidoc refers to the active document, not the newDoc.
selector.SetElementIds(copyRoomIds);
// Copy to clipboard
RevitCommandId copyToClip = RevitCommandId.LookupPostableCommandId(PostableCommand.CopyToClipboard);
uiapp.PostCommand(copyToClip);
// Paste aligned to active view
RevitCommandId pasteAligned = RevitCommandId.LookupPostableCommandId(PostableCommand.AlignedToCurrentView);
uiapp.PostCommand(pasteAligned);
Solved! Go to Solution.