0

I am working on synchronising the view extents of maps on layouts. I can do this using .layoutByName, .itemById, .extent and then .setExtent to get the Map I want from the right layout then find its extents and apply those to another map on a different layout. Currently I am getting the items using .layoutByName but as my layout names are going to change that won't work. I think I should be able to get the layouts by their Uuid but I can't figure out how. Currently my Code is something like the code below

Surveylayout_name = '24888-TRS-02' !!!This name will change!!
SurveyMap_name = 'Tree_Survey_Map'

#getting the layout details for the source plan
manager = QgsProject.instance().layoutManager()
sourcelayout = manager.layoutByName('24888-CON-01')
get_sourceMap = sourcelayout.itemById('Constraints_A')
get_sourcemap_extents = get_get_sourceMap.extent()


#getting the target plan 
Target_layout = manager.layoutByName('24888-TRS-02')
get_TargetMap = Target_layout.itemById('Tree_Survey_Map')
get_TargetMap.setExtent(get_sourcemap_extents)  
5
  • 1
    I don't think layouts do have a uuid. The layout manager can return a list of layouts, could you use the index of that list to target them? E.g. manager.printLayouts()[0]. The list should be in the order in which they have been added. Admittedly it's a bit awkward if you need to remove layouts, or if you have lots of them. Commented Jul 10 at 21:35
  • @SirLostalot targeting using layout index works fine, I don't have many layouts that need syncing so its workable.
    – Sethinacan
    Commented Jul 11 at 8:09
  • Super, happy for me to add this as an answer then? Commented Jul 11 at 14:44
  • To do it safely you can try selecting index by a .index() method of the list, e.g. layoutlist.index('24888-CON-01')
    – rychlik
    Commented Jul 12 at 7:23
  • @SirLostalot you have my permission to answer the question,
    – Sethinacan
    Commented Jul 12 at 15:09

1 Answer 1

1

Layouts do not have a uuid. The layout manager can return a list of layouts, so you can use the index of that list to target them instead E.g.:

manager.printLayouts()[0]. 

The list should be in the order in which they have been added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.