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

Convert PX to CM

Explorer ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

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

Views

5.4K

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

app.preferences.rulerUnits = Units.PIXELS;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

I found a solution

var LB = activeDocument.activeLayer.bounds;

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

alert(width);

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Leilang 

I found a solution

This is not true.
Just like almost always lying textItem.width and textItem.height

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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