It is currently Mon Jul 01, 2024 3:35 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 3:01 pm  (#1) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
Hey all, i've been searching the web slowing learning bits and pieces of gimps Scheme scripting in order to make a few tasks I have a bit easier but have run into a road block I could sure use a little bit of help with. :)

I'm fairly new to coding in general and brand new to Gimps Script-fu so go slow and easy on me.

Heres my question.

I'm looking to be able to use the gimp-file-load-layers procedure to grab a multi page .Tif file and then use the insert-layer procedure to drop them in so I can then do some other tweaking to them. My problem being is that I just don't understand the Return values that load-layers creates and how to access them.

So here's a snippet of how i'm currently using it. (map(car(gimp-file-load-layers RUN-NONINTERACTIVE main input1)))

this works as far as I can tell... at least it seems to actually go and grab the file and load it into layers but then when it's time to use insert-layer I need to provide the LAYER parameter which I understand is a layer-id generated by load-layers but where is it put or how can I access it?

Again i'm pretty new to all this so its highly likely that i'm missing something obvious or that I just don't understand something correctly. Any help to point me in the right direction or any explanations on how this all works would be tremendous. :) Thanks!


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: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 3:34 pm  (#2) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
Ok so i've been doing more digging, more reading, more trial and error. Tell me if i'm wrong but it seems like load-layers first return value of num-layers is ignored by script-fu and only the second return value of layer-ids is actually used. So if thats the case then i have to assume that the Variable I assigned the load-layers procedure now contains that "list" that variable in this case being "map". So now I need to learn about how to access that list of variables from "map" and then set each of the returns from that variable to its own variable so that I can then use those to insert the layers in the order I want?

Brain=broken


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 4:39 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Nov 04, 2015
Posts: 1365
Hi Randomsteve.
You say "grab a multi page .Tif file"
Are they already in tiff form or do you have to produce many tifs?

If already in tif form then launch Gimp File>Open as layers works very well.


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 5:22 pm  (#4) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
Thanks for the reply. Sorry if I didn't explain myself better before.

Basically I've got a script all written up and working that lets me import several different files and then it automatically does a bunch of different processing, cropping, and other adjustments to it and then saves it as a new file. I now need to add the functionality to be able to handle .Tiff files that are multiple pages.

So right now to load a file and insert it as a layer its a very simple process.

layervariable(gimp-file-load-layer imagevariable location-of-image)

and then

gimp-image-insert-layer imagevariable layervariable

Right, so basically load up a file as a layer for the image im working on, and then insert said layer into the image im working on. Works fine and dandy and everything is great until you need to choose a .Tiff file that is more then 1 page. With a multipage .Tiff file it will only insert all pages into the same layer thus overwriting everything but the last page.

So instead I need to be able to use gimp-file-load-layers

my problem is now the variable attached to gimp-file-load-layers contains an array of multiple layers instead of just a single layer id. I've been trying to figure out how arrays work in Scheme and how to access them and assign their values to different variables but I can't seem to figure it out.


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 5:48 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
Not familiar with script-fu. In Python, i get two items, a count and a list of ids, the count being the size of the list). In script-fu, I would expect something like: ( count ( id1 id2 id3 ... idN ) ), where idX can be used directly in gimp-image-insert-layer or gimp-image-add-layer.

In Python:
_,layers=pdb.gimp_file_load_layers(image,'/tmp/layers.xcf')
for l in layers:
    image.add_layer(gimp._id2drawable(l))

In Python-fu, most of the API doesn't deal with integer ids but deals instead with objects. This call is one of the few that returns ids instead of objects, so gimp._id2drawable() is used to create the object from the id.

_________________
Image


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 6:00 pm  (#6) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
little over my head I think. don't know a ton about scheme, even less about python. Trying to wrap my head around one and translate concepts from one to the other is beyond me I think.

I've been trying to wrap my head around exactly what it is that the gimp-image-get-layers procedure does and in gimps procedure browser under return values it states this:

Return Values:
num-layers INT32 The number of loaded layers (num-layers >= 0)

layer-ids INT32ARRAY The list of loaded layers


This looks to me like the data of the layers ids returned from this procedure is handled with an array instead of a list? is this true? and if so how can I get this array to list out from me and print out into a console or something so I can see whats going on?


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Mon Mar 04, 2019 8:16 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
Randomsteve wrote:
little over my head I think. don't know a ton about scheme, even less about python. Trying to wrap my head around one and translate concepts from one to the other is beyond me I think.

I've been trying to wrap my head around exactly what it is that the gimp-image-get-layers procedure does and in gimps procedure browser under return values it states this:

Return Values:
num-layers INT32 The number of loaded layers (num-layers >= 0)

layer-ids INT32ARRAY The list of loaded layers


This looks to me like the data of the layers ids returned from this procedure is handled with an array instead of a list? is this true? and if so how can I get this array to list out from me and print out into a console or something so I can see whats going on?


This is why I don't bother with script-fu. In Python lists and arrays are about the same (in any case, you can apply the same tools to them...). You can be comfortable with python in one afternoon, and you can do more things with it.

_________________
Image


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Tue Mar 05, 2019 8:13 am  (#8) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Provided you can identify the image id, you can use the Script-fu console to enter the commands manually:

Attachment:
Untitled.png
Untitled.png [ 14.87 KiB | Viewed 5997 times ]

So, yes, the "list" of layer-ids is an array (or a vector in Script-Fu)

Here I've converted the vector into a list using vector->list


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Tue Mar 05, 2019 11:55 pm  (#9) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
Thats really helpful thanks!

Any chance you could explain what cadr does in that command? I understand the rest of the command but am unfamiliar with that command.

thanks :)


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Wed Mar 06, 2019 2:37 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
https://en.wikipedia.org/wiki/CAR_and_CDR#Compositions

_________________
Image


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Wed Mar 06, 2019 3:33 am  (#11) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
So correct me if i'm wrong but this line

(cadr(gimp-image-get-layers 5))

is basically say get the first item (car) and get everything but the first item (cdr) thus the abbreviation for cadr?

and then vector->list(cadr)

is basically the same thing? include first item in the vector and include everything else other then the first item in the vector thus cadr and then make it a list?

can I call that same line with a variable in front of it to then store the list? so something like this

(layerList(vector->list(cadr(gimp-image-get-layers 5))))


Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Thu Mar 07, 2019 11:40 am  (#12) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Yes, cdr gets everything in a list after the first element and car gets the first element. cadr therefore gets the second element in the list.

Yes you can assign a variable to the result of (vector->list(cadr(gimp-image-get-layers 5)))

Here's a quick script to illustrate:
(define (script-fu-randomsteve filename)
  (let*
    (
      (imageId (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
      (layerList (vector->list(cadr(gimp-image-get-layers imageId))))
    )
    (for-each
      (lambda (layerId)
        (gimp-message (string-append "layer " (car (gimp-layer-get-name layerId))))
      ) layerList   
    )
    (gimp-display-new imageId)
    (gimp-displays-flush)
  )
)

(script-fu-register "script-fu-randomsteve"
    "Randomsteve"
    "This is Randonsteve's script"
    "(C) Randomsteve"
    "Randomsteve"
    "0.0"
    ""
    SF-FILENAME      "File to load" ""
)
(script-fu-menu-register "script-fu-randomsteve" "<Image>")




Top
 Post subject: Re: Script-fu load-layers help
PostPosted: Thu Mar 07, 2019 2:14 pm  (#13) 
Offline
GimpChat Member

Joined: Mar 04, 2019
Posts: 7
Oh that makes perfect sense. Thank you so much. I believe with this new found knowledge I should be able to get my script working the way I need.

:tyspin


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Load As Layers Wire Initialization Error With Python

6

No new posts script to load text file and create text layer

6

No new posts Attachment(s) Unable to load an image as layer

16

No new posts Cant load GMIC plugin in gimp

2

No new posts Watch Folder and load image as layer

1



* Login  



Powered by phpBB3 © phpBB Group