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

how to group some objects and duplicate it and then enlarge the same group using javascript ??

New Here ,
Mar 30, 2009 Mar 30, 2009
Hi everyone,

I need to write a javascript which will group some object on running the script and then duplcate the same group.After duplicating it will enlarge the same group upto some extend.The object will be generally inside the textframes.We have to group them and then make a duplcate of the group on the same page.Please tell me the javascript code to do the same.

Thanks and regards,
Sanat
TOPICS
Scripting
3.8K
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
Community Expert ,
Mar 30, 2009 Mar 30, 2009
What version of InDesign? For CS3, you can start by looking at Class Group ("A group" is its description in the ESTK Help) and its collection Groups. Those contains a lot, if not all, of the features you request:

* Groups.Group add (groupItems: Array of PageItem[, layer:Layer][, at:LocationOptions=UNKNOWN][, reference:any][, withProperties:Object]) -- Creates a new Group
* PageItem Group.duplicate ([to:any][, by: Array of number]) -- Duplicates the Group at the specified location or offset
* void Group.move ([to:any][, by: Array of number]) -- Moves the Group to a new location.
* Group.absoluteHorizontalScale, Group.absoluteVerticalScale -- The horizontal and vertical scale of the Group relative to its containing object.

(All copied straight out of the CHM version of the ESTK Help, created by me and put into CHM by ABC GREEN. HTML version somewhere at the same location.)
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
New Here ,
Mar 30, 2009 Mar 30, 2009
i m using indesign cs3..
Could u please post the javascript code for the same.
Thanks in advance..
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
Participant ,
Mar 30, 2009 Mar 30, 2009
Given your description of your goal, there's not enough information to do the job.

You say:

>which will group some object on running the script

Do you mean "some objects"? Hope so because you can't group a single item.

How does the script know which objects to work on? Are you requiring the user to select them in advance? If not, what technique should the script use to know which objects?

>it will enlarge the same group upto some extend

To which extent?

>The object will be generally inside the textframes

What does "inside" mean? Are you talking about anchored objects? Or is this a reference to their geometric positions on the page? If the latter, what does the text frames have to do with anything? If the former, then the job just got a whole lot harder because you can't group anchored objects.

Dave
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
Community Expert ,
Mar 30, 2009 Mar 30, 2009
How does

>I need to write...

rhyme with

>post the code

? It's not as if it's a well-known or easy "trick" -- or as if you've given clear objectives (see Dave's list of questions).

Did you check the functions I summed up in the ESTK? These are the ones you will be using, or at least, that's what I'm guessing you should. What have you got so far?
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
New Here ,
Mar 30, 2009 Mar 30, 2009
some objects means we have to combine several objects into a group so that they are treated as a single unit.The object are textframes(means text ).The user has to select the objects and then run the script.By running the script,the script will group the selected object and then make a duplicate of the same group by enlarging it.

The extent of enlargement will be fixed.We can specify the geometric position in the script itself.

I m a beginner to indesign javascript.Plz anyone help me in the code.

Regards,
Sanat
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
New Here ,
Mar 31, 2009 Mar 31, 2009
The code that i m using is like this..fist i m selecting and then grouping them using array. I dont know how to duplicate and enlarge using javascript..But this one is not working perfectly..Its showing error at var myObjectList = new Array(myPageItem); <br />Could anyone tell me the solution...<br /><br />main();<br /><br />function main(){<br /> if (app.documents.length != 0){<br /> if (app.selection.length > 0){<br /> for(myCounter = 0; myCounter<app.selection.length; myCounter++){<br /> myPageItem = app.selection[myCounter];<br /> <br /> var myObjectList = new Array(myPageItem); <br /><br />var myGroup =myDocument.groups.add(myObjectList);<br /> }<br /> }<br /> }<br /> <br /> <br /> }
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
Community Expert ,
Mar 31, 2009 Mar 31, 2009
Hmm. I *think* you got the order wrong:<br /><br />loop<br /> create array of <br />b one page item only;<br /> add to group<br /><br />Try this:<br /><pre>var myObjectList = new Array;<br />for (i=0; i<app.selection.length; i++)<br /><br /> myObjectList.push (app.selection);<br /><br />alert ("length of myObjectList is "+myObjectList.length);</pre>-- an alternative way of creating a valid array of selected items. I can't get<br /><br />>var myObjectList = new Array(app.selection)<br /><br />to work (it certainly sounds as if it should work ...).<br /><br />The resulting array object then can be fed into the group creating line.
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
New Here ,
Apr 01, 2009 Apr 01, 2009
Thanks a lot jongware..now its selecting the objects correctly but i m struck with adding the selected objects to the group and duplicating the same group.<br />I tried the follwing code but it didnot work.<br /><br />main();<br /><br />function main(){<br /> if (app.documents.length != 0){<br /> if (app.selection.length > 0){<br /> <br /> var myObjectList = new Array; <br /> var myObjectList = new Array; <br />for (i=0; i<app.selection.length; i++) <br /> myObjectList.push (app.selection); <br /><br />alert ("length of myObjectList is "+myObjectList.length);<br /><br />var myGroup =app.documents.groups.add(myObjectList); <br /><br />var myGroup1=myGroup.duplicate(myObjectList1,myObjectList1);<br /><br /> }<br /> }<br /> }<br /> <br />I know i m asking silly questions but i m a begginer to this scripting and want to learn more.Please guide me with the proper code to do so.<br /><br />Thanks,<br />Sanat
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
Community Expert ,
Apr 01, 2009 Apr 01, 2009
Perhaps you should start with a simpler script -- set your target a bit lower. Go step by step and don't complain if it doesn't happen overnight. I have been programming JS for a handful of years and it's really just in the last year I can program exactly (more or less) what I intend to achieve.

