This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > September 2007 > format a floating point number





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author format a floating point number
bruce wernick

2007-09-05, 3:16 am

Hi Folks,

Can someone please tell me the right way to format a floating point number.

I get a script error when I try

NodeY = fpformat.fix(Node[1], 2)

But fpformat.fix is a standard Python function.


Thanks
Bruce
bruce wernick

2007-09-05, 3:16 am

bruce wernick wrote:
> Hi Folks,
>
> Can someone please tell me the right way to format a floating point number.
>
> I get a script error when I try
>
> NodeY = fpformat.fix(Node[1], 2)
>
> But fpformat.fix is a standard Python function.
>
>
> Thanks
> Bruce



This seems to work

s = '%.2f' % NodeX + chr(9) + '%0.2f' % NodeY

The Python 2.4 Quick Reference
http://rgruet.free.fr/PQR24/PQR2.4.html#stringModule
shows the Built-In Function
round(x, n=0)
but it causes an error. I guess there must be a missing import???

Is there a comprehensive guide on writing scripts in psp9?

Bruce
Vern Stump

2007-09-05, 6:18 pm

bruce wernick wrote:
> bruce wernick wrote:
>
>
> This seems to work
>
> s = '%.2f' % NodeX + chr(9) + '%0.2f' % NodeY
>
> The Python 2.4 Quick Reference
> http://rgruet.free.fr/PQR24/PQR2.4.html#stringModule
> shows the Built-In Function
> round(x, n=0)
> but it causes an error. I guess there must be a missing import???
>
> Is there a comprehensive guide on writing scripts in psp9?
>
> Bruce


http://www.jasc.com/support/custome...9components.asp

Vern


Fred Hiltz

2007-09-05, 6:18 pm

bruce wernick wrote:
> Can someone please tell me the right way to format a floating
> point number. I get a script error when I try NodeY =
> fpformat.fix(Node[1], 2) But fpformat.fix is a standard Python
> function.
>
> This seems to work
>
> s = '%.2f' % NodeX + chr(9) + '%0.2f' % NodeY
>
> The Python 2.4 Quick Reference
> http://rgruet.free.fr/PQR24/PQR2.4.html#stringModule shows the
> Built-In Function round(x, n=0) but it causes an error. I
> guess there must be a missing import??? Is there a
> comprehensive guide on writing scripts in psp9?


Hi Bruce. PSP 9 uses Python 2.3.3.0. Get "Paint Shop Pro 9.01
Scripting API" and "Scripting for Script Authors" at
http://www.jasc.com/support/kb/arti...components.asp. For some
reason, they still have an earlier 9.00 version of the scripting API
up there, so watch out for it.

Sorry I don't know which library contains the f.p. functions, but a
search at http://www.python.org/doc/current/lib/lib.html should turn
it up quickly.
--
Fred Hiltz, fhiltz at yahoo dot com


SuzShook

2007-09-05, 6:18 pm

bruce wernick wrote:
> bruce wernick wrote:
>
>
> This seems to work
>
> s = '%.2f' % NodeX + chr(9) + '%0.2f' % NodeY
>
> The Python 2.4 Quick Reference
> http://rgruet.free.fr/PQR24/PQR2.4.html#stringModule
> shows the Built-In Function
> round(x, n=0)
> but it causes an error. I guess there must be a missing import???
>
> Is there a comprehensive guide on writing scripts in psp9?
>
> Bruce


You don't have the command written quite correctly, Bruce - it should be
round (x, n)
to round x to n digits to the right of the decimal point. Suz


bruce wernick

2007-09-06, 3:16 am

Thanks Suz,

I'm just bumping my head on the syntax.

I did download the 'Scripting for Script Authors' pdf and will have to
read it before going any further.

Bruce


SuzShook wrote:
> bruce wernick wrote:
>
> You don't have the command written quite correctly, Bruce - it should be
> round (x, n)
> to round x to n digits to the right of the decimal point. Suz
>
>

bruce wernick

2007-09-06, 6:17 am

Thanks, the quick reference is great.

I'm extracting points from a vector to do curve fitting. As I read
through the 'Scripting through authors', I dumped the commands
collection to a file and find this one:

NodeEditAddAndFitPointList
Curve fit point list and add the result to the shape.

I'm not sure but it seems to have what I need, already build into PSP.

Does Curve fit in PSP imply that it generates a polynomial? I don't find
this command in the pdf or a Google search. Where does one find more
details about these build in commands?

Thanks
Bruce


Fred Hiltz wrote:
> bruce wernick wrote:
>
> Hi Bruce. PSP 9 uses Python 2.3.3.0. Get "Paint Shop Pro 9.01
> Scripting API" and "Scripting for Script Authors" at
> http://www.jasc.com/support/kb/arti...components.asp. For some
> reason, they still have an earlier 9.00 version of the scripting API
> up there, so watch out for it.
>
> Sorry I don't know which library contains the f.p. functions, but a
> search at http://www.python.org/doc/current/lib/lib.html should turn
> it up quickly.

Fred Hiltz

2007-09-06, 6:18 pm

bruce wernick wrote:
> Fred Hiltz wrote:
>
> I'm extracting points from a vector to do curve fitting. As I
> read through the 'Scripting through authors', I dumped the
> commands collection to a file and find this one:
>
> NodeEditAddAndFitPointList
> Curve fit point list and add the result to the shape.
>
> I'm not sure but it seems to have what I need, already build
> into PSP.
>
> Does Curve fit in PSP imply that it generates a polynomial? I
> don't find this command in the pdf or a Google search. Where
> does one find more details about these build in commands?


You are in uncharted territory here, AFAIK. I have never seen these
documented, nor heard of other vector users who have
reverse-engineered them to understand them.

My own guess about NodeEditAddAndFitPointList is that it's used in
freehand drawing to insert coordinates from the mouse pointer into
the contour being drawn. This sounds like the opposite of what you
need to extract points.

Suz is probably reading this and probably knows more as well.
--
Fred Hiltz, fhiltz at yahoo dot com


bruce wernick

2007-09-06, 6:18 pm

Fred Hiltz wrote:
> bruce wernick wrote:
>
> You are in uncharted territory here, AFAIK. I have never seen these
> documented, nor heard of other vector users who have
> reverse-engineered them to understand them.
>
> My own guess about NodeEditAddAndFitPointList is that it's used in
> freehand drawing to insert coordinates from the mouse pointer into
> the contour being drawn. This sounds like the opposite of what you
> need to extract points.
>
> Suz is probably reading this and probably knows more as well.


Thanks Fred
It seems that the graphic community doesn't have much use for the nodes
of vector paths. After much searching, I emailed Suz and she kindly
solved my main problem of extracting the node values. I'm now starting
to see huge potential with Python.
Bruce
Fred Hiltz

2007-09-06, 6:18 pm

bruce wernick wrote:
[snip]
> It seems that the graphic community doesn't have much use for
> the nodes of vector paths. After much searching, I emailed Suz
> and she kindly solved my main problem of extracting the node
> values. I'm now starting to see huge potential with Python.


True. I used them once in a script that reports the length of a
straight vector line, intended for measuring distances on a floor
plan, but have not seen much else.

Gary Barton used to work magic with vectors in scripts, but has not
been around for years. His stuff is still up at
http://pixelnook.home.comcast.net/, though, and might give you some
ideas. VectorPaint and VectorTube seem to know how to step uniform
distances along a path.
--
Fred Hiltz, fhiltz at yahoo dot com


Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews