It is currently Thu Mar 28, 2024 7:16 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: data type confusion
PostPosted: Sat Mar 28, 2015 12:16 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Mar 27, 2015
Posts: 22
Hi,

If you look at the script below, I'm puzzled by something...

[size=85](set! theLayer (car
                          (gimp-layer-new
                           remappedImage
                           TileSize
                           TileSize
                           RGBA-IMAGE
                           layerName
                           100
                           NORMAL
                          )
                )
      )
   
   
   ; insert that layer into the remapped image
   (gimp-image-insert-layer remappedImage theLayer 0 0)
   
   
   ; get the layer ID
   (set! layerInsertID (car (gimp-image-get-active-layer remappedImage)))
   (set! layerInsert (car (gimp-item-get-name layerInsertID)))
   (if (= debug TRUE) (begin (debug-message (string-append "after insert layer is " layerInsert )  )))
   
   (gimp-layer-set-offsets theLayer mselXpos mselYpos)[/size]


If I use "theLayer" as a parameter all is good.
If I use layerInsert as a parameter all is not good.
Yet they appear to be the same if I print out the values.

Can anyone shed some light on this please?


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: data type confusion
PostPosted: Sat Mar 28, 2015 12:42 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
When you say:
Quote:
If I use "theLayer" as a parameter all is good.
If I use layerInsert as a parameter all is not good.
.. I presume you are referring to the call to (gimp-layer-set-offsets ), in which case I think you meant to use layerInsertID rather than layerInsert ..the latter is a name string.

BTW, if you haven't already "discovered" it, the Script-Fu Console (SFC) should be your constant companion when scripting ..and the Error Console is your best friend when the going gets tough. When you get into a sticky situation, try it on the SFC exactly as per your script.


Top
 Post subject: Re: data type confusion
PostPosted: Sat Mar 28, 2015 2:22 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Mar 27, 2015
Posts: 22
Thanks for the reply, not sure how to use the console, it only seems to have a one line text box.
I'm used to Maya and the script window in there.
Like how do you test larger bits of code, with several variables?


Top
 Post subject: Re: data type confusion
PostPosted: Sat Mar 28, 2015 2:34 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Dec 27, 2014
Posts: 508
Short answer: one line at a time!


Top
 Post subject: Re: data type confusion
PostPosted: Sat Mar 28, 2015 2:37 pm  (#5) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
Have a look at A Script-Fu Tutorial.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: data type confusion
PostPosted: Sat Mar 28, 2015 3:42 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Sweeney wrote:
Thanks for the reply, not sure how to use the console, it only seems to have a one line text box.
I'm used to Maya and the script window in there.
Like how do you test larger bits of code, with several variables?

Enter your code into a separate text editor (preferably one that at least highlights matching parentheses), and then copy-n-paste the code into GIMP's Script-fu console as you debug it.

You can have multiple lines but your pasted code needs to be complete Scheme expressions. For example, if you paste in "(define x 10", leaving off the trailing parenthesis, the console will not wait for you to enter in the parenthesis; it will merely print out that an <EOF> was encountered and 'x' will not be defined.

When using a lot of variable bindings that appear in your code in a 'let' block, these will typically need to be converted to define statements if you wish to interact with your code step-by-step. For example, consider the following bit of code:

  (let ((x-offset (car (gimp-drawable-offsets layer)))
        (y-offset (cadr (gimp-drawable-offsets layer)))
        (width (car (gimp-drawable-width layer)))
        (height (car (gimp-drawable-height layer))))
    ; do some stuff here
    ; more stuff
    )


You can execute the entire block by pasting it into the console, however, when debugging you will probably wish to execute some of the "stuff" line-by-line, using the values for the offsets and dimensions. To accomplish this, you need to convert them to 'define' statements:

(define x-offset (car (gimp-drawable-offsets layer)))
(define y-offset (cadr (gimp-drawable-offsets layer)))
(define width (car (gimp-drawable-width layer)))
(define height (car (gimp-drawable-height layer)))


While testing, I usually keep a second, temporary file open in my text editor to store these 'defined' versions of the bindings. I've also created a macro that saves some editing in creating such definitions.
(define-macro (dlet args)
  (cons 'begin (map (lambda (x) (cons 'define x)) args)) )

With this macro defined, one can take the beginning of a 'let' declaration up to the end of the bindings, prepend a 'd' to the "let" and add a closing parenthesis to the end. Thus
(let ((x 10) (y 20) (z 30))
  <body>
  )

becomes:
(define x 10)
(define y 20)
(define z 30)

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) SOLVED Wrong version of script running due to folder locn confusion

9

No new posts Attachment(s) save restore data on demand

12

No new posts Parse Device Data size Error - FIXED

5

No new posts wrong parameter type in pdb.plug_in_cubism

9

No new posts Can't open files 'Unknown file type'

7



* Login  



Powered by phpBB3 © phpBB Group