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

need a script to calculate raduis and create frame around shape

Explorer ,
Nov 21, 2020 Nov 21, 2020

I need a script that calculates the radius of a rectangle on the side, and creates a dotted pink square around a shape. Attached files

 

https://www.dropbox.com/sh/gcxlylnbhy5vop3/AAATBuzwS1EFLzLUBPyE999da?dl=0

 

 

TOPICS
Scripting
1.7K
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
Explorer ,
Nov 22, 2020 Nov 22, 2020

Screen Shot 2020-11-22 at 20.58.16.pngexpand image

i have an error. dosn't work.

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 ,
Nov 22, 2020 Nov 22, 2020

Another thing. It's important that it works at the end of the previous script

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 ,
Nov 22, 2020 Nov 22, 2020

Okay I understand why it did not work. (According to what you explained).
Now it works but: The calculation is incorrect. When the rounding is 5, it gives a very high number. please check.
In addition, I want to put this from the top left, of the shape, and have a prefix:
raduis =

Attached is a screenshot.
many thanks!!!Screen Shot 2020-11-23 at 2.40.01.pngexpand image

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 23, 2020 Nov 23, 2020

The result you get is a pt-value ... you have to convert it into mm.

// select round-cornered rectangle
var points = app.selection[0].pathPoints;
var x1 = points[4].anchor[0], x2 = points[5].anchor[0];
var y1 = points[4].anchor[1], y2 = points[5].anchor[1];
var rect1 = app.activeDocument.pathItems.rectangle(y1 + 20, x2 - 60, 50, 20);
var text2 = app.activeDocument.textFrames.areaText(rect1);
text2.contents = +(Math.round((Math.abs(x1 - x2)*0.352777777)+ "e+3")  + "e-3") + " mm";
text2.contents = "r " + text2.contents;
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 ,
Nov 23, 2020 Nov 23, 2020

no. It's not good yet. Attached is a screenshot.Screen Shot 2020-11-23 at 17.50.12.pngexpand image

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 ,
Nov 23, 2020 Nov 23, 2020

It should be 20. And even if you are already correcting, you should expand the text box so that the text does not cut.

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 ,
Nov 23, 2020 Nov 23, 2020

And one last request: if you can have it from top left
Because it conflicts with the dimensions of the rectangle (other script)

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 ,
Nov 23, 2020 Nov 23, 2020

Hi

femkeblanco


I hope you do not forget me.
You have already started and it really helps me .... thank you very much

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 23, 2020 Nov 23, 2020

Hi @femkeblanco and @Tom Winkelmann 

A side note:
You both use the wrong path points for calculation.

In this case:

instead of:

var x1 = points[4].anchor[0], x2 = points[5].anchor[0];
var y1 = points[4].anchor[1], y2 = points[5].anchor[1];

use:

var x1 = points[3].anchor[0], x2 = points[4].anchor[0];
var y1 = points[3].anchor[1], y2 = points[4].anchor[1];

 

But this will only help in this special case. Try not to rotate or mirror the rounded rectangle!

 

As I wrote at the beginning of this thread: A lot more math is required.

First you need to identify the two path points in the upper left corner. Then use these path points for your calculation.

 

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 ,
Nov 23, 2020 Nov 23, 2020

Excellent! This is what I need !!!
Just please move left, (and bigger) similar to the attached drawing.

 

Screen Shot 2020-11-23 at 19.00.13.pngexpand image

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 23, 2020 Nov 23, 2020

@pixxxelschubser 

I didn't pay any attention to the path points because the aviel222 wrote that it now works, but you are right...

For me it looks like aviel222 does not make any attempts to create the required script itself. Therefore I would advise him to think about a plugin like "Hotdoor CADTools" or "BPT-Pro4".

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 23, 2020 Nov 23, 2020

You are right.

(Furthermore he will not gives "likes" to any good answers or do not mark solved threads with correct answers.)

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 ,
Nov 23, 2020 Nov 23, 2020

Basically, it really does not work in all cases.
How much does such a thing cost to write to me? It is also possible in private.

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 ,
Nov 23, 2020 Nov 23, 2020

How do you change the code so that the text is larger and more on the side, and the text box is not cut?

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
Guide ,
Nov 23, 2020 Nov 23, 2020

Thanks @pixxxelschubser.  I presumed that the commonest way to create a rectangle is to start dragging from the upper left to the lower right.  I must finally agree with you at this stage:  too many assumptions are being made. 

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 ,
Nov 24, 2020 Nov 24, 2020
LATEST

Hey friends.
I understand you're a little tired of me. But I have a really last request.
The code does not work in the cs6 version I have in the workplace I work.
Is there a way to adjust it?

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