Skip to main content
Inspiring
March 23, 2017
Answered

cp.model.data: Get information of object

  • March 23, 2017
  • 1 reply
  • 1706 views

Hi all,

how can I use cp.model.data in order to get the information of an object? This is really important for me! Let me explain my question more in detail:

With cp.model.data I get properties of the entire project, for example with cp.model.data.project_main.slides an array of all slides of the project.

Similarly, cp.model.data yields information of an object: For example, if SmartShape_1 is an object which triggers an action, I can access this action by cp.model.data.SmartShape_1.oca (and trigger the action by cp.runJavascript(cp.model.data.SmartShape_1.oca).

My question: I think in the same way it should be possible to access the remaining data of the object (I'm mainly interested in the x- and y-coordinates and in the width and height of the object). But how can I access this information exactly? For example, how can I populate a variable with the x-coordinate of the object?

If I have a look in the CPM.js, I can see the above mentioned oca as well as the coordinates (more precisely, I find the left x-coordinate, the upper y-coordinate, the right x-coordinate and the bottom y-coordinate of the object) - bold in the code below:

SmartShape_1:{type:612,from:1,to:18000,rp:0,rpa:0,mdi:'SmartShape_1c',retainState:false,immo:false,apsn:'Slide5663',JSONTT_4:[],cpa:true,oca:'cp.jumpToNextSlide();',JSONTT_5:[],ofa:'cpCmndResume = 1;',trin:0,trout:0,stl:[{stn:'Normal',stt:0,stsi:[8827]}],stis:0,bstiid:-1,sipst:0,sicbs:false,sihhs:false,sihds:false,isDD:false},SmartShape_1c:{b:[362,175,549,263],uid:8827,dn:'SmartShape_1',visible:1,effectiveVi:1,JSONEffectData:false,accstr:' ',traccstr:'',ti:-1,sc:'#0080ff',sw:0,ss:0,fa:100,bc:'#00beff',p0:[[0],[1,362,175],[2,362,263],[2,549,263],[2,549,175],[2,362,175],[4]],svg:false,vbwr:[362,175,549,263],vb:[362,175,549,263]}

So I'm quite sure it should be possible to access this information in some way. Can anybody help? Or is there any other JavaScript method to get the coordinates and populate a variable with it?

Thank you very much in advance for any help!

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    You can use this function or just the contents depending on your use. This will return an array [width, height]

    function getSize( elem )

        {

         var w = cp.D[elem].b[0]+cp.D[elem].b[1];

         var h = cp.D[elem].b[3]-cp.D[elem].b[1];

         return [w,h];

        }

        console.log(getSize('barc'))

    1 reply

    Inspiring
    March 23, 2017

    See TLCMediaDesign response here:

    Captivate scripting - change x & y position of object

    The item in blue is the name of the object.

    You may have to append a "c" (canvas) to the name.

    var obj = document.getElementById( 'Image_1c' );

    var posX = parseInt( obj.style.left );

    var posY = parseInt( obj.style.top );

    I'm sure width and height would work similiarly.

    Donal.

    Inspiring
    March 23, 2017

    Hi Donal,

    thank you very much for your answer and for helping me!

    The problem with this approach is that it only works if the object is on the same slide when I execute the JS. However I need to get the coordinates of an arbitrary element of the project (also for objects on other slides).

    Use case (just one example of many): I have to finish a project begun by somebody else. Many of the objects on my slides have to fit to the size and coordinates of the already existing slides (many small objects without style definition or whatever). Maybe the other person even changes his slides from time to time.

    I could easily handle the problem if I was able to get the position of these objects by JS.

    Thank you to everybody helping me!

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    March 23, 2017

    You can use this function or just the contents depending on your use. This will return an array [width, height]

    function getSize( elem )

        {

         var w = cp.D[elem].b[0]+cp.D[elem].b[1];

         var h = cp.D[elem].b[3]-cp.D[elem].b[1];

         return [w,h];

        }

        console.log(getSize('barc'))