[vtkusers] Help with tcl interpreter
Johanna
pettersson.johanna at home.se
Wed Jul 30 02:55:09 EDT 2003
Thank you Robert.
Now I got it to work with my own interpreter as well. I had not understood which files/libraries to load in the beginning of my tcl script. This was my error.
/Johanna
-----Original Message-----
From: Robert Belleman <robbel at science.uva.nl>
To: Johanna <pettersson.johanna at home.se>
Date: Wed, 30 Jul 2003 08:28:00 +0200
Subject: Re: [vtkusers] Help with tcl interpreter
Johanna,
Here's an example: the following C code should be all you need
to create a simple Tcl interpreter that executes a script from
a file (given by the first argument):
--------------------------------------------------------------------
#include <tcl.h>
int main(int argc, char *argv[])
{
Tcl_Interp *tclinterp = Tcl_CreateInterp();
if (Tcl_EvalFile(tclinterp, argv[1]) != TCL_OK)
fprintf(stderr, "Error: %s\n", tclinterp->result);
return 0;
}
--------------------------------------------------------------------
Feed this program the script below to get a Vtk cone:
--------------------------------------------------------------------
set tcl_library "/usr/lib/tcl8.3"
source $tcl_library/init.tcl
load libtk
load libvtkCommonTCL
load libvtkGraphicsTCL
load libvtkRenderingTCL
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
vtkConeSource cone
vtkPolyDataMapper coneMapper
coneMapper SetInput [cone GetOutput]
vtkActor coneActor
coneActor SetMapper coneMapper
wm withdraw .
ren1 AddActor coneActor
iren Initialize
iren Start
--------------------------------------------------------------------
Hope that solves your problem,
best,
-- Rob
--
[] Robert Belleman, PhD X Faculty of Science, Informatics Inst. []
[] robbel at science.uva.nl |X| University of Amsterdam, the Netherlands []
[] tel: (+31) 20 525 7510 X http://www.science.uva.nl/~robbel/ []
On Tue, Jul 29, 2003 at 03:52:06PM +0200, Johanna wrote:
> This is part of my code and the result:
>
> Code:
> Tcl_Interp *tclinterp;
> tclinterp = Tcl_CreateInterp();
>
> eval=Tcl_GlobalEval(tclinterp,"info library");
>
> if (tclinterp->result != 0) {
> printf("Test [%s]\n", tclinterp->result);
> }
>
> if (eval==TCL_ERROR) {
> printf("eval=[%d]\n", eval);
> return TCL_ERROR;
> }
>
> Result/Output:
> Test [no library has been specified for Tcl]
>
> So I guess my libraries are not loaded ok. However I still get a TCL_ERROR from Tcl_GlobalEval so it seems that not even the line 'Tcl_GlobalEval(tclinterp,"info library")' is ok.
>
> I tried to do 'Tcl_EvalFile(tclinterp, "/usr/lib/tcl8.3/init.tcl")' but since all Tcl_EvalFile, Tcl_GlobalEval etc generates a TCL_ERROR I do not think it worked.
>
> /Johanna
>
> -----Original Message-----
> From: "shahid" <shahed at isb.paknet.com.pk>
> To: <vtkusers at vtk.org>
> Date: Tue, 29 Jul 2003 17:24:38 +0500
> Subject: RE: [vtkusers] Help with tcl interpreter
>
>
> You probably need to first check that you Interp process is initialized
> properly
> code=Tcl_Eval(tclinterp,"info library"); # returned path must include path
> to vtk files
> #else "package require vtk"
> shall fail
> doing
> Tcl_EvalFile(tclinterp, "your_tcllibpath/init.tcl"); # may help to
> initialize the interpreter properly
>
> Hope this shall solve your problem.
>
> shahed
>
> -----Original Message-----
> From: vtkusers-admin at vtk.org [mailto:vtkusers-admin at vtk.org]On Behalf Of
> Johanna
> Sent: Tuesday, July 29, 2003 12:38 PM
> To: vtkusers at vtk.org
> Subject: [vtkusers] Help with tcl interpreter
>
>
> Hello
>
> I am trying to use Tcl_Interp and Tcl_EvalFile to evaluate a tcl script from
> a c++ file. My code looks like this:
>
> Tcl_Interp *tclinterp;
> tclinterp = Tcl_CreateInterp();
>
> int code = Tcl_EvalFile(tclinterp, "myTclScript.tcl");
>
> if (code!=TCL_OK) {
> return TCL_ERROR;
> }
>
> The problem is that Tcl_EvalFile is never TCL_OK and always returns an
> error, i.e. myTclScript.tcl can not be evaluated. When my tcl script has
> been run by the interpreter I would like to access some actors generated in
> the tcl script.
>
> Does anyone have any experience on this and can see what I am doing wrong?
>
> Sincerely
> Johanna
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list