Gimp-Forum.net
A curiosity - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: A curiosity (/Thread-A-curiosity)



A curiosity - david - 09-12-2020

I have written the attached code which works perfectly (to my amazement!), except for the naming of channels. The screenshot shows the layer names which are identical to the channel names. What I was hoping to have was just the numbers 0 to 9.

I have tried: channelName=channelName[-1] and channelName=""+str(channelNum), but the result is always the same.

It is of no great importance, although I am curious to know why this is the case.

david.
Code:
for spline in splinePoints:
    
        layer_copy1 = pdb.gimp_layer_new_from_drawable(layer_copy,image)
        pdb.gimp_image_insert_layer(image,layer_copy1,None,0)            #(image,layer,parent,position)
        
        pdb.gimp_drawable_curves_spline(layer_copy1,HISTOGRAM_VALUE,len(spline),spline)#cycle through splinePoints list at each iteration
        
        channelNum=(0)                                    #integer index for channelName
        channelName=str(channelNum)                            #channelName string from channelNum

        #copy Red channel as:
        channelName = pdb.gimp_channel_new_from_component(image,CHANNEL_RED,channelName)#(image to add channel, component, channel name)
        pdb.gimp_image_insert_channel(image,channelName,None,0)                #(image,channel,parent,position)
        
        channelNum+=1                                    #increment integer index
        
        pdb.gimp_image_remove_layer(image,layer_copy1)                #remove equalized layer that was used to create masks



RE: A curiosity - tmanni - 09-12-2020

The problem is simple : you initialize the channelNum variable inside the loop (by doing channelNum=(0)).
So, at each iteration of the loop, the channelNum variable is set to (0).
Simply move the initialization of the variable before the loop :


Code:
# integer index of channelName
channelNum = (0)

for spline in splinePoints:
        layer_copy1 = pdb.gimp_layer_new_from_drawable(layer_copy, image)
        pdb.gimp_image_insert_layer(image, layer_copy1, None, 0)
        pdb.gimp_drawable_curves_spline(layer_copy1, HISTOGRAM_VALUE, len(spline), spline)
        channelName = str(channelNum)      

        # copy Red channel as:
        channelName = pdb.gimp_channel_new_from_component(image, CHANNEL_RED, channelName)
        pdb.gimp_image_insert_channel(image, channelName, None, 0)
       
        # increment integer index
        channelNum += 1                                   
       
        # remove equalized layer that was used to create masks
        pdb.gimp_image_remove_layer(image, layer_copy1)



RE: A curiosity - david - 09-12-2020

tmann,

Thank you for pointing out my stupid mistake. I think i must be becoming senile!
I only noticed the problem at the end of a long session at the keyboard. I should have walked away and come back to it with a fresh pair of eyes.

Thanks again,
david.