14 Replies Latest reply on Aug 6, 2018 12:58 AM by Laubender

    Select the Motion Path of a PageItem

    Justin Putney Level 2

      Does anyone know a way to select (or access) the Motion Path of a PageItem with animation applied using ExtendScript?

       

      I know it appears as a graphic line in the document, but I'm wondering if there's any connection between the animated item and the graphic line that represents the motion path.

       

      item.animationSettings.motionPath (and motionPathPoints) give the relative numbers, but I'd like to get my hands on the actual InDesign object. Any ideas?

        • 1. Re: Select the Motion Path of a PageItem
          Pickory Level 3

          Hello,

           

          I think it is generated on the fly. You can copy and paste it ( ID6 ) when it is selected / showing the bounds.

           

          P.

          • 2. Re: Select the Motion Path of a PageItem
            Justin Putney Level 2

            You're right about it being generated on the fly, Pickory. When I select the path manually and query the document with Extendscript, there's an extra item. I'm wondering if there's a way to select the path with ExtendScript.

            • 3. Re: Select the Motion Path of a PageItem
              Pickory Level 3

              I'm not sure if you can do this from a script. From C++, you have. IAnimationFacade.h

                /** Given an interface for an item with a motion path, create a new page item from the motion path points and select it.

                @param pageItemRef is the UIDRef of the page item to created a motion path item from.

                @return the UIDRef of the created item.

                @see SetPageItemAnimationMotionPath

                */

                virtual UIDRef CreateAnimationMotionPathPageItem(const UIDRef& pageItemRef) = 0;

               

              P.

              1 person found this helpful
              • 4. Re: Select the Motion Path of a PageItem
                Laubender Adobe Community Professional & MVP

                Hi Justin,

                I read your feature request about motion paths here:

                ExtendScript access to animation path object – Adobe InDesign Feedback

                 

                I think we already have access to a given motion path of an object through properties motionPath and motionPathPoints of animationSettings of a given object on the page.

                 

                To remove a motionPath do simply:

                pageItem.animationSettings.motionPath = []; // Assign an empty array! Assigning e.g. null is not working and throws an error.
                

                 

                I did not dig very deep into the problem adding a motion path, but it should be possible to assign something like the entirePath array of a given path.

                First tests are showing that you cannot directly assign an entirePath array to property motionPath. I could be wrong. I do not fully understand what's required with:

                InDesign ExtendScript API (13.0)

                 

                However, what is working, is to use a selection and invoke a menu action for applying an existing spline item as motion path:

                Something like the code below with two objects in the document, a rectangle and a polygon:

                 

                var doc = app.documents[0];
                var polyon = doc.polygons[0];
                var rectangle = doc.rectangles[0];
                
                app.select( rectangle );
                app.select( polyon , SelectionOptions.ADD_TO );
                
                app.menuActions.itemByName("$ID/kAnimationUIConvertToMotionPathMenuItem").invoke();
                

                 

                BeforeAddingMotionPath-1.PNG

                 

                After running the snippet:

                 

                AfterAddingMotionPath-1.PNG

                 

                 

                If you found a better method using the entire path as part of the value of motionPath let me know.

                 

                To select the motion path through scripting is another thing I did not manage yet.

                Even if you read out the id number of a selectable motion path item app.select() is not able to select it.

                 

                AfterAddingMotionPath-2.PNG

                Object selected manually:

                AfterAddingMotionPath-3.PNG

                 

                Regards,
                Uwe

                • 5. Re: Select the Motion Path of a PageItem
                  Pickory Level 3

                  Have a look at.

                   

                  animationSettings.motionPathPoints

                   

                  P.

                  • 6. Re: Select the Motion Path of a PageItem
                    Laubender Adobe Community Professional & MVP

                    Hi Pickory,

                    yes, but I still see no correllation between the entirePath of a selected motionPath and the value of motionPathPoints.

                    Perhaps you can enlighten me?

                     

                    Here the value of motionPathPoints with a given object, an array with length 2 containing an array and a boolean value that denotes if the path is open:

                     

                    [ [ 0,0,0,0,0,0,204.094488188976,0,204.094488188976,0,204.094488188976,0 ] , true ]

                     

                    Then I select the motion path manually and retrieve the entirePath array of paths[0] of the selected item:

                     

                    [ [ 162.283464566929,162.283464566547] , [ 366.377952755906,162.283464566547]  ]

                     

                    How will that go together?

                     

                    Regards,
                    Uwe

                    • 7. Re: Select the Motion Path of a PageItem
                      Pickory Level 3

                      I suspect the UI is a fudge, forget that.

                       

                      The real internals are what you need to look at. animationSettings.motionPathPoints

                       

                      P.

                      • 8. Re: Select the Motion Path of a PageItem
                        Laubender Adobe Community Professional & MVP

                        Ok. I can decipher one value in motionPathPoints and that is 204.094488188976, that is the geometrical length of the path in points.

                        Why it's there three times I cannot tell.

                         

                        AfterAddingMotionPath-4.PNG

                         

                        Regards,
                        Uwe

                        • 9. Re: Select the Motion Path of a PageItem
                          Laubender Adobe Community Professional & MVP

                          Ok. I was wrong.

                          My assumption now of value motionPathPoints is:

                           

                          [

                              [

                                  [ x,y ]  , // offset from the center of the object that is animated

                                  [ x,y ]  , // x,y of the left direction point of path point 1

                                  [ x,y ]  // x,y of the right direction point of path point 1

                              ] ,

                            

                              [

                                  [ x,y ] ,  // offset from the center of the object that is animated

                                  [ x,y ] , // x,y of the left direction point of path point 2

                                  [ x,y ]  // x,y of the right direction point of path point 2

                              ]

                                ,

                               true

                           

                          ]

                           

                          Zero point of the values is the center of the object that moves.

                          All values in points.

                           

                          Regards,
                          Uwe

                          1 person found this helpful
                          • 10. Re: Select the Motion Path of a PageItem
                            Laubender Adobe Community Professional & MVP

                            But I have a problem with my samples.

                            I can read out value of motionPathPoints from animationSettings, but not value of motionPath.

                            That simply returns an array of length 0.

                             

                            InDesign CC 2018.1 on WIndows 10.

                             

                            Regards,
                            Uwe

                            • 11. Re: Select the Motion Path of a PageItem
                              Laubender Adobe Community Professional & MVP

                              As it seems applying an ordered array in the structure I posted in reply 9 as value of motionPathPoints from animationSettings is enough to create the motion path.

                               

                              That array can be derived from an existing path and its pathPoints in the document:

                               

                              pathPoint.anchor,

                              pathPoint.leftDirection

                              pathPoint.rightDirection

                               

                              The position of the zero point and the distance from the center of the object you want to move to a given pathPoint has to be factored in. Also that all values used in motionPathPoints[0] will be needed in Points.

                               

                              The value for motionPathPoints[1] can be derived from path.pathType.

                              If pathType is PathType.OPEN_PATH the value will be true, if pathType is PathType.CLOSED_PATH the value will be false.

                               

                              Here a suggestion for a function that will express all things said above with a use case, one rectangle where one likes to apply a motion path and a polygon where the motion path should be taken from the path points of its path[0].

                               

                              /**
                              * @@@BUILDINFO@@@ addMotionPathTo-FUNCTION.jsx !Version! Tue Jul 31 2018 10:56:53 GMT+0200
                              */
                              
                              /*
                                  Snippet by Uwe Laubender
                                  
                                  Posted at:
                                  
                                  Select the Motion Path of a PageItem
                                  Justin Putney Oct 28, 2014
                                  https://forums.adobe.com/message/6877189#6877189
                                  
                                  Introducing function addMotionPathTo()
                                  
                                  Four arguments:
                                  pageItemToAddMotionPathTo
                                  usePathOfPageItem
                                  document
                                  removePageItemThatGivesThePath
                                  
                              */
                              
                              // Use case of function addMotionPathTo()
                              var doc = app.documents[0];
                              var pageItemToAddMotionPathTo = doc.rectangles[0];
                              var usePathOfPageItem = doc.polygons[0];
                              
                              addMotionPathTo( pageItemToAddMotionPathTo , usePathOfPageItem , doc , true );
                              
                              
                              function addMotionPathTo( pageItemToAddMotionPathTo , usePathOfPageItem , document , removePageItemThatGivesThePath )
                              /*
                                  pageItemToAddMotionPathTo : pageItem that a motion path should be applied to
                                  usePathOfPageItem : pageItem where paths[0] will be used as motion path
                                  document : object document where pageItemToAddMotionPathTo and usePathOfPageItem are positioned
                                  removePageItemThatGivesThePath : Boolean, when true usePathOfPageItem will be removed after applying the motion path
                              */
                              {
                                  var viewPreferences = document.viewPreferences.properties ;
                                  document.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS ;
                                  document.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS ;
                                  document.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN ;
                              
                                  var zeroPoint = document.zeroPoint ;
                              
                                  var open = true ;
                                  var gB = pageItemToAddMotionPathTo.geometricBounds;
                                  var center = [ gB[3] - gB[1] , gB[2] - gB[0] ] ;
                                  document.zeroPoint = center ;
                              
                              
                                  var pathPoints = usePathOfPageItem.paths[0].pathPoints.everyItem().getElements();
                                  var pathPointsLength = pathPoints.length;
                              
                                  if( usePathOfPageItem.paths[0].pathType == PathType.CLOSED_PATH ){ open = false };
                                  
                                  var motionPathPoints =  [ [] , open ];
                                  
                                  var distX = pathPoints[0].anchor[0] ;
                                  var distY = pathPoints[0].anchor[1] ;
                              
                                  for( var n=0;n<pathPointsLength;n++ )
                                  {
                                      motionPathPoints[0][n] =
                                      [
                                          [ pathPoints[n].anchor[0] - distX , pathPoints[n].anchor[1] - distY ]  ,
                                          [ pathPoints[n].leftDirection[0] - distX , pathPoints[n].leftDirection[1] - distY ] ,
                                          [ pathPoints[n].rightDirection[0] - distX , pathPoints[n].rightDirection[1] - distY ]
                                      ]
                                  };
                              
                                  pageItemToAddMotionPathTo.animationSettings.motionPathPoints = motionPathPoints ;
                              
                                  document.zeroPoint = zeroPoint ;
                                  document.viewPreferences.properties = viewPreferences ;
                                  
                                  if( removePageItemThatGivesThePath ){ usePathOfPageItem.remove() };
                                  
                              };
                              

                               

                              Regards,
                              Uwe

                              • 12. Re: Select the Motion Path of a PageItem
                                Laubender Adobe Community Professional & MVP

                                FWIW:

                                The object that is the motion path is not part of

                                document.allPageItems

                                if the motion path object is not selected by the user.

                                 

                                If the user selects the motion path the allPageItems array suddenly has an additional object.

                                And that comes with a new id if it is selected anew.

                                 

                                And the motion path object also cannot be fetched if you loop through

                                document.pageItems.itemByID(n)

                                where the loop length is the highest id number you can get when adding a new temp rectangle to the document and n starts with 0.

                                 

                                So to answer a part of the thread's title:
                                You cannot select the motion part by scripting.

                                Access to the motion path path points, yes. But selection no…

                                 

                                Regards,
                                Uwe

                                • 13. Re: Select the Motion Path of a PageItem
                                  Dirk Becker Level 4

                                  I just had a deeper look - that motion path is indeed a regular page item while selected, and discarded on deselect.

                                   

                                  Pickory The kSplineItemBoss is apparently created by the adornment tracker on click, stored at kDocBoss / IID_ISPLINESTATEMOTIONPAGEITEMDATA.

                                  1 person found this helpful
                                  • 14. Re: Select the Motion Path of a PageItem
                                    Laubender Adobe Community Professional & MVP

                                    Hi Dirk,

                                    yes, the motion path points are used as a blueprint for a regular page item while selected and that page item is removed when deselected. While selected and edited by the user, eg. the user is adding or removing path points, the motionPathPoints array is still the same. Only if the user deselects the edited page item the new path properties are written back to the motion path.

                                     

                                    If the user changes position of the first path point the object that is holding the motion path is actually moved as well.

                                    By scripting one could change the position of the first path point of the motion path without moving the object that will be moved by the path.

                                     

                                    The motion of the object always follows the actual path discription of the motion path and not the widget representation of the motion path. See below where I selected the motion path's path ( in blue ) with the direct selection tool while the widget with the arrow shows a slightly different path in green:

                                     

                                    MotionFollowsPath-Not-PathWidget-Presentation.PNG

                                     

                                    Regards,
                                    Uwe