CommandSequenceAvailability LightWave 6.0 Command sequence plug-ins issue commands to create and manipulate geometry in Modeler. They also have access to the same mesh editing functions as the MeshDataEdit class. Activation Function XCALL_( int ) MyCmdSeq( long version, GlobalFunc *global, LWModCommand *local, void *serverData ); The local argument to a command sequence's activation function is an LWModCommand. typedef struct st_LWModCommand { void *data; const char *argument; LWCommandCode (*lookup) (void *, const char *cmdName); int (*execute) (void *, LWCommandCode cmd, int argc, const DynaValue *argv, EltOpSelect, DynaValue *result); MeshEditBegin *editBegin; int (*evaluate) (void *, const char *command); } LWModCommand;
See the Commands pages for a complete list of the commands that can be issued in Modeler, as well as a detailed explanation of the formatting of command arguments for both the execute and evaluate methods. Example The DNA sample is a CommandSequence plug-in that builds classic Watson-Crick DNA molecules. It uses the ModLib static-link library, which greatly simplifies command execution by translating commands into function calls. The library currently contains about 170 functions that cover Modeler commands, mesh edit functions, and globals. This ModLib function executes the MAKEBALL command, building the DynaValue argument list and calling the lookup and execute functions. (ModData is a ModLib structure that caches the LWModCommand pointer and the data returned from a number of globals.) int csMakeBall( double *radius, int nsides, int nsegments, double *center ) { static LWCommandCode ccode; ModData *md = getModData(); DynaValue argv[ 4 ]; assert( md->edit == NULL ); argv[ 0 ].type = DY_VFLOAT; argv[ 0 ].fvec.val[ 0 ] = radius[ 0 ]; argv[ 0 ].fvec.val[ 1 ] = radius[ 1 ]; argv[ 0 ].fvec.val[ 2 ] = radius[ 2 ]; argv[ 1 ].type = DY_INTEGER; argv[ 1 ].intv.value = nsides; argv[ 2 ].type = DY_INTEGER; argv[ 2 ].intv.value = nsegments; if ( center ) { argv[ 3 ].type = DY_VFLOAT; argv[ 3 ].fvec.val[ 0 ] = center[ 0 ]; argv[ 3 ].fvec.val[ 1 ] = center[ 1 ]; argv[ 3 ].fvec.val[ 2 ] = center[ 2 ]; } else argv[ 3 ].type = DY_NULL; if ( !ccode ) ccode = md->local->lookup( md->local->data, "MAKEBALL" ); md->cmderror = md->local->execute( md->local->data, ccode, 4, argv, md->opsel, &md->result ); return md->cmderror == CSERR_NONE; } Using ModLib makes DNA's command processing almost as simple as scripting. Below is a code fragment from the function in the DNA plug-in that creates the cylinders representing atomic bonds. csSetLayer( layer2 ); csSetDefaultSurface( surface_name( snum )); csMakeDisc( r, h, 0, "Y", bond_nsides, bond_nsegments, c ); csRotate( xrot, "X", NULL ); csRotate( yrot, "Y", NULL ); csMove( pt ); rot = 36 * j; csRotate( rot, "Y", NULL ); csCut(); csSetLayer( layer1 ); csPaste(); |