It doesn't help you keep asking for useful snips (or entire scripts) of things that are
i difficult
because I have to tell you what they do, where to insert them, and how to change. I might as well send a complete and totally custom script; and then you learned nothing at all (you'd learn my bank account number).
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
New Here ,
Apr 01, 2009 Apr 01, 2009
thanx jongware for ur valuable suggestion.I understand the same and i m planing to do so.But this requirement is bit urgent.So please help me in this script for which i shall b grateful to u.

Thanks,
Sanat
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
Community Expert ,
Apr 01, 2009 Apr 01, 2009
Sanat,

Make jongware an offer he can't refuse.

Peter
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
New Here ,
Apr 01, 2009 Apr 01, 2009
The main problem i am facing during learning this script is that there not enough resources available like tutorial,book,demo examples for practice.I m trying to get as much as information possible from the this forum.

Again i am seeking help from u guys for solving this script.Waiting 4 ur positive response.
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
Community Expert ,
Apr 02, 2009 Apr 02, 2009
Well, I'm at a loss.

Dave Saunders, in his JS blog, simply uses

>myParent.groups.add(gpArray)

-- then again, he was using CS2 there.

I tried numerous variations for about three consecutive hours (my boss doesn't read this forum), but the best I got was finding out

>var myGroup = app.activeDocument.groups.add(app.selection,null,LocationOptions.AT_BEGINNING,app.activeWindow.activePage); // NOT app.documents!

complains about 'no parent'. The location is optional; yet, if you omit it, you get another error.

I found Dave's page with some google-fu: Google groups site:jsid.blogspot.com has a few more hits. I didn't read them all, but I think you should.

Or make Dave an offer he can't refuse.
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
Participant ,
Apr 02, 2009 Apr 02, 2009
It would have to be a very large offer. I'm no longer available for freelance work (at least, for the foreseeable future).

Dave
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
Community Expert ,
Apr 02, 2009 Apr 02, 2009
Haven't you heard how much he's gonna offer? :-D

See some comparable problems and how much they make when solved.
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
New Here ,
Apr 02, 2009 Apr 02, 2009
Surely i m gonna offer.<br />jongware,I tried the following code.But i m getting error like this:<br /><br />Error String:Cant create page item.No valid parent found.<br />How to fix it again!!<br /><br />main();<br /><br />function main(){<br /> if (app.documents.length != 0){<br /> if (app.selection.length > 0){<br /> //myDocument = app.documents.add();<br /> var myObjectList = new Array; <br /> var myObjectList1 = new Array; <br />for (i=0; i<app.selection.length; i++) <br /><br />myObjectList.push (app.selection); <br /><br />alert ("length of myObjectList is "+myObjectList.length);<br /><br />var myGroup = app.activeDocument.groups.add(app.selection,null,LocationOptions.AT_BEGINNING,app.activeWindow.activePage); <br /><br /> }<br /> }<br /> }<br /><br />thanks,<br />Sanat
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
Community Expert ,
Apr 02, 2009 Apr 02, 2009
It's the same in CS3 and CS4: feed an array to groups.add(). Suppose you have a page with several (ungrouped) items. Then these two lines create a group of all page items on that page:

myArray = myPage.pageItems.everyItem().getElements();
myPage.groups.add (myArray)

Peter
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
Explorer ,
Apr 02, 2009 Apr 02, 2009
Hi Sanat,

You might take a look at the documentation script Group.jsx--it's in the archive on the InDesign scripting home page.

Thanks,

Ole
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
New Here ,
Apr 03, 2009 Apr 03, 2009
hi everyone,finally i got my solution.Thanks everyone for ur great support.I wont hesitate to post the code so that other people can learn.If there is anything worng,then please let me know..thanks again..<br /><br />Code :<br /><br />main();<br /><br />function main(){<br /> if (app.documents.length != 0){<br /> if (app.selection.length > 0){<br /> //myDocument = app.documents.add();<br /> var myObjectList = new Array; <br /> var myObjectList1 = new Array; <br />for (i=0; i<app.selection.length; i++) <br /><br />myObjectList.push (app.selection); <br /><br />//alert ("length of myObjectList is "+myObjectList.length);<br /><br />var myGroup = app.activeDocument.groups.add(myObjectList); <br /><br />var myGroup1=myGroup.duplicate(myGroup1,[22,2]);<br />myGroup1.absoluteHorizontalScale=150;<br />myGroup1.absoluteVerticalScale=150;<br /><br /> }<br /> }<br /> }<br /><br />thanks and regards,<br />Sanat
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
Community Expert ,
Apr 03, 2009 Apr 03, 2009
Congratulations are in order :-)

I still haven't found out why

>app.activeDocument.groups.add(myObjectList);

keeps on failing on my system ... I'll try your script (after the weekend :-)), perhaps it was just a typo on my side.
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
Participant ,
Apr 03, 2009 Apr 03, 2009
Are the objects in your object list on the first spread of the document? If not, that's why it's failing. You should add groups to the page's or spread's groups collection.

Dave
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
New Here ,
Jul 08, 2009 Jul 08, 2009
LATEST

The abhove code is working fine in cs3 but is not working in cs2.

Could anyone give me the cs2 version of the same code.

Its duplicating the group but not enlarging after duplicatiing.I m using absolutehorizontal and vertical scale for enlargeing the group but it is not enlargeing the text inside that.

Thanks,

Sanat

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