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

Grouped object - ungroup - Pathfinder Add - Convert to Rectangle

Community Expert ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

Playing with scripting and finding it very frustrating but this one would save me a good bit of time 

 

I just want to ungroup an object - leave it selected

I figured that out

var ungroupMenuItem = app.menuActions.item("$ID/Ungroup");

if (ungroupMenuItem.isValid) {
    // Invoke the menu item
    ungroupMenuItem.invoke();
} else {
    alert("The Ungroup menu item was not found.");
}

 

Seems to work - maybe not the best way

But can't access

Object>Path>add

 

Then next step is

Object>Convert to Shape>Rectangle

 

All the while leaving the object selected while running through

 

1 out of 3 ain't bad... 

 

Ultimately - I have 2 of these objects on every page that need to be ungrouped

Ideally I'd like to just make them a link - as I'm replacing them with an image anyway 

 

If they were converted to links that would be ideal 
So I would select the objects on the page in 1 selection - then run the script - it makes them a link

Then I can just relink them

 

But given that I can't convert the group to a rectangle by scripting I feel the former and latter part of my plan is beyond me.

 

Any help is much appreciated.

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

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

Community Expert , Feb 11, 2024 Feb 11, 2024

You want to open the file outside of the loop, so I think this might work:

 

var s = app.activeDocument.selection;

