Need Help Getting My Revit Python Sheet Duplicator to Work

Need Help Getting My Revit Python Sheet Duplicator to Work

cmearsQS4E2
Explorer Explorer
620 Views
5 Replies
Message 1 of 6

Need Help Getting My Revit Python Sheet Duplicator to Work

cmearsQS4E2
Explorer
Explorer

All, I am a novice when it comes to Python and Revit API in general, but I'm using a combination of GPT and online resources to build and debug a sheet duplicator button for Revit using RevitPythonShell. It mostly of works. If I duplicate a sheet, it will now duplicate the views on the sheet and locate them on a new sheet so that it looks identical to the first... The first time. It adds the suffix ".1" to the back of the new sheet number and view names. In other words, "architectural floor plan" becomes "architectural floor plan.1" and sheet number A1.0 becomes A1.0.1. That's all well and good, but if I try and duplicate the original sheet a second time, it doesn't work because A1.0.1 already exists and it doesn't know to go to A1.0.2... and so on. Could someone help me fix my code to resolve this issue? My code is attached. Feel free to use if anyone wants it. 


621 Views
5 Replies
Replies (5)
Message 2 of 6

WillianMayrink
Participant
Participant

Try this, after 

# Add a name to the new sheet #

 

 

firstTry = True
numberCopy = 0
nameOk = True
while(nameOk):
    try:
        if(firstTry):                
            newsheet.Name = vs.Name
        else:
            newsheet.Name = vs.Name + "copy " + str(numberCopy)
        nameOk = False
    except:
        numberCopy = numberCopy + 1

 

Message 3 of 6

WillianMayrink
Participant
Participant

In fact, I was wrong, you should use this code :

 

 

suffix = 1
numberOk = True
while(numberOk):
    try:                        
        newsheet.SheetNumber = vs.SheetNumber + "." + str(suffix) 
        numberOk = False
    except:
        suffix = suffix + 1

 

 

 

It because revit allow use same name for diferrents sheets, but the number sheet should be unique in doc.

 

Message 4 of 6

cmearsQS4E2
Explorer
Explorer

Hmm.  Thank you for the suggestion. Something about that code crashes my Revit when I try it. Maybe I formatted it wrong? This is the first time I've had this happen.

0 Likes
Message 5 of 6

cmearsQS4E2
Explorer
Explorer

you know what, I think I caught the error. your snippet says nameOk = False rather than the newly defined numberOk = False.

Would I do a similar code for the views which also have to be uniquely named? 

firstTry = True
viewnameOk = True
while(viewnameOk):
try:
if(firstTry):
newview.Name = ev.Name + "." + str(suffix)
else:
newview.Name = ev.Name + "." + str(suffix)
viewnameOk = False
except:
firstTry = False
suffix = suffix + 1

I don't know if I need to redefine first try or if it will pick that up from being previously defined above?

Message 6 of 6

cmearsQS4E2
Explorer
Explorer

I got it to work without that last step. Thank you so much for your help!