PDA

View Full Version : Cinema 4d Scripts


JoelD
10-28-2005, 04:15 PM
Users--please post your scripts here


--------------------------------------
From c)hri:
UserScript: AO multipass helper

http://forums.cgsociety.org/showthread.php?t=289429




-----------------

hi folks,

I played around with the new script manager and wrote a short script which should help to improve the AO multipass workflow a bit.
The script walks through all materials in the scene, disables all channels except of the luminance channel. The luminance channel is filled with a plain white color.
So the multipass workflow looks like that:
* run the script
* disable all lights in the scene

copy-paste the script code into the script manager, assign a script name. save it. script can be called via the Plugin menu -> user scripts

Be aware that previous material settings will be lost, its a one-way-ticket. It don't works for the old shaders like danel, etc.
Material updates are'nt displayed immediately (coders: help!)

I know the script is far from being perfect, but hey: it's my first one (for c4d)



---------------------------------
vistitMaterial(op) {
if (op == null) return;
// enable luminance
var lum = op->GetChannel(CHANNEL_LUMINANCE);
if (lum) {
var bc = new(BaseContainer);
bc->SetData(CH_BRIGHTNESS,1);
bc->SetData(CH_COLOR, vector(1.0,1.0,1.0));
bc->SetData(CH_MIXMODE,0);
bc->SetData(CH_MIXSTRENGTH,0);
lum->SetContainer(bc);
op->SetChannelState(CHANNEL_LUMINANCE, true);
}
// disable other channels
op->SetChannelState(CHANNEL_COLOR, false);
op->SetChannelState(CHANNEL_TRANSPARENCY, false);
op->SetChannelState(CHANNEL_REFLECTION, false);
op->SetChannelState(CHANNEL_ENVIRONMENT, false);
op->SetChannelState(CHANNEL_FOG, false);
op->SetChannelState(CHANNEL_SPECULAR, false);
op->SetChannelState(CHANNEL_SPECULARCOLOR, false);
op->SetChannelState(CHANNEL_GLOW, false);
op->SetChannelState(CHANNEL_DIFFUSION, false);
op->Update();
vistitMaterial(op->GetNext());
}

main(doc, op){
vistitMaterial(doc->GetFirstMaterial());
}
---------------------------------

JoelD
10-28-2005, 04:17 PM
http://forums.cgsociety.org/showthread.php?t=288976

From Mdme sadie

Use the attached Script (just unzip it in your library/scripts folder, then drag & drop it into your interface/assign it a keyboard shortcut, or access it via the plugins->Scripts menu).

To use : select the object that will be instanced, then run the script. Enter the starting part of the objects names that will be turned into instances, e.g. if you have a bunch of objects called Screw_1 Screw_2 Screw_3... etc then just enter Screw in the dialog. if the object you've got selected is the first name you want to use then just click ok with an empty text box.

Attachment below

http://forums.cgsociety.org/attachment.php?attachmentid=83476

JoelD
10-28-2005, 04:21 PM
From Geespot:

Here's a simple 9.5 script

Just add it to the Script Manager, select a parent object and execute the script the usual method.

// Get the active object
var op = doc->GetActiveObject();
if(!op) return;

// De-select all objects first
CallCommand(12113);

// Percentage 0.0 = 0%, 1.0 is 100%
var perc = 0.5;

// Get te first child object of active object
var child = op->GetDown();

// Start random generator
var r = new(Random);
r->Init(GeGetSysTime()->second);
var n;

// Count the children
while(child)
{
// Generate a number between 0.0 and 1.0
n = r->Get01();

// Is this number less than our percentage?
if(n < perc)
{
// Select object
child->SetBit(BIT_AOBJ);
// Update object
child->Message(MSG_UPDATE);
}

// Move onto next object
child = child->GetNext();

}

// Update document
doc->Message(MSG_UPDATE);

JoelD
10-28-2005, 04:22 PM
//--------------------------
//recursive select routine
Rselect(op,rnd) {
//randomly select (make active or not)
if (rnd->Get11()>0.0) op->SetBit(BIT_AOBJ);
else op->DelBit(BIT_AOBJ);

//recurse through hierarchy
var nchild=op;
for (nchild=nchild->GetDown();nchild;nchild=nchild->GetNext()) Rselect(nchild,rnd);
}

//--------------------------
//main function routine
main(doc,op) {
var child=op->GetDown();
var random_seed=123456;
var rnd=new(Random);
//init random number generator with seed
rnd->Init(random_seed);

for (child=op->GetDown();child;child=child->GetNext()) Rselect(child,rnd);

return TRUE;
}

c-hri
10-29-2005, 01:39 PM
ok, here's my next.

inspired by the boring clean up and grouping process after importing a 3ds files. I don't know about the other apps, but for instance ArchiCad creates kinda cryptic object names without any hierarchy.

The script is called TidyUp:
It groups root level objects by their texture tags. I have successfully tested it with several archicad generated 3ds files.
Example: all objects with a brick material applied get grouped together in a new top-level-group called 'brick' (group name = material name).

Unzip the file into your library/scripts directory.

cheers,
c)hri

c-hri
11-01-2005, 03:59 PM
hi all,

here's my new one, it's called: RenameChildren. I wrote it because I had troubles using mdm_ sadies fine Convert To Instance script in a recent project (unsorted, cryptic object names everywhere; again a .3ds import).

The attached script renames all children of the selected parent object:
Eg. Parent is called Wall => the children will be renamed to wall_1, wall_2 etc etc

There's also an updated version of my TidyUp script attached. Both scripts take care of undo/redo commands now.

cheers
c)hri

Neldor
11-15-2005, 07:58 AM
Hi! This is my simple script.


var bc=new(BaseContainer);
bc->SetData(MDATA_EXTRUDE_OFFSET, 0);
bc->SetData(MDATA_EXTRUDE_SUBDIVISION, 0);
bc->SetData(MDATA_EXTRUDE_PRESERVEGROUPS, TRUE);
bc->SetData(MDATA_EXTRUDE_CREATECAPS, FALSE);
SendModelingCommand(ID_MODELING_EXTRUDE_TOOL, doc, op, bc, MODIFY_POLYGONSELECTION);


Works only witn poly at this moment.

c-hri
12-30-2005, 10:11 AM
hi folks,

here's a simple 'material replacer' user script. Unzip the file into your library/scripts directory.

Usage:
*Activate exactly one material (this will gonna be the new material)
*Select one or more objects
* Run the script: all texture tags of the selected objects (including all children) will have the new material applied.


cheers
c)hri

Per-Anders
01-19-2006, 06:04 AM
Script for setting a texture tag on a spotlight to teh right size/projection to cover the spotlight itself (just place in a coffee tag on a spotlight)


GetTextureTag(op)
{
if (!op) return NULL;

var tag=op->GetFirstTag();
if (!tag) return NULL;

while (tag) {
if (tag->IsInstanceOf(Ttexture)) return tag;
tag=tag->GetNext();
}

return NULL;
}


main(doc,op)
{
var tag=GetTextureTag(op);
if (!tag) return FALSE;

var lang=op#LIGHT_DETAILS_OUTERANGLE;

var coveragey=(lang/PI2);
var coveragex=coveragey*0.5;

var offx=0.25+coveragex;
var offy=0.5-coveragey;

var leny=coveragey*2;
var lenx=-coveragex*2;

tag#TEXTURETAG_OFFSETX=offx;
tag#TEXTURETAG_OFFSETY=offy;
tag#TEXTURETAG_LENGTHX=lenx;
tag#TEXTURETAG_LENGTHY=leny;
}

