# Form and Space

## creating CG 3D since 2001

• Connect @
• Vimeo

#### Segment Curve

Matthew | May 31, 2010

1 Comment

This script will segment an entire curve from knot to knot. I needed something like this tool for my current project. I found this most useful for linear curves, but I added the code to segment a CV curve, as well.

``````
/**************************
Segment Curve Knot to Knot

Format: Jscript
Author: Matthew L. Stoehr
Source: formandspace.com

SEGMENTS A CURVE FROM KNOT TO KNOT

**********************************/

var oSel = Application.Selection(0);

if(oSel.Type != "crvlist")
{
fTrace("Select a curve");
}
else
{
if(Application.Selection.Count > 1)
{
fTrace("Select only one curve.");
}
else
{
fSegmentCurve(oSel);
}
}

/*-------------------------

FUNCTIONS

---------------------------*/

function fTrace(m){
Application.LogMessage(m);
}

function fSegmentCurve(oSel){
var oSelName = oSel.FullName;
var oType = oSel.Type;
var oGeometry = oSel.ActivePrimitive.Geometry;
var oNumKnots = oGeometry.Curves(0).Knots.Count;

fTrace(oNumKnots + " - Knots");

//FOR CUBIC CURVES - DEGREE 3
if(oGeometry.Curves(0).Degree == 3){
fTrace(oSelName + " is a cubic cv curve.")

for(i=0; i < oNumKnots-1; i++)
{
//SKIP FIRST THREE KNOTS & LAST THREE KNOTS
if(i < oNumKnots-5){
ApplyGenOp("CrvExtractSeg", "", oSelName +".knot[" +i+ ","+ (i+1) +" ];"+ oSelName +".knot["+ (i+1) +"]");
}
}
}

//FOR LINEAR CURVES - DEGREE 1
if(oGeometry.Curves(0).Degree == 1){
fTrace(oSelName + " is a linear curve.")

for(i=0; i < oNumKnots-1; i++)
{
ApplyGenOp("CrvExtractSeg", "", oSelName +".knot[" +i+ ","+ (i+1) +" ];"+ oSelName +".knot["+ (i+1) +"]");
}
}
}
``````

### One response to “Segment Curve”

1. Matthew says:

Updated.

396