Skip to main content
Participating Frequently
Oct 13, 2021 3:01 PM UTC
Answered

Scissors tool via script

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 is closed to new replies. Start a new post to keep the conversation going.
LaubenderCorrect answer
Community Expert
Oct 13, 2021 7:22 PM UTC

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 )

8 replies

Participating Frequently
Oct 14, 2021 6:50 AM UTC

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

Translate
Peter Kahrel
Community Expert
Community Expert
Oct 13, 2021 8:32 PM UTC

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

 

P.

Translate
Community Expert
Oct 13, 2021 8:42 PM UTC

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 )

Translate
Community Expert
Oct 13, 2021 8:22 PM UTC

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 )

Translate
LaubenderCommunity ExpertCorrect answer
Community Expert
Oct 13, 2021 7:22 PM UTC

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 )

Translate
Community Expert
Oct 13, 2021 6:28 PM UTC

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 )

Translate
Community Expert
Oct 13, 2021 6:09 PM UTC

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 )

Translate
Community Expert
Oct 13, 2021 5:49 PM UTC

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 )

Translate