Thank You Bill. It worked!!<br><br>Sanket Jain<br><br><div class="gmail_quote">On Thu, Dec 17, 2009 at 10:17 AM, Bill Lorensen <span dir="ltr"><<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">In tcl, if you are reusing an object in a proc, just put a catch<br>
around the construction:<br>
<br>
catch {vtkPolyDataMapper partMapper}<br>
<br>
The first time the statement is executed it will create partMapper.<br>
Subsequent calls, the statement will fail silently.<br>
<br>
Be careful when you are first writing the code. The catch can hide errors.<br>
<br>
Bill<br>
<div><div></div><div class="h5"><br>
On Thu, Dec 17, 2009 at 10:26 AM, Sanket Jain <<a href="mailto:jainsanket1@gmail.com">jainsanket1@gmail.com</a>> wrote:<br>
> Hello Experts,,<br>
><br>
> My question is a TCL question rather than a VTK question. I hope it is fine<br>
> with other members. At the end, is the part of my code required for<br>
> understanding my question.<br>
><br>
> If you look at my code, I have defined 2 procedures: MakeSTLActor and<br>
> MakeDataActor. The main function call these procedures whenever required.<br>
> Now, when these procedures are called for the 1st time, only the highlighted<br>
> portion of the procedure gets the job done.<br>
><br>
> If the procedure is called again for the 2nd time, the interpreter<br>
> give error saying that objects partMapper and partActoro (in MakeSTLActor<br>
> procedure; this also implies for the objects in the other procedure) is<br>
> already created. So, I can delete the partMapper object as soon as its job<br>
> is done (specifically, after creation of partActoro). But I cannot delete<br>
> partActoro because I have to return this object. So, next time when the<br>
> procedure is called, I get the error regarding the existence of partActoro.<br>
><br>
> At, this point I am using flags in my procedures (closeevent, isotrack), to<br>
> delete the objects before calling the procedure for 2nd time. Although, my<br>
> script runs without any bugs, I think this might not be the most elegant way<br>
> of doing it. So, does any one knows a way by which I can avoid using the<br>
> flags in my procedure and delete the objects (partActoro and dataActoro in<br>
> the 2 procedures) before/while the return to the main function.<br>
><br>
> Let me know if I need to clarify my question.<br>
><br>
> Thank You,<br>
><br>
> Sanket Jain<br>
><br>
><br>
> # CODE STARTS HERE......<br>
><br>
> package require vtk<br>
><br>
> package require<br>
><br>
> vtkinteractionpackage require vtktesting<br>
><br>
> #... Relevant Tk Codes for building the GUI.<br>
><br>
> proc main {} {<br>
><br>
> #......Some Relevant TCL Codes<br>
><br>
> vtkActor partActor<br>
><br>
> set partActor [MakeSTLActor vtkSTLReader part]<br>
><br>
> [$partActor GetProperty] SetOpacity 1<br>
><br>
> vtkActor dataActor<br>
><br>
> set dataActor [MakeDataActor vtkConnectivityFilter connect]<br>
><br>
> #.... Other Relevant TCL Codes<br>
><br>
> }<br>
><br>
> #Make Actor for STL File<br>
><br>
> proc MakeSTLActor {vtkSTLReader part} {<br>
><br>
> global closeevent<br>
><br>
> global isotrack<br>
><br>
> if {$isotrack==1} {<br>
><br>
> partMapper Delete<br>
><br>
> partActoro Delete<br>
><br>
> }<br>
><br>
> if {$closeevent == 0} {<br>
><br>
> partMapper Delete<br>
><br>
> partActoro Delete<br>
><br>
> } else {<br>
><br>
> vtkPolyDataMapper partMapper<br>
><br>
> partMapper SetInputConnection [$part GetOutputPort]<br>
><br>
> vtkActor partActoro<br>
><br>
> partActoro SetMapper partMapper<br>
><br>
> return partActoro<br>
><br>
> }<br>
><br>
> }<br>
><br>
> # Makes Actor for the Original Data<br>
><br>
> proc MakeDataActor {vtkConnectivityFilter connecto} {<br>
><br>
> global closeevent<br>
><br>
> global isotrack<br>
><br>
> if {$isotrack==1} {<br>
><br>
> dataMapper Delete<br>
><br>
> prop Delete<br>
><br>
> dataActoro Delete<br>
><br>
> }<br>
><br>
> if {$closeevent == 0} {<br>
><br>
> dataMapper Delete<br>
><br>
> prop Delete<br>
><br>
> dataActoro Delete<br>
><br>
> } else {<br>
><br>
> vtkDataSetMapper dataMapper<br>
><br>
> dataMapper SetInputConnection [$connecto GetOutputPort]<br>
><br>
> vtkProperty prop<br>
><br>
> prop SetOpacity 0.1<br>
><br>
> vtkActor dataActoro<br>
><br>
> dataActoro SetMapper dataMapper<br>
><br>
> dataActoro SetProperty prop<br>
><br>
> dataActoro SetOrigin 0 0 0<br>
><br>
> return dataActoro<br>
><br>
> }<br>
><br>
> }<br>
><br>
> #.... Similarly Defining other procedures<br>
><br>
> #which creates actors and returns to the main<br>
><br>
> #function which renders them.<br>
><br>
> --<br>
> Sanket Jain<br>
><br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
><br>
</blockquote></div><br><br clear="all"><br>-- <br>Sanket Jain<br>