[scribus] Python scripter - scribus.setFont() and scribus.setTextAlignment() ? -- Solution

Anders Jensen jensen.anders.87 at gmail.com
Mon Jun 8 10:27:42 UTC 2015


Yes, great - it works!
This saves my a lot of time :)

On Fri, Jun 5, 2015 at 3:52 AM, Gregory Pittman <gpittman at iglou.com> wrote:

> I somehow lost this email from my client, but here it is copied from the
> Archives:
> *************************
> I am trying to run the following (very simple) script:
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import sys
> try:
>    import scribus
>
> except ImportError:
>    print "This script only works from within Scribus"
>    sys.exit(1)
>
> n = scribus.selectionCount()
>
> for count in range(0,n):
>     textbox = scribus.getSelectedObject(count)
>     scribus.messageBox('Error:', textbox);
>     scribus.setFont('Arial Regular', textbox)
>     scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox)
>     scribus.setTextColor("White", textbox)
>     scribus.setFillColor("Red", textbox)
>
>
> However it fails after one iteration. The error message is:
>
> Traceback (most recent call last):
>   File "<string>", line 8, in <module>
>   File "/home/.../SetTableHeading.py", line 17, in <module>
>     scribus.setFont('Arial Regular', textbox)
> NoValidObjectError: Cannot use empty string for object name when there is
> no selection
>
> If I remove the function calls scribus.setFont() and
> scribus.setTextAlignment(), the script runs fine, but I dont know why...
>
> I am running Scribus 1.4.3 and python 2.7.6 under Ubuntu 14.04.2 LTS.
>
> I am not able to find any solution to this - any suggestions?
>
> regards,
> Anders
>
> *****************************
>
> I'm not quite sure why this doesn't work, but I am able to accomplish
> what you're looking for (I think) with a modified syntax. Basically,
> instead of relying on the count of the selection, I create a list of
> frame names, then feed that list into your text manipulations...
>
> *************
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import sys
> try:
>    import scribus
>
> except ImportError:
>    print "This script only works from within Scribus"
>    sys.exit(1)
>
> n = scribus.selectionCount()
> boxes = []
>
> for x in range(n):
>   frame = scribus.getSelectedObject(x)
>   boxes.append(frame)
>
> for textbox in boxes:
>     scribus.messageBox('Error:', textbox);
>     scribus.setFont('Arial Regular', textbox)
>     scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox)
>     scribus.setTextColor("White", textbox)
>     scribus.setFillColor("Red", textbox)
>
> *************
>
> Greg
>
> ___
> Scribus Mailing List: scribus at lists.scribus.net
> Edit your options or unsubscribe:
> http://lists.scribus.net/mailman/listinfo/scribus
> See also:
> http://wiki.scribus.net
> http://forums.scribus.net
>
-------------- neste del --------------
Et HTML-vedlegg ble skilt ut...
URL: <http://lists.scribus.net/pipermail/scribus/attachments/20150608/f19277a4/attachment.html>


More information about the scribus mailing list