var f = File.openDialog("Select the file", "")
if (f != null) {
    for (var i = 0; i < s.length; i++){
        if (s[i].constructor.name == "Group") {
            s[i].pageItems[0].addPath(s[i].allPageItems);
            s[i].pageItems[0].convertShape(ConvertShapeOptions.CONVERT_TO_RECTANGLE);
            s[i].pageItems[0].place(f)
            s[i].pageItems[0].fit(FitOptions.FIL
...

Votes

Translate

Translate
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

From @Eugene Tyson ’s 2nd post:

 

But imagine say a simple logo - and it's pasted into InDesign

All I want to do is convert that to rectangle - then I place the logo into the frame - same size etc.

 

And why do you keep combining paths

Because it’s a simple command, doesn’t require making anything.

 

We are working blind here.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

I don't understand.

 

I'm getting there with what I want.

 

Currently I think I've been very clear .

 

Thanks for all the help so far.

 

If there's anything I can be clearer about let me know

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

If there's anything I can be clearer about let me know

 

I’ve been guessing what the contents of your group is and where the linked logo is coming from. Not sure why you need the loops, I thought your selection was a single group object? A sample ID file would help.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

@rob day 

 

I still think the Group is just a mockup that should be replaced with a new link... 

 

And yes, you are right, in your code you are using two lines which will be faster than creating Rectangle and all the additional steps - but as @Eugene Tyson needs rotation - I think you should un-rotate it first? 

So the final Rectangle will envelop the Group - not it's bounding box?

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

@Eugene Tyson needs rotation - I think you should un-rotate it first? 

 

The rotation part is not clear to me, and I did not realize the link that needs to be placed was not part of the group, but this:

 

var s = app.activeDocument.selection[0];
if (s.constructor.name == "Group") {
    var f = File.openDialog("Select the file", "*.jpg;*.jpeg;*.png;*.gif");
    if (f != null) {
        s.pageItems[0].addPath(s.allPageItems)
        s.pageItems[0].convertShape(ConvertShapeOptions.CONVERT_TO_RECTANGLE);
        s.pageItems[0].place(f);
        s.pageItems[0].fit(FitOptions.FILL_PROPORTIONALLY);
        s.ungroup();
    } 
} 


Does this:

 

Screen Shot 34.png

Screen Shot 36.png

 

Screen Shot 35.png

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

@rob day

 

So you've solved the puzzle in full!

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

@rob day

 

One more thing - I'm on my phone so can't check - but in the end, there will be bunch of separate objects - s.ungroup(), right?

 

I'm sure Eugene would appreciate if the rest of the Objects from the Group would be removed?

 

Maybe s.pageItems[0].duplicate() instead and then s.remove()?

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

The group gets removed via s.ungroup(), all that’s left is a rotated rectangle with the placed link, which you can see in the Layers panel:

 

Screen Shot 35.png

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

quote

The group gets removed via s.ungroup(), all that’s left is a rotated rectangle with the placed link, which you can see in the Layers panel:

 

By @rob day

 

So this line:

 

s.pageItems[0].addPath(s.allPageItems)

 

will destroys all other elements in the group?

(I think ";" is missing at the end of the line?)

 

But in that case - it's no longer a group but a PageItem/Rectangle?

As you are not declaring/envorcing a type - you won't get an error for different type?

 

Then there is no need to call ungroup()?

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Rectangle.html#d1e217687__d1e219657

 

RobertTkaczyk_0-1707607165464.png

 

But as it returns new object - and you are not assigning it to s.pageItems[0] - how can the rest of the code work?

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

A bit strange - and disturbing...

 

RobertTkaczyk_1-1707607757960.png

 

Conversion to Rectangle - doesn't change internal type - it's a square Oval...

 

But if you convert it from Toolbox - everything is OK:

RobertTkaczyk_0-1707608245500.png

 

RobertTkaczyk_1-1707608288963.png

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 11, 2024 Feb 11, 2024

Copy link to clipboard

Copied

Conversion to Rectangle - doesn't change internal type - it's a square Oval...

 

Right, same happens if you convert corner points or use Pathfinder via the UI.

 

alert(app.activeDocument.selection[0].constructor.name)

Screen Shot 1.png

 

 

In the case of Pathfinder looks like the item at the back determines the class of the combined paths.

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

That's amazingly simpler and a lot shorter than what I am coming up - very simple.

 

Only problem, and my fault for not saying anything earlier, but sometimes the objects are rotated and I need to keep them rotated at the angle they are at whether it's 0, 90, -90, or 180

 

And when testing I couldn't figure out a way (although you probably can do it) to keep the same place and same rotation.

 

But again - it's an eye opener for me.
Thanks

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

@Eugene Tyson

 

If you want to apply rotation - and the rest of transformations - you can get them from the Group and apply to the Rectangle.

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

@rob day

 

I sometimes get notifications about replies that I've just posted?

 

And no notifications about private messages...

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

I've no idea where we are on replies the forums is a mess

 

Thank you @Robert at ID-Tasker  @rob day 

I'll sort through it all and report back

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

quote

I've no idea where we are on replies the forums is a mess

 

By @Eugene Tyson

 

Yeah - after 2nd level there is no way to know to which post the reply is...

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

Thanks for the help @Robert at ID-Tasker @rob day 

I'm 99% there with what I want to 

That is to replace the grouped object(s) with a link - which I set out at first.

I did limit myself by just wanting to convert to a rectangle at the start.

But then possibilities opened up and the idea expanded.

 

Now, I am at the point of replacing every object on the page that's selected with the link. 

Which is great, only thing is I have to select the link how many times it's being replaced, if there's 4 objects it's 4 clicks to replace the link. 

 

As I can't figure out a way to just have 1 link.

Not a big deal - but I'm far closer to when I started. 

 

I'll further revise on Monday when I can test properly.

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 11, 2024 Feb 11, 2024

Copy link to clipboard

Copied

@Eugene Tyson

 

You mean you have Nx Groups?

 

I'm pretty sure it won't be a big deal for @rob day to change the code.

 

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 11, 2024 Feb 11, 2024

Copy link to clipboard

Copied

You want to open the file outside of the loop, so I think this might work:

 

var s = app.activeDocument.selection;

var f = File.openDialog("Select the file", "")
if (f != null) {
    for (var i = 0; i < s.length; i++){
        if (s[i].constructor.name == "Group") {
            s[i].pageItems[0].addPath(s[i].allPageItems);
            s[i].pageItems[0].convertShape(ConvertShapeOptions.CONVERT_TO_RECTANGLE);
            s[i].pageItems[0].place(f)
            s[i].pageItems[0].fit(FitOptions.FILL_PROPORTIONALLY);
            s[i].ungroup();
        } else {
            s[i].place(f)
            s[i].pageItems[0].fit(FitOptions.FILL_PROPORTIONALLY);
        } 
    }
}  

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 11, 2024 Feb 11, 2024

Copy link to clipboard

Copied

Thanks I'll give it a go

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

LATEST

This is what is working for me at the moment - all good - after lots of exploration and trials and errors this is what I needed in the end.
Thanks

Votes

Translate

Translate

Report

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