Skip to main content
Community Expert
February 9, 2024
Answered

Grouped object - ungroup - Pathfinder Add - Convert to Rectangle

  • February 9, 2024
  • 3 replies
  • 2780 views

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.

This topic has been closed for replies.
Correct answer rob day

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.


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);
        } 
    }
}  

3 replies

Community Expert
February 10, 2024

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

Robert at ID-Tasker
Legend
February 10, 2024
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...

 

Community Expert
February 11, 2024

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.

rob day
Community Expert
Community Expert
February 9, 2024

Hi Eugene, I don’t  think you need to resort to the menu invoke() method— there is the the selection’s ungroup() method. The question might be which item in the group do you want to convert to a rectangle?

 

//the first item in a selection–a selected group would have 1 item
var s = app.activeDocument.selection[0];

//check if your selection is a group
if (s.constructor.name == "Group") {
    //converts the first page  item in the group to a rectangle
    s.pageItems[0].convertShape(ConvertShapeOptions.CONVERT_TO_RECTANGLE) 
} 

//ungroups the group
s.ungroup()

 

Before and after

 

Community Expert
February 9, 2024

Everything in the group to be turned into a rectangle

 

Ungroup Object
Pathfinder>Add

Pathfinder>Convert Shape to Rectangle

 

And then place the image

 

If I could got another route of converting the grouped object into an active link and replace the link that would be even better. 

rob day
Community Expert
Community Expert
February 9, 2024

Do you mean you want to remove the group and replace it with a rectangle with the same bounds, or convert both items in the group to rectangles and then place an image into one of the rectangles?

 

Robert at ID-Tasker
Legend
February 9, 2024

You can't convert Group into a Rectangle. 

 

Can you post some screenshot? I'm having hard time to understand what exactly are you trying to achieve. 

 

Community Expert
February 9, 2024

Can't post a screenshot - sorry

 

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. 

 

Steps I do are
Ungroup
Pathfinder>Add

Pathfinder>Convert to Shape>Rectangle 

 

Then place the image into the resulting frame. 

 

 

Robert at ID-Tasker
Legend
February 9, 2024

Why so complicated?

 

  • Get GeometricBounds of the Group,
  • create Rectangle,
  • set those GeometricBounds to this newly created Rectangle,
  • place your logo.