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

Convert a pixel value into a millimeter value using sAIUser->IUAIRealToStringUnits

Participant ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

Hi all,

I have a value with unit pixel or document points and want to convert it to a value with unit millimeter.

The only way I have found so far, is the following:

AIReal pixelValue = 0.316522;
ai::UnicodeString unicodeStr;
sAIUser->IUAIRealToStringUnits(pixelValue, -1, unicodeStr); 
//unicodeStr = "0,1117 mm"
AIReal millimeterValue = 0;
sAIUser->IUStringToAIReal(unicodeStr, &millimeterValue); 
//millimeterValue = 0.1117

That is exactly the result I want to have!

But when I change the ruler-unit in Illustrator from millimeter to e.g. pixel, I get this result:

AIReal pixelValue = 0.316522;
ai::UnicodeString unicodeStr;
sAIUser->IUAIRealToStringUnits(pixelValue, -1, unicodeStr); 
//unicodeStr = "0,3165 px"
AIReal millimeterValue = 0;
sAIUser->IUStringToAIReal(unicodeStr, &millimeterValue); 
//millimeterValue = 0.3165

What can I do to always convert the pixel value to the corresponding millimeter value, regardless of which ruler-unit is set in Illustrator?

Thank you very much in advance.

Best Regards,

Fabian

TOPICS
SDK , Third party plugins , Tools

Views

209

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
Guide ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

There's no way to configure the destination unit for that function. If you want a specific unit, regardless of the current ruler, you need to do the calculation yourself and then use IUAIRealToString() if you need help formatting it for the currently selected locale.

 

I thought there were helper functions, but if there are I don't remember where to find them. I checked how we do this and we manage all unit-to-unit conversions ourselves (since it's fairly straight forward) without using the API, except to get the current ruler unit if that matters to the operation. That we're not using any helper function suggests to me that they don't exist or I assume I'd have written the code to use them 🙂

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
Participant ,
Mar 17, 2023 Mar 17, 2023

Copy link to clipboard

Copied

LATEST

Hello Mr. Patterson,

thanks for the fast answer.

Could you show me how you are doing the unit-to-unit conversion yourself?

I mean, what mathematical formulas or functions do I have to use, to convert e.g. the pixel-value "0.316522" into the millimeter-value "0.1117"?

Thank you very much in advance.

Fabian Taubitz

 

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