Skip to main content
Participating Frequently
October 13, 2021
Answered

Scissors tool via script

  • October 13, 2021
  • 7 replies
  • 606 views

I need to create a half circle and I think the best way is with the scissors tool. The problem is when I want to do it via script. I can't find anything that can guide me.

 

Thank you very much.

This topic has been closed for replies.
Correct answer Laubender

Alright, we can even get an [object Polygon] when we are using the result of the subtractPath() method as a blueprint:

 

var doc = app.documents.add();


/*
	Create a "circle"-like oval on the page.
	Why "circle"-like? See:
	
	A Primer on Bézier Curves
	§42 Circular arcs and cubic Béziers
	https://pomax.github.io/bezierinfo/#circles_cubic
	
*/

var oval = doc.spreads[0].ovals.add
(
	{
		geometricBounds : [ 0, 0, 100, 100 ] ,
		strokeWeight : 0 ,
		strokeColor : "None" ,
		fillColor : "None"
	}
);

/*
	Create a rectangle that overlaps the oval:
*/

var rectangle = doc.spreads[0].rectangles.add
(
	{
		geometricBounds : [ -10, 50, 110, 110 ] ,
		strokeWeight : 0 ,
		strokeColor : "None" ,
		fillColor : "None"
	}
);

// Use substractPath() method.
// ISSUE: The returned object is still of type [object Oval]
var bluePrint = rectangle.subtractPath
( 
	[ oval ]
);

// We could correct that by adding a polygon 
// and clone the entirePath of the result, the bluePrint, to the polygon:
var polygon = doc.spreads[0].polygons.add
(
	{
			strokeWeight : 0 ,
			strokeColor : "None" ,
			fillColor : "None"
	}
);

polygon.paths[0].entirePath = bluePrint.paths[0].entirePath;

//The blueprint is not needed anymore:
bluePrint.remove();

 

Regards,
Uwe Laubender

( ACP )

7 replies

Participating Frequently
October 14, 2021

Thank you very much Uwe. I think that with the ideas you have given me, I can "play" quite a lot.

Peter Kahrel
Community Expert
Community Expert
October 13, 2021

Nice musings, Uwe. But what's dumb about the pathfinder tools?

 

P.

Community Expert
October 13, 2021

Hi Peter,

ok, that was an exaggeration…

 

I had this other thread in mind where the high art of constructing an arc is discussed.

Nice, that there is someone who's commenting my musings; and that the one is you.

 

Regards,
Uwe Laubender

( ACP )

Community Expert
October 13, 2021

Hm. Now it dawns on me, that you want to create not a closed path, but an open path of a half circle

If I'm right just add this code at the bottom of the code above:

 

/*
	Let's simulate the sciccors tool a bit:
	Add a path point
	Open the path
	Remove the added path point.
*/
var newPathPoint = polygon.paths[0].pathPoints.add
(
	{
		anchor : [ 50 , 50] ,
		pointType : PointType.PLAIN
	}
);


polygon.paths[0].pathType = PathType.OPEN_PATH;
newPathPoint.remove();

polygon.strokeWeight = 1;

 

The final result is this:

 

 

 

Regards,
Uwe Laubender

( ACP )

LaubenderCommunity ExpertCorrect answer
Community Expert
October 13, 2021

Alright, we can even get an [object Polygon] when we are using the result of the subtractPath() method as a blueprint:

 

var doc = app.documents.add();


/*
	Create a "circle"-like oval on the page.
	Why "circle"-like? See:
	
	A Primer on Bézier Curves
	§42 Circular arcs and cubic Béziers
	https://pomax.github.io/bezierinfo/#circles_cubic
	
*/

var oval = doc.spreads[0].ovals.add
(
	{
		geometricBounds : [ 0, 0, 100, 100 ] ,
		strokeWeight : 0 ,
		strokeColor : "None" ,
		fillColor : "None"
	}
);

/*
	Create a rectangle that overlaps the oval:
*/

var rectangle = doc.spreads[0].rectangles.add
(
	{
		geometricBounds : [ -10, 50, 110, 110 ] ,
		strokeWeight : 0 ,
		strokeColor : "None" ,
		fillColor : "None"
	}
);

// Use substractPath() method.
// ISSUE: The returned object is still of type [object Oval]
var bluePrint = rectangle.subtractPath
( 
	[ oval ]
);

// We could correct that by adding a polygon 
// and clone the entirePath of the result, the bluePrint, to the polygon:
var polygon = doc.spreads[0].polygons.add
(
	{
			strokeWeight : 0 ,
			strokeColor : "None" ,
			fillColor : "None"
	}
);

polygon.paths[0].entirePath = bluePrint.paths[0].entirePath;

//The blueprint is not needed anymore:
bluePrint.remove();

 

Regards,
Uwe Laubender

( ACP )

Community Expert
October 13, 2021

And finally we have the "dumb" methods of the pathfinder tools. Also with scripting:

 

 

var doc = app.documents.add();


/*
	Create a "circle"-like oval on the page.
	Why "circle"-like? See:
	
	A Primer on Bézier Curves
	§42 Circular arcs and cubic Béziers
	https://pomax.github.io/bezierinfo/#circles_cubic
	
*/

var oval = doc.spreads[0].ovals.add
(
	{
		geometricBounds : [ 0, 0, 100, 100 ] ,
		strokeWeight : 0 ,
		strokeColor : "None" ,
		fillColor : "None"
	}
);

/*
	Create a rectangle that overlaps the oval:
*/

var rectangle = doc.spreads[0].rectangles.add
(
	{
		geometricBounds : [ -10, 50, 110, 110 ] ,
		strokeWeight : 0 ,
		strokeColor : "None" ,
		fillColor : "None"
	}
);

// Use substractPath() method:
rectangle.subtractPath
( 
	[ oval ]
);

 

 

The next step would be to move the resulting item and to scale it.

BUT NOTE: The result is still a [object Oval] which exposes other issues that are discussed elsewhere in the forum. You may have expected a [object Polygon] perhaps…

 

Regards,
Uwe Laubender

( ACP )

Community Expert
October 13, 2021

Also this:

 

A Primer on Bézier Curves
§42 Circular arcs and cubic Béziers

https://pomax.github.io/bezierinfo/#circles_cubic

 

Regards,
Uwe Laubender

( ACP )

Community Expert
October 13, 2021

Hi Fernando,

see into this discussion from 2015:

 

What is the direction of the curve points returned by entirePath()? [See description for details]
ajaatshatru, Oct 12, 2015
https://community.adobe.com/t5/indesign-discussions/what-is-the-direction-of-the-curve-points-returned-by-entirepath-see-description-for-details/m-p/7612096#M203951

 

Regards,
Uwe Laubender

( ACP )