Sneaker
03-08-2006, 12:33 PM
Hi,

I just played arround with user scripts and want to offer my result.

FullSplit performs a split, deletes the selected polygons and removes
unnesessary points using optimize.



-Sneaker

Sneaker
03-08-2006, 02:58 PM
The split function usually creates a new object from your polygon selection
leaving the orignal object in takt.
If you want to break one object into 2 parts you have additional work to remove
poligons and points from the original object.
That is what the script does for you.

-Sneaker

Per-Anders
03-15-2006, 09:27 PM
Rhis is a useful little script to allow you to lock out objects from being selectable in the OM. Just put this in a COFFEE tag on the object you want to protect. All it does is check the objects selected bit(GetBit), then if it's set it switches it off (DelBit) it and forces cinema to redraw it's interface (EventAdd).


main(doc,op)
{
if(op->GetBit(BIT_AOBJ))
{
op->DelBit(BIT_AOBJ);
EventAdd();
}
}

tcastudios
06-14-2006, 09:52 PM
Gathered 20 of my scripts for checking out. They all only make sense if placed in your layout to speed many things up.

Dload here (http://homepage.mac.com/tcastudios/xfiles.html)
http://homepage.mac.com/tcastudios/tcaxpresso/20scripts.jpg

Cheers
Lennart

tcastudios
06-22-2006, 10:42 PM
This one makes a instance but place it right below the source instead of the top of OM.

Cheers
Lennart

otomo
08-15-2006, 09:16 AM
this is a little script written by Frank Berg and me which saves you a few mouseclicks.

it will connect the selected objects, using the connect command, put the result in the same branch, just above the first selected object and delete the original objects.


http://forums.cgsociety.org/showthread.php?t=393322



edit: uploaded an updated version, fixed some issues, like deleting didnt work if not in object mode and other minor things. only thing left: undo the script actions in one step.

Geespot
10-13-2006, 01:13 PM
Group Connect
---------------

Group Connect is a script that will convert an object and all its children into a single polygon mesh.


// Group Connect v1.0
// -------------------
// Group Connect is a script that will convert a grouped selection
// of objects into a single polygon mesh including materials
// using Selection Tags to assign each polygon a seperate texture.
//
// Created by Ian Gorse 12 October 2006
// http://www.iangorse.co.uk/
// Recursive method to create a selection tag for each object
// ==========================================================
// child: The current object in hiearchy
CreateSelection(child)
{

while(child)
{
child->SetBit(BIT_AOBJ); // Select the object
CallCommand(13323); // Select All polygons
// Only create a selection tag if this object has polygons
if(child->GetType()==Opolygon)
{
// Creates a selection tag for this object
// It names the selection tag the same name as the object
var selection = new(BaseSelect);
selection = child->GetPolygonSelection();
var tag = new(PolygonSelectionTag);
tag->SetSelection(selection);
tag->SetName(child->GetName());
child->InsertTag(tag);
}
CallCommand(13324); // Deselect all polygons
child->DelBit(BIT_AOBJ); // Deselect the object
CreateSelection(child->GetDown());
child=child->GetNext();
}
}
// Just a method to start the selection creation process
// Its on its own function because I had other plans, but I made a workaround with a Hack (below)
StartSelectionProcess(op)
{
CreateSelection(op);
}
// Attempts to find a texture tag on the passed object
// If it doesn't find one, it will check its parents object
// and use that instead
// ==========================================================
// op: The object to check for a texture tag
FindTextureTag(op)
{
if(!op) return NULL;
// Search for a texture tag on this object
var tag = op->GetFirstTag();
var searching = TRUE;
var returntag;
while(tag && searching)
{
if(tag->GetType()==Ttexture)
{
// Found a texture tag
returntag = tag;
searching=FALSE;
}
tag=tag->GetNext();
}
// Could not find Texture Tag, attempt to find inherited texture tag
if(!returntag)
{
returntag = FindTextureTag(op->GetUp());
}
return returntag;
}
// Recursive method to find texture tags on each object
// =====================================================
// op: The object to apply the texture onto
// child: The selected object and its children
CreateMaterial(op,child)
{
while(child)
{

// Search for a texture tag on this object
var tag = FindTextureTag(child);

if(tag)
{
// Make a copy
var newtag = tag->GetClone();
newtag#TEXTURETAG_RESTRICTION=child->GetName();
op->InsertTag(newtag);
}
CreateMaterial(op,child->GetDown());
child=child->GetNext();
}
}
main(doc,op)
{
// Cals the Current State To Object command on the selected object
var bc = new(BaseContainer);
SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, doc, op, bc, MODIFY_ALL);
// The new editable object is automatically added to the document.
// Keep track of it here so I can remove it later
var newop = doc->GetActiveObject();
// Make sure the polygon tool is selected
CallCommand(12187);
// Start the polygon selection process
newop->DelBit(BIT_AOBJ); // De-select the cloned object first
StartSelectionProcess(newop);
newop->SetBit(BIT_AOBJ);
// HACK -- To avoid any hierarchy issues, Im just grouping everything up
// -- I'm taking advantage that the Connect command returns a polygon object only
var nullop = new(NullObject);
nullop->SetName(newop->GetName());
doc->InsertObject(nullop,NULL,NULL);

// Move the current state to object under the null objet
newop->Remove();
newop->InsertUnder(nullop);
// Select the nullobject
nullop->SetBit(BIT_AOBJ);

// Creates a texture tag for each polygon selection
CreateMaterial(nullop,op);
CallCommand(16388); // Select Children
CallCommand(12144); // Connect
// Remove the new grouped object
nullop->Remove();
}


Example:
Original model
http://i6.photobucket.com/albums/y211/Unigee/groupconnect_orig.jpg

GroupConnected object
http://i6.photobucket.com/albums/y211/Unigee/groupconnect_result.jpg

