Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Transpose Frame Width and Height (without rotating)?

Guest
May 07, 2019 May 07, 2019

Scoured the forums for a script to flip the width and height frame values to no avail. In other words, make the width value the height’s and the height value the width’s.

Attempting to accomplish this without rotating in order to keep the “top of frame indicator” (i.e. the solid small box on the frame) on top of the frame where it defaults to, hence keeping the proper default orientation throughout. That’s the key.

In the meantime will attempt to scour my dimension scripts to see if I can possibly throw something together.

Although it seems dimension scripts can get pretty hairy.

Thanks all for any leads.

Take a frame as such:

Screen Shot 2019-05-07 at 6.03.01 PM.png

And maintain the dimension while transposing the Width and Height to result in the below (without rotating):

Screen Shot 2019-05-07 at 5.44.03 PM.png

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , May 07, 2019 May 07, 2019

Hi,

    In your first try, you used s.length.  selection is a single object. so it does not have length property.

     1.png

     In your 2nd try, you used g.length.  g is geometric bounds and the selection is a single object but you used s.  so its threw error.

     2.png

     Process :

     1. Selection should be multiple. ie., Rectangle

     2. loop it (rectangle) and proceed your flow.

     var s = app.selection;    // Selection of multiple rectangle

     for(var sCnt = 0; sCnt < s.length; sCnt++)

     {

       

...
Translate
People's Champ ,
May 07, 2019 May 07, 2019

A simplistic script that assumes that a non-rotated, non-sheared rectangle is involved would look like this:

// Select a rectangle and run the script to flip its width and height.

s = app.selection[0];

g = s.geometricBounds;

s.geometricBounds = [g[0], g[1], g[0] + (g[3] - g[1]), g[1] + (g[2] - g[0])];

That might be all you need in your particular case...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 07, 2019 May 07, 2019

This works great on a single selection.

I’m attempting to loop it and not having any luck, so as to grab multiple selections and have it work on all selected.

The below snippet throws the following error (screenshot below):

// Select a rectangle and run the script to flip its width and height.

var s = app.selection;

var g = s.geometricBounds;

for(var n=0;n<s.length;n++) 

    {

s.geometricBounds = [g[0], g[1], g[0] + (g[3] - g[1]), g[1] + (g[2] - g[0])];

};

Screen Shot 2019-05-07 at 7.35.36 PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 07, 2019 May 07, 2019

Also tried the below, with the following error (screenshot below).

But previously, without the “” in the 10th line, after the “s”, it threw no errors, but only affected 1 selection in a group of selected frames.

Seems I’m getting close, but don’t know enough about extend script, or looping, to bring it home.

// Select a rectangle and run the script to flip its width and height.

var s = app.selection[0];

var g = s.geometricBounds;

for(var n=0;n<g.length;n++)

    {

s.geometricBounds = [g[0], g[1], g[0] + (g[3] - g[1]), g[1] + (g[2] - g[0])];

};

Screen Shot 2019-05-07 at 7.42.45 PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 07, 2019 May 07, 2019

Hi,

    In your first try, you used s.length.  selection is a single object. so it does not have length property.

     1.png

     In your 2nd try, you used g.length.  g is geometric bounds and the selection is a single object but you used s.  so its threw error.

     2.png

     Process :

     1. Selection should be multiple. ie., Rectangle

     2. loop it (rectangle) and proceed your flow.

     var s = app.selection;    // Selection of multiple rectangle

     for(var sCnt = 0; sCnt < s.length; sCnt++)

     {

         var cObj = s[sCnt];

         var g = cObj.geometricBounds;

         cObj.geometricBounds = [g[0], g[1], g[0] + (g[3] - g[1]), g[1] + (g[2] - g[0])];    

     }

    Try this..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 07, 2019 May 07, 2019

This works awesomely now.

After staring at this for some time, i want to clarify:

• this snippet contains 4 variables, correct (s, g, sCnt, cObj)?

• What made you name sCnt, and cObj, as such? Just attempting to figure out your train of thought. Obj is short for object, right. Cnt, is that short for container or center?

• s[sCnt] is similar to certain loop setups I’ve come across, i.e. sel. or sel., etc. Is the value inside the [] being multiplied by the value outside the [] or is it simply syntax that holds a value connected to the variable? Cause sometimes I’ll see a zero there or a whole number, or other numerical value.

I would have never came up with this. I knew it would be different than any other loop I’ve come across so far.

In any event, thanks again, really appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 08, 2019 May 08, 2019

Hi,

     I used those variable to hold the values.

     s      -  Selection objects

     g     -   variable holds the bounds value (already used)

     sCnt - Selection Count increament of for loop

     cObj - Current selection object. Instead of this, you can use directly use s[sCnt] as you said.

     You can use it as your own way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 08, 2019 May 08, 2019
LATEST

I’m gonna pretend I understand 100%.

But really it’s more like 60%.

Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines