PythonAPI and groups

Previous topic - Next topic

tropion

Is there a good reason for why the PythonAPI can not access objects in groups?

MrB

There is the function getGroupItems(), so not sure what you're trying to do. Maybe some sample code? If some function is missing in Scripter, then we can add it.

tropion

getGroupItems() gives me the names of the objects in the group (if it is a top level group), but I can not select or move or manipulate these objects in any way. Objects that are in a group in a group are entirely inaccessible.

I submitted a patch to fix this, but I am not sure if it was intended behaviour

The captcha is broken.

henrylaw

I too have found that, while I can get a list of the object names, I can't even access them to determine their properties.  I have an existing document which I'm trying to analyse; it has groups of text frames and I want to examine the paragraph styles assigned to each of those frames.  This code fragment shows how I'm trying to do it:
grouped_items = scribus.getGroupItems( 'group name', type=4 )
for gi in grouped_items:
    if gi[1] == 4:
        try:
            para_style = scribus.getParagraphStyle( gi[0] )
        except scribus.NoValidObjectError:
            print( f"Object not found: '{gi[0]}'" )
            continue
        print( f"Item '{gi[0]}' in group; style '{para_style}'" )

I get "Object not found" for every text frame in the group.

The getGroupItems method could be really useful, essential even; but not if you can't do anything with what it finds.

henrylaw

I've found a workround for this; if you retrieve the names of the objects in the group and then ungroup it, you can then access their properties by name.  But you have to issue "closeDoc()" before exiting your script as otherwise Scribus will remain open and ask for confirmation.

Here's a code fragment which works.  (It processes text frames unless they have paragraph style "diary_style")

grouped_items = scribus.getGroupItems( item_name, type=4 )
scribus.unGroupObjects( item_name )
for gi in grouped_items:
if gi[1] == 4:
  try:
    para_style = scribus.getParagraphStyle( gi[0] )
  except scribus.NoValidObjectError:
    print( f"Object not found: '{gi[0]}'" )
    continue
  if para_style != diary_style:
    process_text_frame(gi[0])
    ... etc