Download the Instructions (http://www.iangorse.co.uk/scripts/groupconnect/groupconnect.pdf) for its installation usage

Geespot
10-27-2006, 03:46 PM
AngleSelect is a script that will select all polygons within an user defined angle. With it, its possible to select all polygons above/below and between two set angles.

Click the attachment to download.

How to install:
Extract the zip file into your Cinema4D/library/scripts folder

The script will then be available in the C4D Script Manager

benytone
10-28-2006, 10:00 AM
many many thanks Geespot http://www.cheesebuerger.de/images/smilie/liebe/g106.gif



.

Per-Anders
01-17-2007, 10:21 PM
FindActiveType(doc, op, type)
{
while (op)
{
if (op->GetBit(BIT_ACTIVE))
if (op->IsInstanceOf(type)) return op;

if (op->GetDown())
{
op = op->GetDown();
}
else
{
while (!op->GetNext())
{
op = op->GetUp();
}
if (op) op = op->GetNext();
}
}
return NULL;
}

main(doc, op)
{
var data = new(BaseContainer);
data->SetData(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);

var spline = FindActiveType(doc, doc->GetFirstObject(), Ospline);
if (spline == NULL) return;
var poly = FindActiveType(doc, doc->GetFirstObject(), Opolygon);
if (poly == NULL) return;

var pspline = spline->GetPrev();
var uspline = spline->GetUp();
var ppoly = poly->GetPrev();
var upoly = poly->GetUp();

doc->StartUndo();

var boole =AllocObject(Oboole);
doc->InsertObject(boole, NULL, NULL);
if (!boole) return;
doc->AddUndo(UNDO_NEW, boole);

var extrude = AllocObject(Oextrude);
if (!extrude) return;
doc->InsertObject(extrude, boole, NULL);
doc->AddUndo(UNDO_NEW, extrude);

var cam = doc->GetActiveBaseDraw()#BASEDRAW_DATA_CAMERA;
if (!cam) return;

var smg = spline->GetMg();
extrude->SetMg(smg);

doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
spline->InsertUnder(extrude);

spline->SetPosition(vector(0.0,0.0,0.0));
spline->SetRotation(vector(0.0,0.0,0.0));
spline->SetScale(vector(1.0,1.0,1.0));

extrude#EXTRUDEOBJECT_MOVE:VECTOR_Z = 100000.0;
extrude#CAP_START = 0;
extrude#CAP_END = 0;

boole#BOOLEOBJECT_TYPE = BOOLEOBJECT_TYPE_WITHOUT;
boole#BOOLEOBJECT_HIGHQUALiTY = TRUE;
boole#BOOLEOBJECT_HIDE_NEW_EDGES = TRUE;

doc->AddUndo(UNDO_CHANGE, poly);
poly->Remove();
poly->InsertUnder(boole);

if ( !SendModelingCommand( MCOMMAND_CURRENTSTATETOOBJEC T, doc, boole, data, MODIFY_ALL)) return;

var newobj = doc->GetActiveObject();
var newchl = newobj->GetDown();

doc->AddUndo(UNDO_NEW, newobj);
if (uspline == poly) uspline = newchl;
if (pspline == poly) pspline = newchl;
if (upoly == spline || ppoly == spline)
{
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
}
else
{
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
}
doc->AddUndo(UNDO_CHANGE, spline);
spline->SetMg(smg);

doc->AddUndo(UNDO_DELETE, poly);
poly->Remove();
doc->AddUndo(UNDO_DELETE, extrude);
extrude->Remove();
doc->AddUndo(UNDO_DELETE, boole);
boole->Remove();
doc->AddUndo(UNDO_DELETE, newobj);
newobj->Remove();

doc->EndUndo();
}

Simply allows you to project cut an editiable polygonal mesh using a spline. Select both the spline and the polygonal object and run this script. Make sure that the spline is betwene your obejct and the camera as it cuts in a projection from the splines current position, so everything behind the spline will get cut, but nothing in front of the spline.

Per-Anders
01-17-2007, 11:09 PM
And here's a version that projects along the camera normal rather than the splines own axis :

FindActiveType(doc, op, type)
{
while (op)
{
if (op->GetBit(BIT_ACTIVE))
if (op->IsInstanceOf(type)) return op;

if (op->GetDown())
{
op = op->GetDown();
}
else
{
while (!op->GetNext())
{
op = op->GetUp();
}
if (op) op = op->GetNext();
}
}
return NULL;
}

main(doc, op)
{
var data = new(BaseContainer);
data->SetData(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);

var spline = FindActiveType(doc, doc->GetFirstObject(), Ospline);
if (spline == NULL) return;
var poly = FindActiveType(doc, doc->GetFirstObject(), Opolygon);
if (poly == NULL) return;

var pspline = spline->GetPrev();
var uspline = spline->GetUp();
var ppoly = poly->GetPrev();
var upoly = poly->GetUp();

doc->StartUndo();

var boole =AllocObject(Oboole);
doc->InsertObject(boole, NULL, NULL);
if (!boole) return;
doc->AddUndo(UNDO_NEW, boole);

var extrude = AllocObject(Oextrude);
if (!extrude) return;
doc->InsertObject(extrude, boole, NULL);
doc->AddUndo(UNDO_NEW, extrude);

var cam = doc->GetActiveBaseDraw()#BASEDRAW_DATA_CAMERA;
if (!cam) return;

var smg = spline->GetMg();
extrude->SetMg(cam->GetMg());

doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
spline->InsertUnder(extrude);

spline->SetMg(smg);

extrude#EXTRUDEOBJECT_MOVE:VECTOR_Z = 100000.0;
extrude#CAP_START = 0;
extrude#CAP_END = 0;

boole#BOOLEOBJECT_TYPE = BOOLEOBJECT_TYPE_WITHOUT;
boole#BOOLEOBJECT_HIGHQUALiTY = TRUE;
boole#BOOLEOBJECT_HIDE_NEW_EDGES = TRUE;

doc->AddUndo(UNDO_CHANGE, poly);
poly->Remove();
poly->InsertUnder(boole);

if ( !SendModelingCommand( MCOMMAND_CURRENTSTATETOOBJECT, doc, boole, data, MODIFY_ALL)) return;

var newobj = doc->GetActiveObject();
var newchl = newobj->GetDown();

doc->AddUndo(UNDO_NEW, newobj);
if (uspline == poly) uspline = newchl;
if (pspline == poly) pspline = newchl;
if (upoly == spline || ppoly == spline)
{
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
}
else
{
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
}
doc->AddUndo(UNDO_CHANGE, spline);
spline->SetMg(smg);

doc->AddUndo(UNDO_DELETE, poly);
poly->Remove();
doc->AddUndo(UNDO_DELETE, extrude);
extrude->Remove();
doc->AddUndo(UNDO_DELETE, boole);
boole->Remove();
doc->AddUndo(UNDO_DELETE, newobj);
newobj->Remove();

doc->EndUndo();
}

MrBraun
01-18-2007, 08:02 AM
Great script !!

Tnx Per-Anders!! :thumbsup:

Darter
01-18-2007, 09:56 AM
Yes, I've wanted this functionality in C4D with a single-click since migrating across from LightWave.

And with a minor tweak, the script works with object and spline primitives...

Per-Anders
04-01-2007, 09:03 PM
This script allows you to select selection tags if their selection overlaps the selection you have made. Works on polygon selection tags only (can be modified to work on point selection tags too).

Use in the Script Manager.

To use : Make a polygon selection, then execute the script to select any polygon selection tags on your object that overlap your selection (quick way to find the right polygon selection tag on an object for a specific area).

var sel = op->GetPolygonSelection();
var cnt = sel->GetCount();
var ar = new(array, cnt);
var vcnt = op->GetPolygonCount();
var i = 0, o = 0;
for (i = 0; i < vcnt ; i++)
{
if (sel->IsSelected(i))
{
ar[o] = i;
o++;
}
}

var tag = op->GetFirstTag();
while (tag)
{
tag->DelBit(BIT_ACTIVE);
if (tag->IsInstanceOf(Tpolygonselection))
{
var tsel = tag->GetSelection();
for (i = 0; i < cnt ; i++)
{
if (tsel->IsSelected(ar[i]))
{
tag->SetBit(BIT_ACTIVE);
break;
}
}
}
tag = tag->GetNext();
}

soccerrprp
04-02-2007, 12:14 PM
Cool script- Spline Cut! Thanks!

Per-Anders
04-02-2007, 07:31 PM
Just select several objects and this will instance them all in one go.

op = doc->GetFirstObject();
var instance = op;
var mynull = AllocObject(Onull);
while (op)
{
if (op->GetBit(BIT_ACTIVE))
{
instance = AllocObject(Oinstance);
instance#INSTANCEOBJECT_LINK = op;
instance->InsertUnder(mynull);
instance->SetMg(op->GetMg());
op->DelBit(BIT_ACTIVE);
}

if (op->GetDown())
{
op = op->GetDown();
}
else
{
while (!op->GetNext() && op->GetUp())
{
op = op->GetUp();
}
op = op->GetNext();
}
}

op = mynull->GetDown();

while(op)
{
instance = op;
op = op->GetNext();
instance->Remove();
doc->InsertObject(instance, NULL, NULL);
instance->SetBit(BIT_ACTIVE);
}

MJV
04-02-2007, 09:22 PM
This one makes a instance but place it right below the source instead of the top of OM.

Cheers
Lennart

The Add Instance Command in this script is wrong, causing the script to fail in 10.1. Is this due to a change in call command ID numbers since last year or was it always wrong and not noticed before despite 45 people having downloaded it?

MJV
04-02-2007, 09:49 PM
This script fails in 10.1


Group Connect
---------------

Group Connect is a script that will convert an object and all its children into a single polygon mesh.


// Group Connect v1.0
// -------------------
// Group Connect is a script that will convert a grouped selection
// of objects into a single polygon mesh including materials
// using Selection Tags to assign each polygon a seperate texture.
//
// Created by Ian Gorse 12 October 2006
// http://www.iangorse.co.uk/
// Recursive method to create a selection tag for each object
// ==========================================================
// child: The current object in hiearchy
CreateSelection(child)
{

while(child)
{
child->SetBit(BIT_AOBJ); // Select the object
CallCommand(13323); // Select All polygons
// Only create a selection tag if this object has polygons
if(child->GetType()==Opolygon)
{
// Creates a selection tag for this object
// It names the selection tag the same name as the object
var selection = new(BaseSelect);
selection = child->GetPolygonSelection();
var tag = new(PolygonSelectionTag);
tag->SetSelection(selection);
tag->SetName(child->GetName());
child->InsertTag(tag);
}
CallCommand(13324); // Deselect all polygons
child->DelBit(BIT_AOBJ); // Deselect the object
CreateSelection(child->GetDown());
child=child->GetNext();
}
}
// Just a method to start the selection creation process
// Its on its own function because I had other plans, but I made a workaround with a Hack (below)
StartSelectionProcess(op)
{
CreateSelection(op);
}
// Attempts to find a texture tag on the passed object
// If it doesn't find one, it will check its parents object
// and use that instead
// ==========================================================
// op: The object to check for a texture tag
FindTextureTag(op)
{
if(!op) return NULL;
// Search for a texture tag on this object
var tag = op->GetFirstTag();
var searching = TRUE;
var returntag;
while(tag && searching)
{
if(tag->GetType()==Ttexture)
{
// Found a texture tag
returntag = tag;
searching=FALSE;
}
tag=tag->GetNext();
}
// Could not find Texture Tag, attempt to find inherited texture tag
if(!returntag)
{
returntag = FindTextureTag(op->GetUp());
}
return returntag;
}
// Recursive method to find texture tags on each object
// =====================================================
// op: The object to apply the texture onto
// child: The selected object and its children
CreateMaterial(op,child)
{
while(child)
{

// Search for a texture tag on this object
var tag = FindTextureTag(child);

if(tag)
{
// Make a copy
var newtag = tag->GetClone();
newtag#TEXTURETAG_RESTRICTION=child->GetName();
op->InsertTag(newtag);
}
CreateMaterial(op,child->GetDown());
child=child->GetNext();
}
}
main(doc,op)
{
// Cals the Current State To Object command on the selected object
var bc = new(BaseContainer);
SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, doc, op, bc, MODIFY_ALL);
// The new editable object is automatically added to the document.
// Keep track of it here so I can remove it later
var newop = doc->GetActiveObject();
// Make sure the polygon tool is selected
CallCommand(12187);
// Start the polygon selection process
newop->DelBit(BIT_AOBJ); // De-select the cloned object first
StartSelectionProcess(newop);
newop->SetBit(BIT_AOBJ);
// HACK -- To avoid any hierarchy issues, Im just grouping everything up
// -- I'm taking advantage that the Connect command returns a polygon object only
var nullop = new(NullObject);
nullop->SetName(newop->GetName());
doc->InsertObject(nullop,NULL,NULL);

// Move the current state to object under the null objet
newop->Remove();
newop->InsertUnder(nullop);
// Select the nullobject
nullop->SetBit(BIT_AOBJ);

// Creates a texture tag for each polygon selection
CreateMaterial(nullop,op);
CallCommand(16388); // Select Children
CallCommand(12144); // Connect
// Remove the new grouped object
nullop->Remove();
}


