Forum

Author Topic: Adding labels to shape groups  (Read 99 times)

Abe Whaanga

  • Newbie
  • *
  • Posts: 5
    • View Profile
Adding labels to shape groups
« on: November 10, 2019, 10:43:34 PM »
does anyone know how I might add labels to shape groups via a python script?  I have a script that creates a bunch of default shape groups, but I want the labels for everything in these shape groups to match the group name.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
Re: Adding labels to shape groups
« Reply #1 on: November 11, 2019, 10:16:48 AM »
Hello Abe,

Do you mean to add the label to every shape in the group that corresponds to the group name?
Best regards,
Alexey Pasumansky,
AgiSoft LLC

Abe Whaanga

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Adding labels to shape groups
« Reply #2 on: November 11, 2019, 09:41:05 PM »
Hi Alexey,

Yes every shape in the group that gets drawn needs to have a label that is the same as the group name.  My script below creates the default shape groups.


   current_document = Metashape.app.document
   current_chunk = current_document.chunk
   
   default_shp_groups = {'QV Maj':[255,0,0], 'QV Min':[255,0,0], 'FAULT':[38,0,255],'AN':[0,170,0], 'CHL':[0,0,0], 'BM':[0,0,0], 'CL':[0,170,255], 'COR':[0,85,0], 'INE':[255,85,0], 'BND':[0,0,0], 'BX':[0,0,0], 'MAS':[0,0,0], 'OX':[255,85,0], 'pd':[0,0,0], 'stk':[255,0,0] }

   #loop new groups to add
   for new_shp_group_key in default_shp_groups:
   
      #set test if group to be added already exists to False
      new_shp_group_key_exists = False
   
      #loop existing groups
      for existing_shp_group in current_chunk.shapes.groups:
      
         #test if new group to be added already exists      
         if new_shp_group_key == existing_shp_group.label:
            new_shp_group_key_exists = True
   
      if new_shp_group_key_exists == False:   
         new_group = current_chunk.shapes.addGroup()
         new_group.label = new_shp_group_key
         new_group.color = (default_shp_groups[new_shp_group_key][0], default_shp_groups[new_shp_group_key][1], default_shp_groups[new_shp_group_key][2])


   

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
Re: Adding labels to shape groups
« Reply #3 on: November 12, 2019, 01:59:10 PM »
Hello Abe,

You can assign the shape labels after their are drawn according to the layer labels in the following way:
Code: [Select]
for shape in chunk.shapes:
    if not shape.label:
         shape.label = shape.group.label
Best regards,
Alexey Pasumansky,
AgiSoft LLC

Abe Whaanga

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Adding labels to shape groups
« Reply #4 on: November 12, 2019, 11:36:59 PM »
Thanks Alexey works great :D