Skip navigation
VanithaAllwin
Currently Being Moderated

How to convert group into multistate object

Jun 18, 2012 1:50 AM

Hi,

 

How can i convert a group into multistate object? Please help.

 

Thanks,

Vanitha Allwin

 
Replies
  • Currently Being Moderated
    Jun 18, 2012 2:06 AM   in reply to VanithaAllwin

    @Vanitha – what do you want exactly?
    An MSO with 1 state (not possible, an MSO needs at least 2 states) that holds the group?

     

    An MSO where every part of the group get its own state?

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 18, 2012 2:42 AM   in reply to VanithaAllwin

    @Vanitha – To help you we will need some code from you. At least a snippet of an working example (the one you converted a single text frame into an MSO).

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 1:51 AM   in reply to VanithaAllwin

    @Vanitha – I did not test your code, but I can show you an code example that generates an MSO out of a selection. It is working with groups and single objects selected (that is a special case). There are no tests for a valid selection, but I give you hints in the code what is missing:

     

    var d=app.documents[0];
    var MSOlength = d.multiStateObjects.length;
     
    if(app.selection.length ===0){alert("You have nothing selected. STOP!"){exit(0)}};
     
    //We have to add some more tests for the validity of a selection:
    //Do not add selection to an MSO, if the selection is text, if it is locked, if it is an anchored object 
    //etc.
     
    var sel = app.selection;
     
    //Adding an default MSO with 2 default states,
    //each contain 1 default rectangle 
    //at position (upper left corner) [0,0]:
    var MSO = app.documents[0].multiStateObjects.add({
        name:"MSO"+"_"+(MSOlength+1)
        });
     
    //Adding all selected objects to a seperate state:
    for(var n=0;n<sel.length;n++){
        MSO.addItemsAsState(sel[n]);
        };
     
    //Special case: selection length = 1:
    //We add another state and set the geometric bounds of its default rectangle 
    //to the geometric bounds of the selected object:
    if(sel.length===1){
        MSO.states.add();
        MSO.states[-1].pageItems[0].geometricBounds = sel[0].geometricBounds;
        };
     
    //Cleaning up:
     
    //1. Removing the 2 default states:
    MSO.states[0].remove();
    MSO.states[0].remove();
     
    //2. Renaming the states:
    for(var n=0;n<MSO.states.length;n++){
        MSO.states[n].name = "State "+(n+1);
        };
    

     

    Adding objects (also groups) to an already existing state inside an MSO is a different case.
    I still don't know if you want to add each object of a group to its own state. Would you please answer that?

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 2:36 AM   in reply to VanithaAllwin

    @Vanitha – What kind of object is an "answer"? I guess it could be a text frame or a group. Could it be a couple of objects? If so, do they go all together in one single state?

     

    If so, group all objects that define an "answer", create a new MSO, add that group to the MSO with addItemsAsState().

    The MSO now has 3 states. Remove the first state and then set the geometricBounds of the default rectangle of the first state (formerly the second default state) to the geometricBounds of the group.

     

    If the "answer" is a single object (no group) you simply add that single object to a new MSO. Again: remove the first state, set the geometricBounds of the default rectangle of the first state (formerly the second default state) to the geometricBounds of the single object you detect as "answer".

     

    I hope I understood your basic situation.
    If not, can you provide a simple sample as an IDML file somewhere to download?

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 11:22 PM   in reply to VanithaAllwin

    @Vanitha – I can only repeat what I said in my answer #7 in more detail:

     

    0. Store the geometricBounds of "theAnswer" in a variable:

     

    var theAnswerGB = theAnswer.geometricBounds;
    

     

    1. add a new MSO

    1.1 without setting any properties besides "name".

    1.2 leave the geometricBounds alone

     

    var theMSO = thePageRef.multiStateObjects.add({name:"multiState"+cnt});
    

     

    2. then add the "answer" as new state (see my code in #5):

     

    theMSO.addItemsAsState(theAnswer);
    

     

    3. then get rid of the first default state of the MSO:

     

    theMSO.states[0].remove();
    

     

    3.1 you now have an MSO with 2 states:

    state 1: a default empty rectangle at position [0,0] (upper left corner)

    state 2: your "theAnswer" object

     

    4. and now the trick: set the default rectangle of state 1 to the geometricBounds of "theAnswer":

     

    theMSO.states[0].pageItems[0].geometricBounds = theAnswerGB;
    

     

    5. Finally rename the states of the MSO:

     

    theMSO.states[0].name = "m1";
    theMSO.states[1].name = "m2";
    

     

    I think the core of this is:

     

    1. Do not set the geometricBounds of the MSO during creation of the new MSO

    2. Use "addItemsAsState()" instead "addItemsToState()" for adding "theAnswer" to the new MSO

     

    Hope this helps,

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 11:48 PM   in reply to VanithaAllwin

    @Vanitha – without seeing your InDesign file I cannot help with that any further.

    If you could provide a single page (IDML export) with "theAnswer" beeing a group, I could dig deeper into the problem.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 12:31 AM   in reply to VanithaAllwin

    @Vanitha – I sent you a private message.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 5:35 AM   in reply to Laubender

    After investigating the individual original page (thank you, Vanitha, for providing the file), the case seems quite clear to me:

     

    The problem is a tiny group of graphic lines, which is so small, that its geometric bounds cannot be applied to a new MSO (so it seems at least).

     

    Strange enough one could add a new MSO to a page that is 0.01 x 0.01 mm:

     

    var myMSO = app.documents[0].pages[0].multiStateObjects.add();
    myMSO.states.everyItem().pageItems.everyItem().geometricBounds = [0,0,"0.01 mm","0.01 mm"];
    


    I have to find out what that means in regards to this individual case here.

     

    Maybe:

    1. add a new MSO without setting its geometricBounds and later set the geometricBounds of its default objects to a very small size.

    2. then add the geometricBounds of the object on state 2 to the default object on state 1.

     

    I will report here, if I find a conclusion…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 5:47 AM   in reply to Laubender

    After inspecting the problem group, I have to tell you, that the height of that group = 0 (when calculated in geometricBounds).

    You cannot apply a height of "0" to an MSO.

     

     

    GeometricBounds of problem group:

     

    45.0541666666667,

    17.8809523809524,

    45.0541666666667,

    19.5178571428571

     

    VisibleBounds of problem group :

     

    45.0333333333333,

    17.8809523809524,

    45.075,

    19.5178571428571

     

    So, instead of using the geometricBounds properties, we should use the visibleBounds properties to determine the size of the MSO (its geometricBounds).

     

    Uwe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points