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

New value for property position

Participant ,
Nov 20, 2018 Nov 20, 2018

Hello, hello

I have a problem with property position about pathItem in Illustrator, in Javascript I can write : object.position[0] = newValue and position from object change.

But no with illustrator objects, I can't use pathItem.position[0] = newValue because position from pathItem don't change.

Capture.PNG

I try a test, I share with you code :

---------

var x = app.activeDocument.activeLayer.pathItems["coucou"]

$.writeln("First value : " + x.position) //Result : First value : 17,-11

x.position[0] = 10

x.position[1] = 20

$.writeln("New value : " + x.position) //Result: New value : 17,-11

---------

Thank you, thank you for your help and sorry for my bad english

TOPICS
Scripting
1.1K
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

Community Expert , Nov 20, 2018 Nov 20, 2018

that's how it works, position property takes a pair of values. You can't assign each value individually.

try this instead, if you want to change only the x position

var left = 10;

var top = x.position[1];

x.position = [left, top];

Translate
Adobe
Community Expert ,
Nov 20, 2018 Nov 20, 2018

try this:

var x = app.activeDocument.activeLayer.pathItems["coucou"]

$.writeln("First value : " + x.position) //Result : First value : 17,-11

x.position = [10,20];

$.writeln("New value : " + x.position) //Result: New value : 17,-11

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
Participant ,
Nov 20, 2018 Nov 20, 2018

Hello, thank you for your answer.

I can do this but I want just modify one value without write all array.

When I write :

---

var x = [1, 2, 3];

x[0] = 10;

$.writeln(x[0]) //Result : 10

---

I want do it with property position without write all array.

It's work for object JavaScript but no for Illustrator object.

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
Community Expert ,
Nov 20, 2018 Nov 20, 2018

that's how it works, position property takes a pair of values. You can't assign each value individually.

try this instead, if you want to change only the x position

var left = 10;

var top = x.position[1];

x.position = [left, top];

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
Participant ,
Nov 20, 2018 Nov 20, 2018

Ok, thus impossible with property position, thank you because i don't saw it in documentation 😕

It's same for all array about illustrator object and illustrator properties or just for property position ?

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
Community Expert ,
Nov 20, 2018 Nov 20, 2018

No, it's not impossible. Just like carlos mentioned, you simply have to feed it an array. but you don't need to manually populate all of the elements of the array.. you can pull one of the values right out of the existing position array.

x.position = [10,x.position[1]];

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
Participant ,
Nov 20, 2018 Nov 20, 2018

Yes, i do it, thank you.

Just, I don't undestand why I can just write pathItem.position[0] = newValue

Thx to take time for answer 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
Advocate ,
Nov 20, 2018 Nov 20, 2018

Salut !

La vie est dure...

// JavaScript Doc

  var docRef = documents.add( DocumentColorSpace.CMYK,600,800);

      docRef.rulerOrigin = [0,0];

      ogjRect = docRef.pathItems.rectangle(750,20,100,100);

      redraw();

      alert(ogjRect.position);

      var dx = 5;

      for (var i = 1; i < 50; i++) {

          ogjRect.position = [20+dx*i,750];

          redraw();

      }

      alert(ogjRect.position)

      for (var j = 1; j < 50; j++) {

          ogjRect.position = [ogjRect.position[0]-dx,ogjRect.position[1]];

          redraw();

      }

      alert(ogjRect.position)

de elleere

position Array de 2 nombres

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
Participant ,
Nov 20, 2018 Nov 20, 2018
LATEST

Ah vous parlez français, c'est cool.

Sinon, j'ai fais a peu près ça pour contourner le problème.

C'est dommage que le fait que la propriété position ne prend qu'un couple de valeurs, ne soit pas écrit dans la documentation ExtendScript.

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
Community Expert ,
Nov 20, 2018 Nov 20, 2018

function test()

{

     var docRef = app.activeDocument;

     var path = docRef.pageItems[0];

     path.left = 10;

     path.top = 20;

}

test();

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
Participant ,
Nov 20, 2018 Nov 20, 2018

Thank you I tried left and top but left and top include stroke weight @@

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