[vtkusers] Accessing C++ representation from scripting language

Kevin Wright krw at viz-solutions.com
Mon Feb 10 13:07:34 EST 2003


At 04:31 PM 2/10/2003 +0100, you wrote:
>Hi All,
>
>I have the following question:
>If I create a VTK object in scripting language (e.g. Tcl)
>
>vtkUnstructuredGrid ugrid
>
>can I somehow get the the pointer to its underlying C++ representation?

If you create a new Tcl command (I assume, given your question that you 
know how to do this, if not, you can find out from any Tcl/Tk book) which 
accepts the name of the object (and the class of the object if that's not 
always the same), and call vtkTclGetPointerFromObject (from 
vtkTclUtils.cxx, I believe) with the name to get the pointer.  It will be a 
void pointer, which you can cast to the proper class.

e.g.

int DoSomethingCmd(ClientData clientData, Tcl_Interp *interp,
         int objc, Tcl_Obj *CONST objv[]) {

   char *objectName = "ugrid";
   char *className = "vtkUnstructuredGrid";
   int error = 0;
   void *ptr = vtkTclGetPointerFromObject(objectName,className,interp,error);
   vtkUnstructuredGrid *ug = (vtkUnstructuredGrid *) ptr;
}




More information about the vtkusers mailing list