Book a Demo

Author Topic: SOLVED! Change color by script  (Read 3459 times)

skmeridian2

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
SOLVED! Change color by script
« on: April 02, 2015, 09:05:16 pm »
Hi,

I am looking for help. I would like to change color of an object via JavaScript in EA12. I prepared the code based on EA help which prepares new style (sNewStyle) and write it to the object:

Session.Output(sNewStyle);       //[13230758]
oDiagramObjects.GetAt(k).Style=sNewStyle;
var bSuccess=oDiagramObjects.GetAt(k).Update();
if(!bSuccess)
  Session.Output(oDiagramObjects.GetAt(k).GetLastError());
                                                
Repository.ReloadDiagram(oDiagrams.GetAt(j).DiagramID);
Session.Output(oDiagramObjects.GetAt(k).Style);     //[13242758]



But even bSuccess is true, the object does not contain the new style:

[13230757]      DUID=78BB293F;NSL=0;BFol=-1;LWth=-1;fontsz=0;bold=0;black=0;italic=0;ul=0;charset=0;pitch=0;UCRect=1;BCol=16777164;LCol=8388863;
[13230758]      DUID=78BB293F;NSL=0;BFol=-1;LWth=-1;fontsz=0;bold=0;black=0;italic=0;ul=0;charset=0;pitch=0;UCRect=1;BCol=9178367;LCol=8388863;
[13242758]      DUID=78BB293F;NSL=0;BFol=-1;LWth=-1;fontsz=0;bold=0;black=0;italic=0;ul=0;charset=0;pitch=0;UCRect=1;BCol=16777164;LCol=8388863;

Does anybody have an idea what is wrong in my code? Thanks in advance!

Milos
« Last Edit: April 02, 2015, 10:26:27 pm by skmeridian2 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change color by script
« Reply #1 on: April 02, 2015, 09:28:39 pm »
The way you're doing it looks suspicious to me. I guess each getAt returns a new object. You should try (note that I don't know the syntax of the language you use):
Code: [Select]
do = oDiagramObjects.GetAt(k);
do.Style = sNewStyle;
do.Style.Update();

q.
« Last Edit: April 02, 2015, 09:29:24 pm by qwerty »

skmeridian2

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Change color by script
« Reply #2 on: April 02, 2015, 10:22:37 pm »
Thank you for your advice, you are right! I changed the code to:

Session.Output(sNewStyle);
var oMyObject=oDiagramObjects.GetAt(k);
oMyObject.Style=sNewStyle;
Session.Output(oMyObject.Style);
var bSuc=oMyObject.Update();
if(!bSuc)
  Session.Output(oMyObject.GetLastError());
                                                
Repository.ReloadDiagram(oDiagram.DiagramID);
Session.Output(oDiagramObjects.GetAt(k).Style);


Everything works fine now!  8-)