<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><br><br><div>> Date: Thu, 4 Jun 2015 21:52:32 -0400<br>> From: gpittman@iglou.com<br>> To: scribus@lists.scribus.net<br>> Subject: [scribus] Python scripter - scribus.setFont() and scribus.setTextAlignment() ? -- Solution<br>> <br>> I somehow lost this email from my client, but here it is copied from the<br>> Archives:<br>> *************************<br>> I am trying to run the following (very simple) script:<br>> <br>> #!/usr/bin/env python<br>> # -*- coding: utf-8 -*-<br>> <br>> import sys<br>> try:<br>> import scribus<br>> <br>> except ImportError:<br>> print "This script only works from within Scribus"<br>> sys.exit(1)<br>> <br>> n = scribus.selectionCount()<br>> <br>> for count in range(0,n):<br>> textbox = scribus.getSelectedObject(count)<br>> scribus.messageBox('Error:', textbox);<br>> scribus.setFont('Arial Regular', textbox)<br>> scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox)<br>> scribus.setTextColor("White", textbox)<br>> scribus.setFillColor("Red", textbox)<br>> <br>> <br>> However it fails after one iteration. The error message is:<br>> <br>> Traceback (most recent call last):<br>> File "<string>", line 8, in <module><br>> File "/home/.../SetTableHeading.py", line 17, in <module><br>> scribus.setFont('Arial Regular', textbox)<br>> NoValidObjectError: Cannot use empty string for object name when there is<br>> no selection<br>> <br>> If I remove the function calls scribus.setFont() and<br>> scribus.setTextAlignment(), the script runs fine, but I dont know why...<br><br></div><div>Arial is a Windows font, and some Linux systems do not have it.</div><div><br></div><div>I have the code below in one of my test scripts.</div><div><br></div><div><div> try:</div><div><br></div><div> scribus.setFont("Arial Regular", txt)</div><div><br></div><div> except:</div><div><br></div><div> try:</div><div><br></div><div> scribus.setFont("FreeSans Medium", txt)</div><div><br></div><div> except:</div><div><br></div><div> pass</div></div><div><br></div><div>Regards,</div><div>William</div><div><br></div><div><br></div> </div></body>
</html>