08-08-2017, 08:18 PM
(08-08-2017, 02:09 PM)Juniata Wrote:(08-07-2017, 09:33 PM)Ofnuts Wrote: Do not, ever, use clipboard functions internally in scripts!Okay. What is the alternative?
Mu own code does:
Code:
# make a copy of the layer, with an alpha channel
mergedLayer=layer # so we return something anyway
symLayer=layer.copy(True)
image.add_layer(symLayer)
symmetryFunction(image,layer,symLayer,symmetry)
pdb.gimp_edit_clear(symLayer)
pdb.gimp_selection_invert(image)
pdb.gimp_edit_clear(layer)
mergedLayer=image.merge_down(symLayer,EXPAND_AS_NECESSARY)
Where symmetryFunction is something like this (it basically transforms the top layer, and sets a selection so that the adequate parts can be
cleared)
Code:
def straightSymmetryCore(image,layer,symLayer,side):
# Some arrays to avoid if/else, indexed by 'side'
flipTypes=[ORIENTATION_VERTICAL,ORIENTATION_VERTICAL,ORIENTATION_HORIZONTAL,ORIENTATION_HORIZONTAL]
x,y=layer.offsets
w,h=layer.width,layer.height
# The rects we delete in the flipped layer
rects=[(x,y,w,h/2),(x,y+h-h/2,w,h/2),(x+w-w/2,y,w/2,h),(x,y,w/2,h)]
# Rotate and flip as required
symLayer.transform_flip_simple(flipTypes[side],True,0)
pdb.gimp_image_select_rectangle(image, CHANNEL_OP_REPLACE,*rects[side])
The complete code is here. Note that:
- It's Python, not script-fu. if you have to learn a new language to write scripts, use Python. It's easier to learn, and can be used in many more places
than Scheme/script-fu. If will also allow you to do more things.
- I use my scripts as test beds for new programming techniques. I hate verbosity, and repeating myself. It may make my code a bit obscure for the beginners. Simple Python is easier to read than simple script-fu.