Hello Dynamo friends,
When i duplicate a view “xyz” i want to give it the same name with some addon like “xyz - copy”.
I’ ve i want to duplicate “xyz” again it won´t work because the name is already used.
So i just want to ask if there is some way to solve this problem without going the way of getting all views nin project, get their names and test if the name already exists.
Revit is so intelligent that it is naming new duplicates automatically “copy 1”, “!copy 2”, etc…so is there a way that dynamo also does this automatically?
Would be happy about your thoughts!
if you want to duplicate multiple times, then the input of the name should be list of names that equal the number of how many views do you want
Thanks but that is not the problem. I want to make only one duplicate. But if i want to do another one later i have to avoid the equal names.
Now I´m confused, I let dynamo check if the name “copy” is already used and if so to name the view “copy 1”. Can you see what dynamo did this time? It ignored my view name and did exactly what i would want it to. Dynamo automatically gave the view the addon “(2)”
It seems that by adding ANY string to the view name, dynamo starts automatic numbering to avoid same names.
I don´t understnd why but it seems to work like this now. If someone has some more knowledge of this behavior, please clear things up.
So i did some testing with the following results:
If dynamo duplicates a view that has the same name, dynamo in fact will create the view and it will get the addon “copy #” as you can see here:

Although it works the graph looks like this:
The graph gives out errors and that means i can´t place the view on the sheet 
Maybe try just duplicating the views and at first let Revit name them. Then rename the view after creation(?) Then pass the views to Viewport.Create.
myView = doc.ActiveView
option = ViewDuplicateOption.Duplicate
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
newview = myView.Duplicate(option)
myNewView = doc.GetElement(newview)
myNewView.Name = "New Name"
TransactionManager.Instance.TransactionTaskDone()
1 Like
You could always try creating the views using Python, and put that step in a Try/Except statement. I’m pretty sure the error is caught by this and would skip creating that view. The except side of the statement could also be a view creation method with something unique added to it, like the current time and date so that you know it has to be unique.
1 Like
Thanks aaron, i got the duplicating working, but I´m struggling to get the new view as output.
IN = myView = UnwrapElement(IN[0])
option = ViewDuplicateOption.Duplicate
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
newview = myView.Duplicate(option)
TransactionManager.Instance.TransactionTaskDone()
OUT = newview


OUT = doc.GetElement(newview)
maybe
1 Like
yes! 
IN = myView = UnwrapElement(IN[0])
option = ViewDuplicateOption.Duplicate
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
newview = myView.Duplicate(option)
TransactionManager.Instance.TransactionTaskDone()
OUT = doc.GetElement(newview)
Duplicate_View.dyn (20.0 KB)
OUT = doc.GetElement(DB.ElementId(newview))
incase all you have is an int.
1 Like
Yes. The duplicate view just returns the element id. You then need to get the actual element from the Id. You’ll also want a loop in there to process more than one view.
1 Like
Here it is with a loop. You’ll have to work out what you want for the name.
The issue is that you can’t just do:
myNewView.Name = myNewView.Name + myName
That tosses the duplicate name error.
You need to cast it to a string first.
myNewView.Name = str(myNewView.Name) + myName
That works fine.
myViews = IN[0]
myName = IN[1]
option = ViewDuplicateOption.Duplicate
doc = DocumentManager.Instance.CurrentDBDocument
myNewViews = []
myNewViewNames = []
for v in myViews:
inView = doc.GetElement(ElementId(v.Id))
TransactionManager.Instance.EnsureInTransaction(doc)
newview = inView.Duplicate(option)
TransactionManager.Instance.TransactionTaskDone()
myNewView = doc.GetElement(newview)
myNewView.Name = str(myNewView.Name) + myName
myNewViews.append([myNewView, myNewView.Name])
OUT = myNewViews
Just change the myNewView.Name = str(myNewView.Name) + myName line to account for the new name prefix/suffix or whatever other modification you need.
Of course the IN[1] could also be a list, but you would need to modify the loop to account for that.
Change the myNewViews.append([myNewView, myNewView.Name]) to just myNewViews.append(myNewView) if you only want the view and no name, of course.
1 Like
Thanks for your help @aaron_rumple !
I´m pretty happy with the name that revit gives to the views so i cleaned up your code a little bit and it works for me fine now:
Just wanted to ask if i now have some unnaccasary lines in there?!
What exactly is the “.append” line for?
myViews = IN[0]
option = ViewDuplicateOption.Duplicate
doc = DocumentManager.Instance.CurrentDBDocument
myNewViews = []
for v in myViews:
inView = doc.GetElement(ElementId(v.Id))
TransactionManager.Instance.EnsureInTransaction(doc)
newview = inView.Duplicate(option)
TransactionManager.Instance.TransactionTaskDone()
myNewView = doc.GetElement(newview)
myNewViews.append(myNewView)
OUT = myNewViews
.append is standard python. It is adding each new myNewView to the list myNewViews that is then set as output.
1 Like