It is currently 25 Jan 2022, 10:40

• Featuring Members' Images •
Could be related to 'Change the names of script (SCM) files'
tim
tim
tim
tim
tim

GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | 🡆 Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Change the names of script (SCM) files

Share your Scheme Fu scripts for GIMP here
Pegleg44
Forum Member
40th Place
53 Post(s)

Change the names of script (SCM) files

Post#1 by Pegleg44 » 17 Feb 2017, 19:48


I'd like to rename some of my scripts so that I can better recognize what they are when I look through them. Can I just change the name of it and it will still work right?

tim
GL Blogger
1st Place
5775 Post(s)

Post#2 by tim » 17 Feb 2017, 21:07


yep, filename change is fine.
You could even change the menu name inside the file too if you like
aka Tin
World Food Program | Good Deeds Forum

         

Pegleg44
Forum Member
40th Place
53 Post(s)

Post#3 by Pegleg44 » 17 Feb 2017, 22:35


Now the name of the file has nothing to do with anything right. Like dependencies or anything. Am I right on that?

So is the menu name always at the end and ends up with the text "menu register" like this.

Code: Select all

 
  "<Image>/Script-Fu/Sel To Darken Layer"    ;menu register
 
And all I have to do is change the "Sel To Darken Layer" right.
If so I can change that.
But will I also have to change my keyboard shortcuts that I use.

tim
GL Blogger
1st Place
5775 Post(s)

Post#4 by tim » 17 Feb 2017, 22:52


You can change Sel To Darken Layer yes...but I don't even know how to assign keyboard short cuts to scripts?

Edit: i just tried it and it messes with the dynamic short cut key assigned. it looks like i assigns short cut to whichever menu item is in that place.
so the name change will move that script to a different location alphabetically so short cuts are no longer valid.
aka Tin
World Food Program | Good Deeds Forum

         

Pegleg44
Forum Member
40th Place
53 Post(s)

Post#5 by Pegleg44 » 17 Feb 2017, 23:29


But the name of the SCM file doesn't matter for anything right.

I have shortcut keyed almost all of those scripts. I will just have to disable the shortcut key then change the menu name and then re-assign the shortcut key again.

My next question is where can I find in a script the place that it calls upon another separate script?

tim
GL Blogger
1st Place
5775 Post(s)

Post#6 by tim » 17 Feb 2017, 23:36


you're right, the file name isn't used anywhere.
if a script calls another script.
It calls it in code that starts with 'script-fu' and then some name or 'python-fu' and then some name.
because the scripts are registered in the database so other scripts call it using those names not file name.
for example if a script is registered with

Code: Select all