Example:
Original model
http://i6.photobucket.com/albums/y211/Unigee/groupconnect_orig.jpg

GroupConnected object
http://i6.photobucket.com/albums/y211/Unigee/groupconnect_result.jpg

Download the Instructions (http://www.iangorse.co.uk/scripts/groupconnect/groupconnect.pdf) for its installation usage

marcorabellini
04-07-2007, 02:56 AM
I modified this script to add the name of the original plus a "[i]" to the end of the name. I actually didn't do to much coding myself but used a couple scripts I downloaded from here. One was from Per and I don't know who did the other one. (Sorry). I've commented the two lines I added. I'm not a coder by any stretch so if there's a way to make this any better I have no idea. It seems to be working for me in 10.1.
Select an object and run this script. That's it.

op = doc->GetFirstObject();
var instance = op;
var mynull = AllocObject(Onull);
var objectname=GetActiveDocument()->GetActiveObject()->GetName(); //get the original object name
while (op)
{
if (op->GetBit(BIT_ACTIVE))
{
instance = AllocObject(Oinstance);
instance#INSTANCEOBJECT_LINK = op;
instance->InsertUnder(mynull);
instance->SetMg(op->GetMg());
op->DelBit(BIT_ACTIVE);
}

if (op->GetDown())
{
op = op->GetDown();
}
else
{
while (!op->GetNext() && op->GetUp())
{
op = op->GetUp();
}
op = op->GetNext();
}
}

op = mynull->GetDown();

while(op)
{
instance = op;
op = op->GetNext();
instance->Remove();
doc->InsertObject(instance, NULL, NULL);
instance->SetBit(BIT_ACTIVE);
instance->SetName(objectname + " [i]"); //set the instance name to original +[i]
}

tcastudios
04-07-2007, 11:15 AM
The Add Instance Command in this script is wrong, causing the script to fail in 10.1. Is this due to a change in call command ID numbers since last year or was it always wrong and not noticed before despite 45 people having downloaded it?

Many CallCommands changed between R9 and R10.
Scripts I've posted are allmost all from R9.

Check the R10 version(s) of the commands and simply replace them.
Cheers
Lennart

tcastudios
04-07-2007, 12:30 PM
This script fails in 10.1

It works as it should here in 10.1.
The top parent must be a object thou and not a Null.

Cheers
Lennart

LucentDreams
04-11-2007, 07:39 AM
theres almost 30 here http://www.cineversity.com/tutorials/index.asp?cid=21

Two packages,

GRIP, camera and light management scripts
CONscripts, constraint creation and defaults scripts.

FrankBerg
04-11-2007, 02:50 PM
theres almost 30 here http://www.cineversity.com/tutorials/index.asp?cid=21

Two packages,

GRIP, camera and light management scripts
CONscripts, constraint creation and defaults scripts.

That's only $10,00 a script!!

Please don't take this the wrong way Kai, but isn't this thread for users sharing their scripts.

frank

LucentDreams
04-11-2007, 04:02 PM
none taken I can see where your coming from. Personally I think this thread is simply a resource for scripts, and I'm posting a link to a bunch. Yes you need a cineversity membership to download them, you also get the training on how to make them and edit them.

angeluSlo
04-11-2007, 10:59 PM
well can this scripts be copyrighted in any way at all?

Srek
04-12-2007, 06:49 AM
Scripts are just another type of code. By creating it the author automaticaly has the copyright.
However in most cases scripts are not unique / complex enough to warrant more rigid protection (patents etc.).
In the end you are not allowed to copy / spread scripts without the authors / right holders permission, but i think it's no problem that if you have them you can learn from them to create your own solutions.

Of course thats just my opinion on these matters, if you want a conclusive answer go to a specialised lawyer.

Cheers
Björn

otomo
08-17-2007, 07:33 AM
none taken I can see where your coming from. Personally I think this thread is simply a resource for scripts, and I'm posting a link to a bunch. Yes you need a cineversity membership to download them, you also get the training on how to make them and edit them.


No, I agree with Frank Berg. This should be a thread for script-sharing not script-selling.

birdy
08-31-2007, 07:07 AM
I can't get the "spline cut " script working on version 10.
Or maybe I am doing something wrong.

AkaKico
08-31-2007, 07:37 PM
I can't get the "spline cut " script working on version 10.
Or maybe I am doing something wrong.

Working fine with 10.111 for me, make sure the spline and poly object are make editable. Be sure to select both before running the script. Works best in "parallel" view.

Darter
01-01-2008, 06:51 AM
This script randomly applies materials to a polygon object. For each Texture Tag on the object, a Polygon Selection Tag is created and assigned a random selection of polygons.

Each tag has a unique selection, so no overlapping of textures occurs.

If you find this script useful, its companion Update Selection Tags (http://forums.cgsociety.org/showthread.php?f=182&t=576712) may also be of interest.

tcastudios
01-03-2008, 12:40 AM
Speedo prints the Velocity(Units and degrees per second) of a selected object.
To get velocity of other parameters use SetDriver/Driven to a Dummy Null
and use the script on the Null.
Velocity is calculated between the Start and End Frame of the Preview Range.

Cheers
Lennart

// Speedo by tcastudios©2008. For commercial and personal use.
// Re-distribution in any form is not allowed,
// but feel free to use any part of it for your own stuff.
// (If notonly to make it better:) )
// Speedo comes "as is" with no warranty in any form and without any
// personal support.
//
// Speedo is a script for Cinema4D versions having a scriptmanager and/or
// to be used in a Menu COFFEE setup.
// Copy and paste -all- text from top to bottom into the ScriptManager.
// Select an Object and run the SpeedoScript.
// Speedo prints the velocity of the active object in the Console.
// The average velocity is calcultated between the Start- and End Frame
// of the documents PreviewRange.
// For "One Frame" velocity, set Preview Range to two frames.
//
// Enjoy! Lennart Wåhlin tcastudios


var op = doc->GetActiveObject();
if(!op) return;

var a;
var ax;
var ay;
var az;
var ah;
var ap;
var ab;

var b;
var bx;
var by;
var bz;
var bh;
var bp;
var bb;

var fps = doc->GetFps();
var first = doc->GetLoopMinTime()->GetSecond()*fps;
var last = doc->GetLoopMaxTime()->GetSecond()*fps;
var keytokey = last-first;

var TimeNow = new(BaseTime);
TimeNow->SetFrame(first,fps);
doc->SetTime(TimeNow);
doc->AnimateDocument(ALL);
doc->Message(MSG_UPDATE);
a = op->GetMg()->GetV0();
var apos = op->GetPosition();
var arot = op->GetRotation();
ax = apos.x;
ay = apos.y;
az = apos.z;
ah = arot.x;
ap = arot.y;
ab = arot.z;

var TimeThen = new(BaseTime);
TimeThen->SetFrame(first+(last-first),fps);
doc->SetTime(TimeThen);
doc->AnimateDocument(ALL);
doc->Message(MSG_UPDATE);
b = op->GetMg()->GetV0();
var bpos = op->GetPosition();
var brot = op->GetRotation();
bx = bpos.x;
by = bpos.y;
bz = bpos.z;
bh = brot.x;
bp = brot.y;
bb = brot.z;

var dist = vlen(a-b);
var x = bx-ax;
var y = by-ay;
var z = bz-az;
var h = bh-ah;
var p = bp-ap;
var b = bb-ab;

TimeNow->SetFrame(first,fps);
doc->SetTime(TimeNow);
doc->AnimateDocument(ALL);
doc->MultiMessage(MSG_UPDATE);
var distsec = dist/(keytokey/fps);
var xsec = x /(keytokey/fps);
var ysec = y /(keytokey/fps);
var zsec = z /(keytokey/fps);
var hsec = Degree(h /(keytokey/fps));
var psec = Degree(p /(keytokey/fps));
var bsec = Degree(b /(keytokey/fps));
println("__________________________________________________");
println("Speed Between Frame ",int(first)," and ",int(last));
println("Velocity ",tostring(distsec,".2f")," Units/Sec");
println("X-Velocity ",tostring(xsec,".2f")," Units/Sec");
println("Y-Velocity ",tostring(ysec,".2f")," Units/Sec");
println("Z-Velocity ",tostring(zsec,".2f")," Units/Sec");
println("H-Rotation ",tostring(hsec,".2f")," Degrees/Sec");
println("P-Rotation ",tostring(psec,".2f")," Degrees/Sec");
println("B-Rotation ",tostring(bsec,".2f")," Degrees/Sec");
println("__________________________________________________");

Per-Anders
04-20-2008, 05:09 AM
Cinema normally only allows you to scale multiple objects with x+ whatever, this script allows you to size multiple selected objects with units, percent (relative to the largest object), and relative units (to the largest object).


getSize(op, dir, global)
{
var min = MAXREAL, max = MINREAL;

var i = 0;
var mg = op->GetMg();
if (!global) mg = new(Matrix);
var pcnt = op->GetPointCount();
var padr = op->GetPoints(), p, pv;
if (!padr) return 0.0;

switch (dir)
{
case 0: //x
{
for (i = pcnt - 1 ; i >= 0; --i)
{
pv = mg->GetMulP(padr[i]);
p = pv.x;
if (p < min) min = p;
if (p > max) max = p;
}
} break;
case 1: //y
{
for (i = pcnt - 1 ; i >= 0; --i)
{
pv = mg->GetMulP(padr[i]);
p = pv.y;
if (p < min) min = p;
if (p > max) max = p;
}
} break;
case 2: //z
{
for (i = pcnt - 1 ; i >= 0; --i)
{
pv = mg->GetMulP(padr[i]);
p = pv.z;
if (p < min) min = p;
if (p > max) max = p;
}
} break;
default: return FALSE; break;
}

return max - min;
}

scaleObject(op, amt, dir, scalepoints, global)
{
if (amt == 0.0) return FALSE;

var dist = getSize(op, dir, global);
if (dist == 0.0) return FALSE;

var ratio = (dist + amt) / dist;
if (!scalepoints) ratio = (dist * amt) / dist;

if (scalepoints)
{
//rescale all points
var i = 0;
var pcnt = op->GetPointCount();
var padr = op->GetPoints();
if (!padr) return FALSE;

switch (dir)
{
case 0:
{
for (i = pcnt - 1; i >= 0; --i) padr[i].x *= ratio;
} break;
case 1:
{
for (i = pcnt - 1; i >= 0; --i) padr[i].y *= ratio;
} break;
case 2:
{
for (i = pcnt - 1; i >= 0; --i) padr[i].z *= ratio;
} break;
default: return FALSE; break;
}

op->SetPoints(padr);
}
else
{
//set objects scale
var scl = op->GetScale();
switch (dir)
{
case 0: scl.x *= ratio; break;
case 1: scl.y *= ratio; break;
case 2: scl.z *= ratio; break;
default: return FALSE; break;
}

op->SetScale(scl);
}

return TRUE;
}

class ScaleAllDlg : GeModalDialog
{
public:
ScaleAllDlg();

var stored_x, stored_y, stored_z;

CreateLayout();
Command(id, msg);
}

ScaleAllDlg::ScaleAllDlg()
{
super();
}

ScaleAllDlg::CreateLayout()
{
SetTitle("Scale Units");

AddGroupBeginV(1000, BFH_SCALE|BFV_SCALE, 1, "", 0);
{
AddGroupBorder(BORDER_GROUP_IN);
AddGroupBorderSpace(4,4,4,4);
AddGroupSpace(4,4);

AddGroupBeginV(1001, BFH_SCALE|BFV_SCALE, 2, "", 0);
{
AddStaticText(1002, BFH_LEFT, 0,0, "X", 0);
AddEditNumberArrows(2000, BFH_SCALE, 80, 0);

AddStaticText(1003, BFH_LEFT, 0,0, "Y", 0);
AddEditNumberArrows(2001, BFH_SCALE, 80, 0);

AddStaticText(1004, BFH_LEFT, 0,0, "Z", 0);
AddEditNumberArrows(2002, BFH_SCALE, 80, 0);
}
AddGroupEnd();

AddComboBox(2005, BFH_SCALE|BFH_FIT, 0, 0);
AddItem(2005, 0, "Global");
AddItem(2005, 1, "Local");

AddComboBox(2003, BFH_SCALE|BFH_FIT, 0, 0);
AddItem(2003, 0, "Scale");
AddItem(2003, 1, "Size");
AddItem(2003, 2, "Size+");

AddButton(2004, BFH_SCALE|BFH_FIT, 0, 0, "Apply");

AddDlgGroup(DR_DLGGROUP_OK);
}
AddGroupEnd();

SetInt(2003, 0, 0, 3, 1);
SetPercent(2000, 100.0, MINREAL, MAXREAL, 0.01);
SetPercent(2001, 100.0, MINREAL, MAXREAL, 0.01);
SetPercent(2002, 100.0, MINREAL, MAXREAL, 0.01);

return;
}

ScaleAllDlg::Command(id, msg)
{
switch (id)
{
case 2005:
case 2003:
{
switch (GetInt(2003))
{
case 0:
{
SetPercent(2000, 100.0, MINREAL, MAXREAL, 0.01);
SetPercent(2001, 100.0, MINREAL, MAXREAL, 0.01);
SetPercent(2002, 100.0, MINREAL, MAXREAL, 0.01);
} break;
case 1:
{
var doc = GetActiveDocument(); if (!doc) return;
var op = doc->GetFirstObject(); if (!op) return;
var global = !GetInt(2005);
var xwid = 0.0, ywid = 0.0, zwid = 0.0;
while (op)
{
if (op->GetBit(BIT_ACTIVE))
{
var wid = getSize(op, 0, global);
if (wid > xwid) xwid = wid;
wid = getSize(op, 1, global);
if (wid > ywid) ywid = wid;
wid = getSize(op, 2, global);
if (wid > zwid) zwid = wid;
}

if (op->GetDown()) op = op->GetDown();
else
{
while (!op->GetNext() && op->GetUp()) op = op->GetUp();
op = op->GetNext();
}
}
SetMeter(2000, xwid, MINREAL, MAXREAL, 0.01);
SetMeter(2001, ywid, MINREAL, MAXREAL, 0.01);
SetMeter(2002, zwid, MINREAL, MAXREAL, 0.01);

stored_x = xwid;
stored_y = ywid;
stored_z = zwid;
} break;
case 2:
{
SetMeter(2000, 0.0, MINREAL, MAXREAL, 0.01);
SetMeter(2001, 0.0, MINREAL, MAXREAL, 0.01);
SetMeter(2002, 0.0, MINREAL, MAXREAL, 0.01);
} break;
default: break;
}
} break;
case 2004:
{
var doc = GetActiveDocument();
if (!doc) return;
var op = doc->GetFirstObject();
if (!op) return;

var global = !GetInt(2005);

var scl = vector(0.0, 0.0, 0.0);
var smode = FALSE;

switch (GetInt(2003))
{
case 0:
{
scl.x = GetFloat(2000);
scl.y = GetFloat(2001);
scl.z = GetFloat(2002);
smode = FALSE;
} break;
case 1:
{
scl.x = GetMeter(2000) - stored_x;
scl.y = GetMeter(2001) - stored_y;
scl.z = GetMeter(2002) - stored_z;
smode = TRUE;
} break;
case 2:
{
scl.x = GetMeter(2000);
scl.y = GetMeter(2001);
scl.z = GetMeter(2002);
smode = TRUE;
} break;
default: break;
}

while (op)
{
if (op->GetBit(BIT_ACTIVE))
{
doc->AddUndo(UNDO_CHANGE, op);
if ((smode && scl.x != 0.0) || (!smode && scl.x != 1.0)) scaleObject(op, scl.x, 0, smode, global);
if ((smode && scl.y != 0.0) || (!smode && scl.y != 1.0)) scaleObject(op, scl.y, 1, smode, global);
if ((smode && scl.z != 0.0) || (!smode && scl.z != 1.0)) scaleObject(op, scl.z, 2, smode, global);
op->Message(MSG_UPDATE);
}

if (op->GetDown()) op = op->GetDown();
else
{
while (!op->GetNext() && op->GetUp()) op = op->GetUp();
op = op->GetNext();
}
}
EventAdd();
DrawViews(DA_NO_THREAD);
} break;
default: break;
}
}


main(doc, op)
{
var dlg = new(ScaleAllDlg);
var result = dlg->Open(-1, -1);
}

bellaLugosi
07-06-2008, 02:59 PM
Hi,

I made this to speed up my deformer workflow, maybe some of ya'll find it useful as well.
I dock it in my layout to have one-click-deformers appear in place :)

The script inserts deformers at position of currently active object, as child of active object. Deformer also assumes same rotation and size as active object.

Upon invocation, a dialog appears that lets one select which type of deformer to create.
Supported are 5 most basic deformers (bend,shear and so on..)
other deforemers like formula are not supported atm.

works on polyObjects and all primitives except figure.
polyObjects should have their axis centered before using the script, else deformer size may be a little off.


hf,
BellaLugosi



//---------------------------------------
// EasyDeformer
//
// Inserts basic Deformers at position of selected object.
// Also inherits rotation and scale, by computing bounding box.
// Works for poly-Objects and all primitives except Figure.
// If used on poly-Objects, objects should have their axis centered before,
// else deformer dimensions may be off.
//
// by BellaLugosi
//---------------------------------------


// returns bounding box size vector of given object
GetBoundingBox(obj){
var count = obj->GetPointCount();
var points = (obj->GetPoints());
var maxPoint = vector(0,0,0);
var i;
for (i = 0; i < count; i++) {
var x = abs(int(points[i].x + 0.5)); if(x > maxPoint.x) maxPoint.x = x;
var y = abs(int(points[i].y + 0.5)); if(y > maxPoint.y) maxPoint.y = y;
var z = abs(int(points[i].z + 0.5)); if(z > maxPoint.z) maxPoint.z = z;
}
return maxPoint*2; // dist from center times two equals size
}

// type of deformer to put around the active object
var deformerType;

//The dialog
class InstanceDialog : GeModalDialog {
public:
CreateLayout();
Command(id,msg);
};

InstanceDialog::CreateLayout() {
SetTitle("EasyDeformer");

AddGroupBeginH(0,BFH_SCALEFIT,3,"",0);
AddStaticText(0,BFH_SCALEFIT,0,0,"Select Deformer to use:",0);
AddComboBox(1000,BFH_SCALEFIT, 80, 12);
AddItem(1000, obend, "Bend");
AddItem(1000, otwist, "Twist");
AddItem(1000, obulge, "Bulge");
AddItem(1000, oshear, "Shear");
AddItem(1000, otaper, "Taper");

AddDlgGroup(DR_DLGGROUP_OK|DR_DLGGROUP_CANCEL);
AddGroupEnd();
}

InstanceDialog::Command(id,msg) {
deformerType=GetInt(1000);
// use default deformer
if(deformerType==0) deformerType=obend;
}

main(doc,op)
{

// Get the active object
var op = doc->GetActiveObject();
if(!op) return;

// open Dialog
var dlg=new(InstanceDialog);
//dlg->SetDimensions();
dlg->Open(NOTOK,NOTOK);
if (!dlg->GetResult()) return FALSE;

var size = vector(0,0,0);
var type = op->GetType();

// is it a poly object ?
if(op->IsInstanceOf(opolygon))
size = GetBoundingBox(op);
else if(type>5153 && type<5174) // or a primitive ?
{
// create polyobject from input object
var bc = new(BaseContainer);
SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, doc, op, bc, MODIFY_ALL);
//doc->Message(MSG_UPDATE);
var clone = doc->GetActiveObject();
clone->SetName("copy");

//compute bounding box
size = GetBoundingBox(clone);
// remove poly object
clone->Remove();
}
else return; // else incompatible object (like spline or array or sth)

// compute some deformer offset from the average size of the objects sides
var _offset = int((size.x+size.y+size.z) / 100 + 0.5);
// apply offset
size+=_offset;

// insert deformer object as child of selected object
var deformer = AllocObject(deformerType);
// align deformer to parent obbject
var zeroVec = vector(0,0,0);
deformer->SetPosition(zeroVec);
deformer->SetRotation(zeroVec);
// resize deformer
var deformer_bc = deformer->GetContainer();
deformer_bc->SetData(DEFORMOBJECT_SIZE,size);
deformer->SetContainer(deformer_bc);

// add deformer as child of selected object
deformer->InsertUnder(op);
// add undo
doc->AddUndo(UNDO_OBJECT_NEW,deformer);
// De-select all objects
CallCommand(12113);
// select Deformer
op->GetDown()->SetBit(BIT_AOBJ);
// Update document
doc->Message(MSG_UPDATE);
}

HolgerBiebrach
08-23-2008, 01:01 PM
"GetNameFromChild" is my very first Script. It´s small but fine and does what the name says.

Enjoy it!!

http://www.holgerbiebrach.de/files/getnamefromchild.zip (http://www.holgerbiebrach.de/files/getnamefromchild.zip)

ler01
10-29-2008, 11:10 PM
group connect doesn`t work fine in 10.5. maby there is some alternative way to connect a lot of objects with preservation of their texturing?

otomo
01-24-2009, 02:09 PM
this script is a detector if your current poly selection contains polygons which are
already part of another selection tag. If so then the according selection tags are selected.
Works only with one selected object at a time.


/*
OVERLAP DETECTOR

this script is a detector if your current poly selection contains polygons which are
already part of another selection tag. If so then the according selection tags are selected.
Works only with one selected object at a time.
*/


var polySelection = op->GetPolygonSelection();//get the selected polygons of the currently selected object
var polycountOfSel = polySelection->GetCount();//how many polygons are selected?
var arSelPolys = new(array, polycountOfSel);//create array for selected polygons
var polycountOfObject = op->GetPolygonCount();//how many polygons does the object have in total?

var i = 0, o = 0;
for (i = 0; i < polycountOfObject ; i++)//iterate through all polygons of the object
{
if (polySelection->IsSelected(i))//writes every selected polygon(index) into an array
{
arSelPolys[o] = i;
o++;
}
}

var tag = op->GetFirstTag();
while (tag)//iterates through all tags of the object
{
tag->DelBit(BIT_ATAG);//deselect the tag
if (tag->IsInstanceOf(Tpolygonselection))//check if the tag is a Polygonselection tag
{
var tagSelection = tag->GetSelection();//what are the polygons in the selection tag?
for (i = 0; i < polycountOfSel ; i++)//iterates trhroug all currently selected polygons
{
if (tagSelection->IsSelected(arSelPolys[i]))//if a currently selected polygon is also part of the selection tag, then mark it as selected
{
tag->SetBit(BIT_ATAG);
break;
}
}
}
tag = tag->GetNext();
}

tcastudios
03-26-2009, 01:17 AM
Two scripts that might come in handy.
DIVIDE_SELECT: Selects the new points.
SELECT_NTH_POINT: Select nth number of points.

(Both only tested in R11)

In ScriptManager go File->Import and navigate to the dloaded files.

Cheers
Lennart

Rich-Art
03-26-2009, 06:51 PM
Thanks Lennart.

DIVIDE_SELECT: Selects the new points.

How does this one works. When I execute this one, my object gets subdivided (polygon's).

Peace,
Rich_Art. :thumbsup:

MJV
04-14-2009, 07:16 PM
Gathered 20 of my scripts for checking out. They all only make sense if placed in your layout to speed many things up.

Dload here (http://homepage.mac.com/tcastudios/xfiles.html)
http://homepage.mac.com/tcastudios/tcaxpresso/20scripts.jpg

Cheers
Lennart

These scripts are no longer available?

tcastudios
04-14-2009, 07:29 PM
@MJV I'm sorry, no. If things (ever) calm down I'll try to
repost updated versions.

@Rich-Art. They are for splines but the Subdivide is funky
(if the spline is closed or not differs)
and I haven't had time to check it.


Cheers
Lennart

ecore
04-26-2009, 03:01 PM
2 simple scripts to adjust select tools/brushes radius with your own assigned hotkey, as the same as bodypaint brush hotkeys use "." and ",".

support commands:

Live Selection (Soft Selection)
Modeling Brush
Modeling Magnet
CA Paint Tool
CA Morph Brush
CA Weight Tool
MoGraph Selection
Hair Live Selection
Hair Brush
Hair Cut

04.27.09 modified:
1 unit increase/decrease per click when radius<=50;
2 units increase/decrease per click when radius>50.

kvb
04-26-2009, 09:34 PM
2 simple scripts to adjust select tools/brushes radius with your own assigned hotkey, as the same as bodypaint brush hotkeys use "." and ",".

support commands:

Live Selection (Soft Selection)
Modeling Brush
Modeling Magnet
CA Paint Tool
CA Morph Brush
CA Weight Tool
MoGraph Selection
Hair Live Selection
Hair Brush
Hair Cut

Thank you so much for this:) Being a mac user with a Logitech Mx Revolution mouse, I'm stuck with a bug that won't allow me to adjust the brush radius. Reported to Maxon months ago... But this'll do for now:)


EDIT: 11.027 caused even more issues with the logitech mouse and software... prompted me to check and update my logitech control center software and now everything works as should (problem was that the scroll speed and acceleration weren't being taken into account: for both general and application specific settings... at least in c4d).

ecore
04-27-2009, 02:29 PM
04.27.09 modified:
1 unit increase/decrease per click when radius<=50;
2 units increase/decrease per click when radius>50.

Plz re-download.

Per-Anders
11-09-2009, 11:55 PM
Mirror Vice in COFFEE form. Keeps points at zero and kills extra polygons

Must be placed on the symmetry object itself rather than the polygonal geometry under it, and you should enable "Camera Dependent" on the COFFEE tag for the camera flipping to work (also make sure when you apply the tag that your camera is facing the side of the object that your geometry is on).

var clamp_pnts, clamp_flags, clamp_cnt, cur_pcnt, cur_vcnt, clamp_dir, tolerance, camera_dir;

GetCameraDirection(doc, symmetry_object)
{
var bd = doc->GetActiveBaseDraw();
if (!bd) return FALSE;

var cam = bd#BASEDRAW_DATA_CAMERA;
if (!cam) return FALSE;

var dir = cam->GetMg()->GetV3();
var mg = symmetry_object->GetMg();

dir = mg->GetMulV(dir);

switch (clamp_dir)
{
case SYMMETRYOBJECT_PLANE_XY: return dir.z > 0; break;
case SYMMETRYOBJECT_PLANE_XZ: return dir.y > 0; break;
case SYMMETRYOBJECT_PLANE_YZ: return dir.x > 0; break;
default: break;
}

return FALSE;
}

Init(doc, op, symmetry_object)
{
var padr = op->GetPoints();
var pcnt = op->GetPointCount();
var i = 0, cnt = 0;

tolerance = symmetry_object#SYMMETRYOBJECT_TOLERANCE;
clamp_dir = symmetry_object#SYMMETRYOBJECT_PLANE;

if (!symmetry_object#SYMMETRYOBJECT_WELD) tolerance = 0.0;

//Iterate through points and work out which need to be flagged
if (!clamp_pnts)
{
clamp_pnts = new(BaseSelect);
camera_dir = GetCameraDirection(doc, symmetry_object);
}

clamp_pnts->DeselectAll();

switch(clamp_dir)
{
case SYMMETRYOBJECT_PLANE_XY:
{
for (i = pcnt - 1; i >= 0; --i)
{
if (padr[i].z > -tolerance && padr[i].z < tolerance)
{
//Point within range
clamp_pnts->Select(i);
}
}
} break;
case SYMMETRYOBJECT_PLANE_XZ:
{
for (i = pcnt - 1; i >= 0; --i)
{
if (padr[i].y > -tolerance && padr[i].y < tolerance)
{
//Point within range
clamp_pnts->Select(i);
}
}
} break;
case SYMMETRYOBJECT_PLANE_YZ:
{
for (i = pcnt - 1; i >= 0; --i)
{
if (padr[i].x > -tolerance && padr[i].x < tolerance)
{
//Point within range
clamp_pnts->Select(i);
}
}
} break;
}

cnt = clamp_pnts->GetCount();

if (!clamp_cnt || clamp_cnt != cnt)
{
//Convert selection to short array for faster get/set access
//No BaseSelect::GetRange in COFFEE unfortunately
clamp_cnt = cnt;
clamp_flags = new(array,cnt);
if (!clamp_flags) return FALSE; //Memory Error

cnt = 0;

for (i = pcnt - 1; i >= 0; --i)
{
if (clamp_pnts->IsSelected(i))
{
clamp_flags[cnt++] = i;
}
}
}

cur_pcnt = pcnt;

return TRUE;
}

RemoveZeroPolygons(doc, op)
{
var padr = op->GetPoints();
var pcnt = op->GetPointCount();
var vadr = op->GetPolygons();
var vcnt = op->GetPolygonCount();
var i = 0, cnt = 0, ind = 0;

var vc = new(VariableChanged);
var map = new(array, vcnt);
if (!vc || !map) return FALSE;

if (!cur_vcnt || cur_vcnt > vcnt) cur_vcnt = 0;

for (i = cur_vcnt - 1; i >= 0; --i)
{
map[i] = i;
}

//New polygons are always added at the end, so this makes this much quicker
for (i = cur_vcnt, ind = cur_vcnt; i < vcnt && ind < vcnt; ++i, ++ind)
{
cnt = clamp_pnts->IsSelected(vadr[i * 4 + 0]);
cnt += clamp_pnts->IsSelected(vadr[i * 4 + 1]);
cnt += clamp_pnts->IsSelected(vadr[i * 4 + 2]);
cnt += clamp_pnts->IsSelected(vadr[i * 4 + 3]);

if (cnt == 4)
{
//All points are clamped, therefore we need to cull this polygon
map[i] = NOTOK;
ind--;
continue;
}

map[i] = ind;
}

if (ind != vcnt)
{
//Update the polygon count using the map
vc->Init(vcnt, ind, map);
op->MultiMessage(MSG_POLYGONS_CHANGED, vc);
op->Message(MSG_CHANGE);
} else cur_vcnt = vcnt;

return TRUE;
}

ClampPoints(op)
{
var padr = op->GetPoints();
var pcnt = op->GetPointCount();
var i = 0, ind = 0, changed = FALSE;

for (i = clamp_cnt - 1; i >= 0; --i)
{
ind = clamp_flags[i];
if (ind > pcnt) continue;

if (padr[ind].x != 0.0)
{
padr[ind].x = 0.0;
changed = TRUE;
}
}

if (changed)
{
op->SetPoints(padr);
op->Message(MSG_UPDATE);
}
}

CameraFlip(doc, op, symmetry_object)
{
var dir = GetCameraDirection(doc, symmetry_object);

var i = 0;
var pcnt = op->GetPointCount();
var padr = op->GetPoints();
var bc = new(BaseContainer);

if (camera_dir == dir) return; //Nothing changed
camera_dir = dir;

switch (clamp_dir)
{
case SYMMETRYOBJECT_PLANE_XY:
{
for (i = pcnt - 1; i >= 0; --i) padr[i].z = -padr[i].z;
} break;
case SYMMETRYOBJECT_PLANE_XZ:
{
for (i = pcnt - 1; i >= 0; --i) padr[i].y = -padr[i].y;
} break;
case SYMMETRYOBJECT_PLANE_YZ:
{
for (i = pcnt - 1; i >= 0; --i) padr[i].x = -padr[i].x;
} break;
default: break;
}

op->SetPoints(padr);
SendModelingCommand(MCOMMAND_REVERSENORMALS, NULL, op, bc, MODIFY_ALL);
op->Message(MSG_UPDATE);
}

//Main function routine, called each pass
main(doc,op)
{
//Get the active symmetry object involved here
var symmetry_object = op;
while (symmetry_object)
{
if (symmetry_object->IsInstanceOf(Osymmetry)) break;
symmetry_object = symmetry_object->GetUp();
}

if (!symmetry_object || !symmetry_object->IsInstanceOf(Osymmetry) || !symmetry_object#ID_BASEOBJECT_GENERATOR_FLAG) return TRUE; //No active symmetry object

//We only adjust the first child of the symmetry object
op = symmetry_object->GetDown();

if (!op->IsInstanceOf(Opoint)) return TRUE; //Not a points object

var pcnt = op->GetPointCount();
var vcnt = op->GetPolygonCount();

//Check for any new points that need clamping
if (!clamp_pnts || pcnt != cur_pcnt || symmetry_object#SYMMETRYOBJECT_TOLERANCE != tolerance || symmetry_object#SYMMETRYOBJECT_PLANE != clamp_dir)
{
if (!Init(doc, op, symmetry_object)) return FALSE;
}

ClampPoints(op);

//Check for any new polygons that might need culling
if (symmetry_object#SYMMETRYOBJECT_WELD && vcnt != cur_vcnt)
{
if (!RemoveZeroPolygons(doc, op)) return FALSE;
}

CameraFlip(doc, op, symmetry_object);

return TRUE;
}