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

Creating circles?

Participant ,
Feb 16, 2020 Feb 16, 2020

Greetings!!!

 

Thanks to many I've gotten my mixed inks swatchbook generator up and running:

download it here: Let it Shine! 

 

Currently, I'm struggling with making the swatch a circle.

 

if(customSwatchShapeNumberOfSides == 0)
{
   polygon = currentPage.ovals.add({geometricBounds:[topLeftCoordinates_Y,  topLeftCoordinates_X, bottomRightCoordinates_Y,  bottomRightCoordinates_X], numberOfSides:customSwatchShapeNumberOfSides, strokeWeight: 0, fillColor: swatchesToUse[k].name, cornerRadius:100} );
}

 

It's not working. Could anyone shed light on this error of mine please?

 

Thank you kindly!

 

Antoine

TOPICS
Scripting
1.3K
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 2 Correct answers

Community Expert , Feb 17, 2020 Feb 17, 2020

Hi Antoine,

I don't understand why you are using properties:

numberOfSides and cornerRadius

when using ovals.add().

 

FWIW: What exactly is not working when executing your code?

Any error message? Is the result not an oval? Anyting else?

 

Better look up all available properties of object Oval in DOM documentation:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Oval.html

 

Regards,
Uwe Laubender

( ACP )

 

Translate
Community Expert , Feb 17, 2020 Feb 17, 2020

You could also make a spiral grid with circles. This makes a sunflower spiral :

 

 

 

var d = app.activeDocument
var ovp = d.viewPreferences.properties;
d.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.POINTS, verticalMeasurementUnits:MeasurementUnits.POINTS, rulerOrigin:RulerOrigin.PAGE_ORIGIN};
d.zeroPoint = [d.documentPreferences.pageWidth*.5, d.documentPreferences.pageHeight*.5];

var n = 250
var tp = 100/n
var w = h = 10;
var space = 100;
var phi = 1.6180339887498
...
Translate
Community Expert ,
Feb 16, 2020 Feb 16, 2020

Pages are part of the active window, so I think you’ll need something like this

 

var p = app.activeWindow.activePage;
p.ovals.add();
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 ,
Feb 16, 2020 Feb 16, 2020

In case you haven’t tried it, the modulus % operator is an easy way to make swatch grids. This makes a 5 x 5 grid of 1" circles filled with Black, with a .1" space in between

 

 

 

var ovp = app.activeDocument.viewPreferences.properties;
app.activeDocument.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.INCHES, verticalMeasurementUnits:MeasurementUnits.INCHES}

var ncols = 5;
var nrows = 5;
var w = 1;
var h = 1;
var gut = .1;
var xs = xoff = 1;
var yoff = 1;

var p = app.activeWindow.activePage;

for (var i = 0; i < ncols*nrows; i++){
    if(i%ncols>0){
        xoff = xoff + w + gut 
        p.ovals.add({geometricBounds:[yoff, xoff, yoff+h, xoff+w], fillColor:"Black"});
    }else{
        xoff = xs 
        yoff = yoff + h + gut
        p.ovals.add({geometricBounds:[yoff, xoff, yoff+h, xoff+w], fillColor:"Black"});
    }
};   

app.activeDocument.viewPreferences.properties = ovp; 

 

 

 

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 ,
Feb 17, 2020 Feb 17, 2020

As I wrote I kept thinking 'there gotta be an easier way than this...'  Sigh.

Thanks Rob!

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 ,
Feb 17, 2020 Feb 17, 2020

You could also make a spiral grid with circles. This makes a sunflower spiral :

 

 

 

var d = app.activeDocument
var ovp = d.viewPreferences.properties;
d.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.POINTS, verticalMeasurementUnits:MeasurementUnits.POINTS, rulerOrigin:RulerOrigin.PAGE_ORIGIN};
d.zeroPoint = [d.documentPreferences.pageWidth*.5, d.documentPreferences.pageHeight*.5];

var n = 250
var tp = 100/n
var w = h = 10;
var space = 100;
var phi = 1.61803398874989
var pos, ov; 
var p = app.activeWindow.activePage;

for (var i = 0; i < n; i++) {
        pos=getPos(i);
        pos = [pos[0]-(w*.5), pos[1]-(h*.5)];

        ov = p.ovals.add({geometricBounds:[-(h*.5), -(w*.5), h*.5, w*.5], fillColor:"Black", fillTint:(n-i)*tp});
        
        if (i==0){
            var startingX = getPos(1)
            ov.move([pos[0]-(startingX[0]*Math.sqrt(phi)), pos[1]]);
        }else{
            ov.move(pos);
        }
}

d.viewPreferences.properties = ovp; 


/**
* @param num increment number
* @return an X,Y position as phi 1.61803398874989
*/	

function getPos(num) {
    
    var a=[];
    var angle = phi*2*Math.PI*num;
    var px=Math.cos(angle)*Math.sqrt(num*phi*(space));
	var py=Math.sin(angle)*Math.sqrt(num*phi*(space));
    a.push(px);
	a.push(py);

	return a;
};

 

 

 

Screen Shot 18.png

 

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 ,
Feb 17, 2020 Feb 17, 2020

Hi Antoine,

I don't understand why you are using properties:

numberOfSides and cornerRadius

when using ovals.add().

 

FWIW: What exactly is not working when executing your code?

Any error message? Is the result not an oval? Anyting else?

 

Better look up all available properties of object Oval in DOM documentation:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Oval.html

 

Regards,
Uwe Laubender

( ACP )

 

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 ,
Feb 17, 2020 Feb 17, 2020

Hi Uwe,

 

You and Rob are correct.

I've fixed it now. 

 

Thank you for your help,

 

Antoine

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 ,
Feb 21, 2020 Feb 21, 2020
LATEST

OMG You are spoiling me haahaha 🙂 Thanks Rob.

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