Can't delete element because of ID issue


I have some issues with deleting sheets with python code. Code is similar with the archi-lab node but i have added some additional functionality to this. Error message is shown in the bottom.


# Obtaining titleblocks
for sheet in shts:
	trans = SubTransaction(doc)

for i in elements_on_sheet_ids:
    for j in i:

for i in elements_on_sheet:
    if i.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM).AsValueString() == "Title Blocks":


This error seems to disappear when I restart my computer. Do you have any solution for this to work every time?

Error in Dynamo:


why do you use sub transaction at all? First loop is quite strange


First loop is a bit funny.

Where is the rest of your code. Is line 37 that loop?


Are you just trying to get all the items on the sheet? If so, I think there would be a better way to do this then pseudo deleting the sheet like this. What is your goal here?


Yes I am just trying to get elements on sheet because I want to get titleblock located on sheet.
Sub transaction is just to delete elements and restore them. This is the approach that was used in archi-lab node “Elements on Sheet”
Rest of my code is not important because this is very long and does not affect first few lines.


Just try getting Titleblocks directly from the sheet. Maybe see this post for information.


Yes I know this solution because I already used this. However right now I want to use python code for this not just a custom node. I am trying to learn python a bit and I don’t know why it does not work properly.
Thanks for your input :slight_smile:


Have you tried opening up the custom node to see how it works? Often times it is python inside as you require. Just double click and look around.

Also, since Sheets are really views, you can use a Filtered Collector like this
TB = FilteredElementCollector (doc,Sheet.Id).Of Category(BuiltInCategory.OST_TitleBlocks).ToElements()



Yes but right now my input is just a few sheets from which I want to grab titleblocks. I dont need to collect all titleblocks available in the project.
So to sum up:
I have list of sheets -> I want to have list of titleblocks located on these sheets ( there might be different sizes of titleblocks)

I want to do this because I am writing a code to copy selected sheets with views and legends for next stage of the project and keep the old set present in the Revit file.


Correct. The code I supplied will only get the Titleblock(s) on the sheet supplied. That is why the Sheet.Id is used in the collector. That limits the collector results to only the view (in this case sheet) supplied.

for sheet in shts:

Oh great! i didnt notice this. Thanks for your help. Very appreciated!

This solves my problem but still doesnt solve the issue stated in the first post :smiley: