Created
November 6, 2015 18:11
-
-
Save 3200creative/5549f1689ad3d0a9bbdd to your computer and use it in GitHub Desktop.
C4D COFFEE script - Attach Object By Spline [add coffee script to spline with child objects]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main(doc,op) | |
{ | |
var i, j, k, pointcount; | |
i = 0; | |
var a = op->GetDown();//count number of children | |
while(a != NULL){ | |
a = a->GetNext(); | |
i++; | |
} | |
//allocate array for coordinates | |
pointcount = i; | |
var pointadr = new(array, pointcount); | |
a = op->GetDown(); | |
pointadr[0] = a->GetPosition(); | |
for(i = 1; i<pointcount; i++){//get coordinates of children | |
a = a->GetNext(); | |
pointadr[i] = a->GetPosition(); | |
} | |
k = 0;//count number of splines needed | |
for(i = 0; i<pointcount-1; i++){ | |
for(j = i; j<pointcount-1; j++){ | |
k++; | |
} | |
} | |
var vc = new(VariableChanged); | |
vc->Init(pointcount, k*2);//allocate points | |
op->Message(MSG_POINTS_CHANGED, vc); | |
vc->Init(op->GetSegmentCount(), k);//allocate segments | |
op->Message(MSG_SEGMENTS_CHANGED, vc); | |
print(k," "); | |
var gg = op->GetSegmentCount(); | |
print(gg, " "); | |
var segmentcount = new(array, k); | |
for(i = 0; i < k; i++){ | |
segmentcount[i] = 2; | |
} | |
print(segmentcount[3], " "); | |
print(op->SetSegments(segmentcount), " ");//assign 2 points per segment | |
println(op->GetSegmentCount()); | |
k = 0;// generate point pairs | |
for(i = 0; i < pointcount; i++){ | |
for(j = i; j < pointcount-1; j++){ | |
op->SetPoint(k, pointadr[i]); | |
k++; | |
op->SetPoint(k, pointadr[j+1]); | |
k++; | |
} | |
} | |
op->Message(MSG_UPDATE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment