It is currently Thu Jul 04, 2024 4:31 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Python-Fu Question (gimp-image-insert-layer)
PostPosted: Tue Nov 06, 2012 6:06 am  (#1) 
Offline
GimpChat Member

Joined: Nov 06, 2012
Posts: 11
Hi, I am experimenting with Gimp scripting. I am testing to see how various procedures in the PDB work, using the Python-Fu console (with the goal of writing some simple scripts in python).

I am encountering a problem with "gimp-image-insert-layer" when I run the following code in the Python-Fu console:

w = 3648
h = 2736
new_image = gimp.gdb.gimp_image_new(w, h, 0) #returns an IMAGE type
new_layer = gimp.gdb.gimp_layer_new(new_image, w, h, 0, "layer 1", 100, 0) #returns a LAYER type
gimp.gdb.gimp_image_insert_layer(new_image, new_layer, 0, -1)


When I run enter the last line (the call to "gimp_image_insert_layer"), I get the following error message:

Quote:
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: wrong parameter type


I also tried setting the position of the new layer to "0", but I get the same error:

w = 3648
h = 2736
new_image = gimp.gdb.gimp_image_new(w, h, 0)
new_layer = gimp.gdb.gimp_layer_new(new_image, w, h, 0, "layer 1", 100, 0)
gimp.gdb.gimp_image_insert_layer(new_image, new_layer, 0, 0)


A couple of years ago, when I was playing around with Gimp 2.6 and python scripting, I was going thru a similar exercise using "gimp_image_add_layer" I did not have any problem (but "gimp_image_add_layer" has been depreciated and is not recognized by Gimp 2.8). The main difference in calling "gimp_image_insert_layer" or "gimp_image_add_layer" is the former has an extra parameter "parent layer". But my images is new and has no layers, parent or otherwise. The info in the PDB Browers suggests that "parent layer" relates to "layer groups", and if you do not have a group, or if the inserted layer is not part of a group, then "0" should be entered for that parameter (0=None).

I am pretty sure my types are okay, "gimp_image_insert_layer" requires 4 parameters: image (an IMAGE type), layer (a LAYER type), parent payer (a LAYER type) and position (INT32).

I have tried to find an answer on web, but cannot seem to find anything addressing why I am getting this error. I am sure I must be missing something obvious. Any help would be much appreciated.

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: Python-Fu Question (gimp-image-insert-layer) [SOLVED]
PostPosted: Tue Nov 06, 2012 6:44 am  (#2) 
Offline
GimpChat Member

Joined: Nov 06, 2012
Posts: 11
I got this code to do what I intended.

I had been trying to solve this for a few hours. Most (if not all) of the stuff I found in the internet with coding examples using "gimp-image-insert-layer" were Script-Fu, and for situations where there was no "parent layer" a "0" was entered as the parameter for "parent layer." After I made the above post, I ran the code again, but used "None" rather than "0" for "parent layer," and it worked! I thought that I had tried "None" late last night but with no success - I must have been mistaken.

I wonder if the "None" vs. "0" distinction is a python thing?


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer) [SOLVED]
PostPosted: Tue Nov 06, 2012 11:07 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
gatoruss wrote:
I got this code to do what I intended.

I had been trying to solve this for a few hours. Most (if not all) of the stuff I found in the internet with coding examples using "gimp-image-insert-layer" were Script-Fu, and for situations where there was no "parent layer" a "0" was entered as the parameter for "parent layer." After I made the above post, I ran the code again, but used "None" rather than "0" for "parent layer," and it worked! I thought that I had tried "None" late last night but with no success - I must have been mistaken.

I wonder if the "None" vs. "0" distinction is a python thing?


It is consistent with the fact that in Python, the API doesn't take numeric object ids but objects references. In other words, it should be either:
gimp.gdb.gimp_image_insert_layer(new_image, new_layer, None, 0)

or
gimp.gdb.gimp_image_insert_layer(5, 12, 0, 0)

_________________
Image


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer) [SOLVED]
PostPosted: Tue Nov 06, 2012 12:44 pm  (#4) 
Offline
GimpChat Member

Joined: Nov 06, 2012
Posts: 11
ofnuts wrote:
It is consistent with the fact that in Python, the API doesn't take numeric object ids but objects references. In other words, it should be either:
gimp.gdb.gimp_image_insert_layer(new_image, new_layer, None, 0)

or
gimp.gdb.gimp_image_insert_layer(5, 12, 0, 0)


Thank you. I am not exactly sure what that means (yet)...when it comes to python or any programming or scripting language, "newbie" would greatly overstate my competence ;)

Question, though, i am note sure where the "5" and "12" came from? Are they "plug values" you use to illustrate that use of the two differenct ways to write the code?


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer)
PostPosted: Tue Nov 06, 2012 3:28 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
To put in another way, the Scheme API takes zip codes, and the Python one takes city names :)

And yes, 5 and 12 are merely examples here...

_________________
Image


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer)
PostPosted: Tue Nov 06, 2012 7:40 pm  (#6) 
Offline
GimpChat Member

Joined: Nov 06, 2012
Posts: 11
ofnuts wrote:
To put in another way, the Scheme API takes zip codes, and the Python one takes city names :)


Love the analogy! :jumpclap

Isn't your second alternative like a "zip code"?

gimp.gdb.gimp_image_insert_layer(5, 12, 0, 0)


Sorry to be obtuse.


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer)
PostPosted: Wed Nov 07, 2012 2:01 am  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
Yes... the second alternative is what the code would look like if the Python API used the zip codes.

_________________
Image


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer)
PostPosted: Wed Nov 07, 2012 5:37 am  (#8) 
Offline
GimpChat Member

Joined: Nov 06, 2012
Posts: 11
ofnuts wrote:
Yes... the second alternative is what the code would look like if the Python API used the zip codes.


So, the second alternative would not work in the Python API, since the Python API is expecting "city names" and not "zip codes," correct?

I appreciate your patience. Thank you.


Top
 Post subject: Re: Python-Fu Question (gimp-image-insert-layer)
PostPosted: Fri Dec 01, 2017 1:08 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Nov 04, 2015
Posts: 1365
Thanks ofnuts. I just used the numerical value to edit some C code and it solved a plugin error message in Gimp 2.9.
(there is a plugin written in C) :clap


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Adding a image as a layer, moving layer, and then flattening

2

No new posts Open Image window, Places column question

0

No new posts Get a mouse click or select a pixel in an image in a python plugin?

3

No new posts Attachment(s) Image Layer Disappears When I Move It

4

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

16


cron

* Login  



Powered by phpBB3 © phpBB Group