Jump to content

Script or plugin that will take selection and automatically move it to desired locations?


Recommended Posts

I continually use the same template for projects and always move the exact same selected areas to the same places. In the picture provided, I give an example of how I may move my selection. In the colored top block, I break it up into two even slices and move them to another location.

Basically what I am looking for is a way to say "Move top selection ###, ###. Bounding rectangle size ### x ### to location --> top selection ###, ###.

 

If that does not make sense, please let me know because I am determined to find a quicker way since I have been doing this manually for years. I need a script or plugin that will save me tons of time!

Example pdn.png

Link to comment
Share on other sites

29 minutes ago, toe_head2001 said:

That is possible, but you wouldn't do it with selections.

 

Do you have basic programming skills? You write a script/plugin with CodeLab.

If not, I or someone else will be able to assist.

How would I do it without selections? 

Haha, the only programming I know is HTML and CSS so I'm a newb. If someone were to write a little bit of the script, I could probably finish it since I am a quick learner.

Link to comment
Share on other sites

Just now, katust said:

How would I do it without selections? 

Instead of defining the Bounding Rectangle with a selection, you define it programmatically. You said you're continually using the same template, so the values of the Bounding Rectangle could even be hard-coded.

 

I'll see what I can come up with this weekend. It should be pretty straightforward.

Link to comment
Share on other sites

1 minute ago, toe_head2001 said:

Instead of defining the Bounding Rectangle with a selection, you define it programmatically. You said you're continually using the same template, so the values of the Bounding Rectangle could even be hard-coded.

 

I'll see what I can come up with this weekend. It should be pretty straightforward.

Sweet! Thank you so much! With the picture I shared, it's a lot of that same idea but just all over the template. If the structure of the script were provided and one example of how to move a selection to another area, I could probably fill in the rest.

Thank you for your help and advice, I truly appreciate it! 

Link to comment
Share on other sites

@katust, sorry for the delay... I didn't get around to doing this until tonight.

Copy and paste the script into CodeLab.

 

copyRegion.png

 

 

 

The three Rectangles are based on the image template you posted.

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle fromRect = Rectangle.FromLTRB(229, 202, 361, 238);
    Rectangle toRect1 = Rectangle.FromLTRB(215, 353, 283, 389);
    Rectangle toRect2 = Rectangle.FromLTRB(306, 353, 374, 389);

    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];

            if (toRect1.Contains(x, y))
            {
                int offSetX = x - toRect1.Left + fromRect.Left;
                int offSetY = y - toRect1.Top + fromRect.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            else if (toRect2.Contains(x, y))
            {
                int offSetX = fromRect.Right - toRect2.Right + x;
                int offSetY = y - toRect2.Top + fromRect.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            
            dst[x,y] = CurrentPixel;
        }
    }
}

 

Let us know if you need further help. :D

 

  • Upvote 2
Link to comment
Share on other sites

  • 9 months later...

I have no experience at running scripts with paint.net. This seems to look as a sollution to what I need.

 

I need a script that creates a fixed size selection in the center of the image.

The script has to be called by the same script that opens the image in paint.net, including the width and height of the selection.

 

Can that be done?

What tools/programs would I need to support this? (It should work with multiple users).

 

Thanks in advance!

Link to comment
Share on other sites

Plugins cannot open images. They get access to the active layer (or a selection on it if one is active).

 

If you're OK with opening your image and running a plugin, what do you want done with the central area once you have defined it?

Link to comment
Share on other sites

9 hours ago, Ego Eram Reputo said:

Plugins cannot open images. 

Is it possible to call a plug in from a script or command line?

 

9 hours ago, Ego Eram Reputo said:

what do you want done with the central area once you have defined it?

 

The user needs to move the selection to a section of choice and then crop to selection.

For a command line something like      > scribus.exe [file] -[script]

Ideally the size of the selection would be a given parameter (like "-size 600x600"). Or I simply copy the plugin scripts to various sizes.

 

In more detail:

We need all images to have a specific dimension (lets say 600x600)

I am using "magick" to resize all input images (so 1800x1200 will become 900x600, 1200x1500 will become 600x750) etc.

Then the user need to select what part should be in the 600x600 and what part can be shaved.

 

Link to comment
Share on other sites

16 hours ago, hanzon73 said:

Is it possible to call a plug in from a script or command line?


Scripts are run by plugins (mostly pyrochild's ScriptLab), so while a script can run another plugin, it can't do anything a plugin can't do. Things plugins (and therefore scripts) can't do include: opening a file into Paint.Net; creating or modifying a selection; cropping an image, or otherwise resizing an image's canvas.

 

16 hours ago, hanzon73 said:

The user needs to move the selection to a section of choice and then crop to selection.

 

Plugins can move pixels from one region to another, but they can't modify the selection boundary, and they can move pixels to a region outside the selection, since only the pixels inside the current selection can be written. They also can't crop  an image.

 

I suspect you'll have to find a program other than PDN to do what you want to do.

 

 

Link to comment
Share on other sites

Completely agree with MJW. Paint.net isn't designed to be used this way.

 

Although, thinking about it, I suggest you have a look at this....

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...