(script-fu-register
  "script-fu-custom-font" 
  ... 
then other scripts will call it inside .scm
by calling

Code: Select all

(script-fu-custom-font [parameters]...)
or inside .py
by

Code: Select all

pdb.script_fu_custom_font(parameters..)
aka Tin
World Food Program | Good Deeds Forum

         

Pegleg44
Forum Member
40th Place
53 Post(s)

Post#7 by Pegleg44 » 17 Feb 2017, 23:50


It looks like when I make a keyboard shortcut in gimp it looks it up by the function name.

Pegleg44
Forum Member
40th Place
53 Post(s)

Post#8 by Pegleg44 » 18 Feb 2017, 16:44


@ Tin

What I really want to do is put all the scripts that I have into the same menu drop down box so that when I share them with others they will be able to see them all right there in one place.

So I've noticed that you have made a few scripts that I use and they are in a file menu at the top called Script-Fu. Now does that menu (Script-Fu) appear simply because you have put it in this line here:

Code: Select all

 "<Image>/Script-Fu/round-raster-for-PegLeg44 ..."    ;menu register
Here's the whole code which calls upon another script that is called "RMA_selection_blend" that is named 3 times in this script. Once after define and then after step 4 and 7.

Code: Select all

;as described in steps by PegLeg44 here:http://gimpchat.com/viewtopic.php?f=9&t=14046&p=192064#p192064
;
(define (RMA_selection_blend_sub img inLayer inGrad inRev inMethod)
  (let*
    ( (width (car (gimp-image-width img)))
	  (height (car (gimp-image-height img)))
      (selbounds (gimp-selection-bounds img))
      (inGrad (if (equal? inGrad "") (car (gimp-context-get-gradient)) inGrad))
      (origimg img)
      (origlayer inLayer)
      (img (car (gimp-image-duplicate img)))
      (inLayer (car (gimp-image-get-active-layer img)))
      (selchannel 0)
      (counter 0)
      (countto 0)
      (selsize 0)
      (slice 0)
      (errhandler (car (gimp-message-get-handler)))
	)
    
    (gimp-message-set-handler CONSOLE)
    
    (gimp-image-undo-group-start origimg)
    (gimp-image-undo-freeze img)
    (gimp-context-push)
    (gimp-context-set-gradient inGrad)
	
    (if (zero? (car selbounds)) (gimp-selection-all img))
    
    (set! selchannel (car (gimp-selection-save img)))
    
    (cond
      ( (= inMethod 0) ; Horizontal
        (set! counter (caddr selbounds))
        (set! countto (cadddr (cdr selbounds)))
        (set! selsize (- (cadddr selbounds) (cadr selbounds)))
        (while (< counter countto)
          (gimp-rect-select img (cadr selbounds) counter selsize 1 CHANNEL-OP-REPLACE FALSE 0)
          (gimp-selection-combine selchannel CHANNEL-OP-INTERSECT)
          (set! slice (cdr (gimp-selection-bounds img)))
          (if (zero? inRev)
            (gimp-edit-blend inLayer CUSTOM-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE TRUE 3 0.2 TRUE 
              (car slice) (cadr slice) (caddr slice) (cadr slice))
            (gimp-edit-blend inLayer CUSTOM-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE TRUE 3 0.2 TRUE 
              (caddr slice) (cadr slice) (car slice) (cadr slice))
           )
          (set! counter (+ counter 1))
        )
      )
      ( (= inMethod 1) ; Vartical
        (set! counter (cadr selbounds))
        (set! countto (cadddr selbounds))
        (set! selsize (- (cadddr (cdr selbounds)) (caddr selbounds)))
        (while (< counter countto)
          (gimp-rect-select img counter (list-ref selbounds 2) 1 selsize CHANNEL-OP-REPLACE FALSE 0)
          (gimp-selection-combine selchannel CHANNEL-OP-INTERSECT)
          (set! slice (cdr (gimp-selection-bounds img)))
          (if (zero? inRev)
            (gimp-edit-blend inLayer CUSTOM-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE TRUE 3 0.2 TRUE 
              (car slice) (cadr slice) (car slice) (cadddr slice))
            (gimp-edit-blend inLayer CUSTOM-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE TRUE 3 0.2 TRUE 
              (car slice) (cadddr slice) (car slice) (cadr slice 2))
          )              
          (set! counter (+ counter 1))
        )
      )
    )
     
    (if (zero? (car selbounds))
      (gimp-selection-none img)
      (gimp-selection-load selchannel)
    )

    (gimp-edit-copy inLayer)
    (gimp-floating-sel-anchor (car (gimp-edit-paste origlayer TRUE)))
    
  	(gimp-displays-flush)
	(gimp-context-pop)
  	(gimp-image-undo-thaw img)
    (gimp-image-delete img)
    
  	(gimp-image-undo-group-end origimg)
    
    (gimp-message-set-handler errhandler)
    
  )
)
(define (script-fu-round-raster-for-pegleg44 image layer 
			step4gradient
			step4reversed
			step4method
			step7gradient
			step7reversed
			step7method
			offset-x-power
         )
	
		(let* 
		   (
		   (width (car (gimp-image-width image)))
		   (height (car (gimp-image-height image)))
		   (active-vectors 0)
		   (new-layer 0)
		   (dup-layer 0)
		   (dup-layer2 0)
		   (offset-x 0)
		   )
			;(gimp-image-undo-disable image); DN = NO UNDO
			(gimp-context-push)
			(gimp-image-undo-group-start image)                   ;undo-group in one step
			
			
			;1. I turn the path to a [Selection] [From Path].
			(set! active-vectors (car (gimp-image-get-active-vectors image)))
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			
			;2. I create a new white layer.
			(set! new-layer (car (gimp-layer-new image width height
	                           RGBA-IMAGE "new white" 100 NORMAL-MODE)))
			(gimp-drawable-fill new-layer WHITE-FILL)         ;fills background with white
			(gimp-image-insert-layer image new-layer 0 0) ;parent 0, insert layer on top position(0)				   
	
			;3. And fill the selection with black [Fill with Foreground Color].
			(gimp-edit-fill new-layer FOREGROUND-FILL)
			
			;4. And then un-select [Select] [None].
			(gimp-selection-none image)
			
			;5. Then I run the [Colors] [Threshold] on the layer (with the standard 127 and 255 setting).
			(gimp-threshold new-layer 127 255)
			
			;6. And run [Layers] [Transparency] [Color to Alpha] on it.
			(plug-in-colortoalpha 1 image new-layer '(255 255 255))
			
			;7. Then click the button [Lock Alpha Channel] at the top of the layers dockable dialog.
			(gimp-layer-set-lock-alpha new-layer TRUE)
			
			;8. Change the layer mode to [Darken Only]
			(gimp-layer-set-mode new-layer DARKEN-ONLY-MODE)
			
			;9. And finally use [Colors] [Invert] on it to make the black white.
			(gimp-invert new-layer)
			;------------------------------------------------- END OF path-to-selection-for Pegleg44
			
			;1. Run the script that you have made on the path that is already created - [Script-Fu] [path-to-selection]
			; ALREADY DONE ABOVE
			
			;2. [Layer] [Transparency] [Alpha to Selection]
			(gimp-image-select-item image CHANNEL-OP-REPLACE new-layer)
			
			;3. [Image] [Crop to Selection]
			(plug-in-autocrop 1 image new-layer)
            ;4. Run the [Select] [Selection Blend] script that RobA made with a gradient that I have created called 01RoundFull or I would prefer to select it.
			(RMA_selection_blend_sub image new-layer step4gradient step4reversed step4method)
			
			;5. [Layer] [Duplicate Layer]
			(set! dup-layer (car (gimp-layer-copy new-layer TRUE)))
			(gimp-image-insert-layer image dup-layer 0 0)
			
			;6. [Select] [All]
			(gimp-selection-all image)
			
			;7. [Select] [Selection Blend] RobA script with a different gradient (FG to BG RGB] or I will be able to select.
			(RMA_selection_blend_sub image dup-layer step7gradient step7reversed step7method)
			
			;8. [Colors] [Levels] and the far right input level field at 127
			(gimp-levels dup-layer HISTOGRAM-VALUE 0 127 1.0 0 255)
			
			
			;13. Step 9 thru 12 need to be repeated with the other X values from 2 to 256 (up to 256 would work best or 512 if you want)
			; while loop from step 9 to step 12
			(while (<= offset-x offset-x-power)
				;9. [Layer] [Duplicate Layer]
				(set! dup-layer2 (car (gimp-layer-copy dup-layer TRUE)))
				(gimp-image-insert-layer image dup-layer2 0 0)
				
				;10. Set layer mode to [Darken Only]
				(gimp-layer-set-mode dup-layer2 DARKEN-ONLY-MODE)
				
				;11. [Layer] [Transform] [Offset] X value of 1, (2, 4, 8, 16, 32, 64, 128, 256)
				(gimp-drawable-offset dup-layer2 TRUE 
												 1 ;not used as we have specifed wrap to TRUE above
												 (pow 2 offset-x)
												 0
												 )
				
				;12. [Layer] [Merge Down]
				(set! dup-layer (car (gimp-image-merge-down image dup-layer2 0)))
				
				(set! offset-x (+ offset-x 1))
			)
			
			;14. Finally the layer mode needs to be set to Screen
			(gimp-layer-set-mode dup-layer SCREEN-MODE)			
			
			
			
			
		   ;(gimp-image-undo-enable image) ;DN = NO UNDO
			(gimp-image-undo-group-end image)                     ;undo group in one step
			(gimp-context-pop)
			(gimp-displays-flush)
			
			
	    )
	
    
) ;end of define
(script-fu-register
  "script-fu-round-raster-for-pegleg44"         ;function name
  "<Image>/Script-Fu/round-raster-for-PegLeg44 ..."    ;menu register
  "Start with a Path - The Script will Change the Image Size so Use a New Canvas"       ;description
  "Tin Tran"                          ;author name
  "copyright info and description"         ;copyright info or description
  "2016"                          ;date
  "RGB*, GRAY*"                        ;mode
  SF-IMAGE      "Image" 0                   
  SF-DRAWABLE   "Layer" 0
  SF-GRADIENT   "(Step 4) Blend Selection Gradient"           ""
  SF-TOGGLE     "(Step 4) Blend Selection Reversed"           FALSE
  SF-OPTION	    "(Step 4) Blend Selection Method"		       (list "Horizontal" "Vertical")
  SF-GRADIENT   "(Step 7) Blend Selection Gradient"           ""
  SF-TOGGLE     "(Step 7) Blend Selection Reversed"           FALSE
  SF-OPTION	    "(Step 7) Blend Selection Method"		       (list "Horizontal" "Vertical")
  SF-OPTION	    "Transform Offset X upto and including"		   (list "1" "2" "4" "8" "16" "32" "64" "128" "256" "512" "1024" "2048")
)
So I would want to change the name of RMA_selection_blend to something else and make it appear in a new pull down menu in gimp. And then also make the script that calls upon it to find it.

I have a whole list of scripts that I want to put into a pull down that I will call GIMP CAD. Some of them are python and some script-fu. Can I do that? You have made some that I use and put them into a python-Fu pull down and others that you made go into Script-Fu. But I want to put them all in one.

Alan

tim
GL Blogger
1st Place
5775 Post(s)

Post#9 by tim » 18 Feb 2017, 18:10


this RMA_selection_blend_sub is only internally used by this script that's why it's defined and used twice (that's why 3 occurrences).
I copied it from somewhere else, the original that provides that RMA_selection_blend is probably just called RMA_selection_blend without the _sub... i named it _sub to let me know that it's just a subroutine used internally by this script.
You can name it anything you like as long as it's valid name like words with underscores, just make sure you change them in all 3 places.
As far as where it is on the menu you can change <Image>/Script-Fu/round-raster-for-PegLeg44
to anything you like, like for example <Image>/GIMP CAD/my script 1
And GIMP will automatically create a 'GIMP CAD' menu on top and then inside that will be your 'my script 1'
aka Tin
World Food Program | Good Deeds Forum

         

Pegleg44
Forum Member
40th Place
53 Post(s)

Post#10 by Pegleg44 » 18 Feb 2017, 20:55


Basically I only want to change where scripts are put in the menu pull downs and the names that they are called in there.

So as long as I just change the <Image>/GIMP CAD/my script 1, then it will create the (GIMP CAD) menu and call it (my script 1) and all the other stuff can stay the same and I won't have any issues with one script calling on another one or defining or whatever. Is that correct?

The <Image>/GIMP CAD/my script 1, just names menus and the name that appears or that it is called in the menu right?

That way the register for python-fu and script-fu register will stay the same and all scripts will find other ones if they need it right?

And if the register stays the same then I won't even have to change the keyboard shortcuts that I have already set up.

If this is correct then I won't need to change the name of the SCM file at all.

If the answer is yes then I will make a copy of my scripts and plug ins and change them to try it out.

Alan


GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | 🡆 Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply New Topic
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests