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

cp.model.data: Get information of object

Explorer ,
Mar 22, 2017 Mar 22, 2017

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!

1.4K
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

correct answers 1 Correct answer

People's Champ , Mar 23, 2017 Mar 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'))

Translate
Engaged ,
Mar 23, 2017 Mar 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.

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 ,
Mar 23, 2017 Mar 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!

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
People's Champ ,
Mar 23, 2017 Mar 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'))

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 ,
Mar 23, 2017 Mar 23, 2017

Thank you very much! Great! It works perfectly fine!

I think there is a little typo in your formula for w. We have X = cp.D[elem].b[0], Y = cp.D[elem].b[1], X+width = cp.D[elem].b[2], Y+height = cp.D[elem].b[3]. This yields

w = cp.D[elem].b[2] - cp.D[elem].b[0]

So thank you again - your contribution to the forum is really a great help for me!

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
Engaged ,
Mar 31, 2017 Mar 31, 2017

@TLCMediaDesign

1. What does the ".b" in the code stand for ?

And also in CP output - SmartShape_1c:{b:[362,175,549,263},

2. What is being used for X, Y?

So if you're using a rectangle smart shape is X top left of rectangle?

.... what is Y?

Regards

Donal.

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
People's Champ ,
Mar 31, 2017 Mar 31, 2017

b is a property of the object that has the coordinates:

Like this in the CPM.js

si2390c: {

            b: [25, 65, 867, 99],

b = x, y, w+x, h+y

or actual css properties

25 = left

65 = top

867 = left + width

99 = top + height

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 ,
Mar 31, 2017 Mar 31, 2017

I wonder whether it's also possible to get the z-index of an element in a similar way. But maybe it's not. I cannot find the z-index in the CPM.js.

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
Engaged ,
Mar 31, 2017 Mar 31, 2017
LATEST

Thanks TLCMediaDesign.

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
Resources
Help resources