Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get_BoundingBox drastically slow down script

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
vitalij.marcukov2BP2F
436 Views, 8 Replies

get_BoundingBox drastically slow down script

Hello, 

 

I use the below to get a bounding box of a titleblock schedule on a sheet. This particular bit drastically slows down my script. If I hard code XYZ coordinates, then the script runs no more than 10 seconds. If I use the below, it takes around 5-6 minutes. Please advise if this is what it is or there is an efficient way of getting bounding box or coordinates of a titleblock schedule.

bounding_box = schedule_instance_element.get_BoundingBox(picked_sheet)

 

8 REPLIES 8
Message 2 of 9

Hi @vitalij.marcukov2BP2F,

The get_BoundingBox() can be slow if the sheet contains a lot of data because Revit keeps recalculating the bounding box for the element every time get_BoundingBox() is called.

Is it possible to store the bounding box values in a cache and use them where necessary?

Example, if you get the minPoint and maxPoint as below, you can save them in a cache to re-use later.
XYZ minPoint = schedule_instance_element.get_BoundingBox(picked_sheet).Min;
XYZ maxPoint = schedule_instance_element.get_BoundingBox(picked_sheet).Max;

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 3 of 9

Hello @moturi.magati.george

Thank you for the reply.

So basically, the script is: Revit user pick revision (only 1 allowed), then picks sheets where the revision need to be set to. The script applies revision to sheets and also places generic annotation family based on titleblock schedule max coordinates. So I need to call get_BoundingBox for each schedule/picked sheet if that makes sense. So not sure how I can store it in a caches...

Message 4 of 9

Hi @vitalij.marcukov2BP2F ,

 

Are you refering to the Revision Schedule that's inside the TitleBlock?

 

Maybe get the point of the ScheduleSheetInstance, and calculate width/height from the TableSectionData ?

https://www.revitapidocs.com/2023/a7d3080d-811d-4c71-d15a-1a466de68df0.htm 

https://www.revitapidocs.com/2023/e067f2c7-f809-89d4-5b61-a93004e3710d.htm 

https://www.revitapidocs.com/2023/f83926e3-44de-82f4-250e-254d087001de.htm 

Etc.

 

- Michel

Message 5 of 9

as something to try, once user selects the sheet, set it as the active view, then your code becomes:

bounding_box = schedule_instance_element.get_BoundingBox(activeview)

 no guarantees it will be any faster, but its something ive done with no noticeable slowdown.

Message 6 of 9

Hello @TripleM-Dev.net,

 

I have done a quick test and your advice has solved the problem. I will do my best to finalize the script this weekend and provide a full feedback / mark your advice as solved. Thank you.

Message 7 of 9

@ctm_mka

 

Thank you. Will test it to check timings. 

Message 8 of 9
TripleM-Dev.net
in reply to: ctm_mka

Uhm, yes this is it. The function triggers a refresh so if the sheet has large views on it it will definitly slow it down.

So a second time (if nothing changed) it should run faster?

Message 9 of 9

Hello @TripleM-Dev.net,

Thank you for your help. Your advice steered me towards the right direction. 

 

I used Point property to get the placement point of revision schedule within the sheet coordinates and then used GetScheduleHeightsOnSheet().GetBodyRowHeights() to get the row heights as per the code below. It takes seconds to execute the code rather than minutes. 

 

schedule_origin = schedule_instance_element.Point
ip_x, ip_y, ip_z = schedule_origin[0], schedule_origin[1], schedule_origin[2]
view_schedule_height = sum(view_schedule_element.GetScheduleHeightsOnSheet().GetBodyRowHeights())
insertion_point = XYZ(ip_x, (ip_y + view_schedule_height + 0.01572111827428), ip_z)
return insertion_point

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report