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

Convert PX to CM

Explorer ,
Feb 12, 2019 Feb 12, 2019

Quick question

How convert PX to CM ?

var doc = activeDocument;

var artLayer = activeDocument.activeLayer;

var textItem = artLayer.textItem;

textItem.kind = TextType.PARAGRAPHTEXT;

var textWidth = textItem.width.as("px");

var textHeight = textItem.height.as("px");

alert(textWidth+"_"+textHeight);

textItem.width.as("cm");  ----> It does not show the correct value and the value is different depending on the resolution.

;

TOPICS
Actions and scripting
7.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
Adobe
Community Expert ,
Feb 12, 2019 Feb 12, 2019

I believe you need to set the units for everything to what ever you want to use:

app.preferences.rulerUnits = Units.PIXELS;

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 ,
Feb 12, 2019 Feb 12, 2019

I found a solution

var LB = activeDocument.activeLayer.bounds;

var width = LB[2].as("cm") - LB[0].as("cm");

alert(width);

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 ,
Feb 12, 2019 Feb 12, 2019

Leilang 

I found a solution

This is not true.
Just like almost always lying textItem.width and textItem.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 ,
Feb 12, 2019 Feb 12, 2019
LATEST

My point was that I found a way to solve my problem differently.

I wanted to know the width of the text in centimeters and now I know.

If I mislead you, I apologize;) Of course, textItem.width is still useless.

TEXTWIDTH.jpg

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