Welcome, Guest. Please login or register.
Did you miss your activation email?
February 09, 2012, 03:12:27 AM
Home Help Login Register
News: Any Problems or Experience with Industrial Robots ?
Register and place your Question / Answer to worldwide Robotexperts right here !

+  Robotforum | Support for Robotprogrammer and Users
|-+  Simulation Systems
| |-+  eM-Workplace / Robcad
| | |-+  Help in tcl/tk programming in robCAD
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 3 Print
Author Topic: Help in tcl/tk programming in robCAD  (Read 7452 times)
jitsubh07
Guest
« on: February 13, 2009, 12:30:50 PM »

Can anyone help in basic programming with tcl/tk in robCAD in windows platform. 
Logged
joker
Full Member
***
Offline Offline

Gender: Male
Posts: 204


"Hell...Yesterday it was workinG... I sweaR" :o)


« Reply #1 on: February 14, 2009, 10:29:35 AM »

Hi, what exactly do You need??
Logged
jitsubh07
Guest
« Reply #2 on: February 17, 2009, 07:05:29 AM »

HI!! I'm trying to write some interactive macro in RobCAD with the help of tcl/tk. I'm using RobCAD7.5.1, tcl/tk8.4 & os WinXP. I've not installed any tcl/tk application seperately.

In RobCAD interactive macROSE console when I write the following command,
         % set pipetk [open | c:/Conversion/example1.tk r+]
it gives the error :-- expected integer but got "r+"

Kindly Help....
Regards,
jitsubh07
Logged
asimo
Guest
« Reply #3 on: February 19, 2009, 02:16:18 AM »

Your problem is your pipe symbol. The way you wrote it, it's as if your "r+" argument was the ?permission? argument tcl needs (the 4th argument). Normally, it is set as the Unix pattern *owner-group-other* (i.e. 777 -- permission to everyone). That's why it needs an integer. Normally, the pipe is used inside double quotes to open a process pipeline. Example:
Code:
set computer [open "|hostname" r]

If you want to read a file in Windows, do it this way:
Code:
set pipetk [open C:/Conversion/example1.tk r+]
or
Code:
set pipetk [open {C:\Conversion\example1.tk} r+]
or
Code:
set pipetk [open C:\\Conversion\\example1.tk r+]
Logged
jitsubh07
Guest
« Reply #4 on: February 19, 2009, 07:45:56 AM »

Hi asimo ,

     thanks for the answer.. But when I'm writing the following code in the console, it doesn't create the interface from the test1.tk file.
                              Command :- % set pipetk [open {c:/Conversion/test1.tk} r+]
                              Returns:-      file1537b8

I'm also giving the code I've written in the test.tk

              exec wish84;

              tk_setPalette Grey
              frame .frm -borderwidth 2 -relief sunken
              pack .frm -fill x

              label .frm.hello -text "Hello World"
              entry .frm.ent -width 30
              button .but -text "CLICK"
              button .quit -text Quit -command exit

              pack .frm.hello -side left -padx 2
              pack .frm.ent -after .frm.hello -padx "5 10"

              pack .but -side left
              pack .quit -after .but



regards,
jitsubh07
Logged
asimo
Guest
« Reply #5 on: February 20, 2009, 02:10:52 AM »

Hi,

The "open" command returns an I/O channel (file1537b8 in your case). From that, you can access the file/pipeline content. As I understand your problem, you have made a GUI in your test1.tk file and you want to start that GUI from your TCL console. This one is a little bit tricky. Normally, to execute something, you can use the "exec" command. But if you try it like this:
Code:
catch {exec c:/Conversion/test1.tk} error

You will only get a wish window with nothing inside. If you want to run a TCL script inside a TCL/TK script (or a TCL console as in your case), you have to use the "source" command like this:
Code:
source {c:/Conversion/test1.tk}

Try that one and let us know.
Logged
jitsubh07
Guest
« Reply #6 on: March 10, 2009, 07:25:56 AM »

HI!!

     I've tried with the source command. Now it is creating the interface but not the intercative one....

   Actually my problem is....... I want to create an interactive interface which will display the name of the entity after I'll select any entity in base RobCAD application. For that I've written following codes...which are not working.....

1st file is:- #example1.tcl#

set pipetk [source {c:/Conversion/example1.tk}]
flush $pipetk

set entity ""
set cmd ""
set property ""

while {$cmd != "exit"} {
   set cmd [gets $pipetk]
   if {$cmd == "select_entity"} {
      uiWriteMsg "Pick an Entity"
      set entity [uiGetPick]
      set property [apGetProperty $entity P_NAME]
      puts $pipetk $property
      flush $pipetk
   }
   puts stderr $cmd
}

2nd file:- #example1.tk#

exec wish84 c:/Conversion/exam2.tcl &

3rd file:-#exam2.tcl#

tk_setPalette Grey
frame .frm -borderwidth 2 -relief sunken
pack .frm -fill x

label .frm.hello -text "Hello World"
entry .frm.ent -width 30
button .but -text "CLICK"
button .quit -text Quit -command exit

pack .frm.hello -side left -padx 2
pack .frm.ent -after .frm.hello -padx "5 10"

pack .but -side left
pack .quit -after .but

bind .but <Button-1> {
puts "select_entity"
flush stdout
set data ""
while {$data != "end"} {
   set data [gets stdin]
   .frm.ent insert 0 $data
   }
}

Now when I run the macro "example1.tcl" from RobCAD macROSE,  the interface named "exam2" appears with an error message in RobCAD "Can't load or execute script C:/Conversion/example1.tcl:".

If I press the "Quit" button, the interface gets closed. But if I press the Click button....the interface gets hanged......

Any help will be greatly appreciated....

thanks

jitsubh07
Logged
asimo
Guest
« Reply #7 on: March 12, 2009, 01:56:25 AM »

First, I think that you don't need 3 files to do that. In fact, everything can be in a single file, but if you want to separate tcl and tk, it's fine. So I suggest that the code inside exam2.tcl would be in your example1.tk instead of the single line calling exam2.tcl. Second, I am not sure why you need a flush command on the second line of your example1.tcl. Normally, I use flush to output something (normally used with -nonewline and puts, but it can be for something else). Third, I think that what makes hang your application is your while loop. When you click on your button, it is always looking for "end" and we cannot enter it as it is always scanning for it.
Logged
jitsubh07
Guest
« Reply #8 on: March 16, 2009, 08:04:11 AM »

HI Asimo!!,

  I've modified the code of example1.tk as follows:-

2nd file:- #example1.tk#

exec wish84
tk_setPalette Grey
frame .frm -borderwidth 2 -relief sunken
pack .frm -fill x

label .frm.hello -text "Hello World"
entry .frm.ent -width 30
button .but -text "CLICK"
button .quit -text Quit -command exit

pack .frm.hello -side left -padx 2
pack .frm.ent -after .frm.hello -padx "5 10"

pack .but -side left
pack .quit -after .but

bind .but <Button-1> {
puts "select_entity"
flush stdout
set data ""
while {$data != "end"} {
   set data [gets stdin]
   .frm.ent insert 0 $data
   }
}

Now when I run the macro "example1.tcl" from RobCAD macROSE,  the interface doesn't get created, only the wish console gets appeared...

I'm using RobCAD7.5.1, tcl/tk8.4 & os WinXP. I've not installed any tcl/tk application separately.
Does this require any extra license pack in robcad? Or I should install tcl/tk application...  I’m not being able to trace the mistake I’m doing…

jitsubh07
Logged
asimo
Guest
« Reply #9 on: March 20, 2009, 01:43:34 AM »

Hi,

It is normal that you get that empty window because you are calling wish directly. And I've seen that you still have the "while" statement which I think may be your problem. No, you don't have to install a version of TCL/TK. If it wasn't there, you would not see the empty window you have. Its been a long time since I've work with Robcad, but give me some time, I will try to have a look more closely at your code.
Logged
asimo
Guest
« Reply #10 on: March 20, 2009, 02:46:48 AM »

Okay, let's start with a basic program. I think what you are trying to do is get the information from an entry box. So try this small script (only one file, call it whatever you want with the *.tcl extension, like "example1.tcl"):

Code:
tk_setPalette Grey
frame .frm -borderwidth 2 -relief sunken
pack .frm -fill x

label .frm.hello -text "Hello World"
entry .frm.ent -width 30
button .but -text "CLICK" -command GetText
button .quit -text Quit -command exit

pack .frm.hello -side left -padx 2
pack .frm.ent -after .frm.hello -padx "5 10"

pack .but -side left
pack .quit -after .but

update idletasks

proc GetText {} {
set data [.frm.ent get]
if {$data == "end"} {
    tk_messageBox -type ok -default ok \
        -message "This is a message" \
        -icon info \
        -title "Information"
}
}

If you enter the word "end" in the entry box and you hit the "CLICK" button, you should see a message box. Is it working?
Logged
jitsubh07
Guest
« Reply #11 on: March 20, 2009, 11:04:30 AM »

Hi Asimo!! Thanks a lot for spending your valuable time.......

     Actually what I want is...to get an information(say,  name) in an entry box(e.g.) about an entity selected from robCAD application.

    I've tried the small script as suggested by you....i've saved it with .tcl extension...test1.tcl and then tried to run this script from robCAD macROSE. But it is not running...gives a message "can't load or execute test1.tcl"...

regards,
Subhrajit
Logged
asimo
Guest
« Reply #12 on: March 26, 2009, 02:44:24 AM »

Mmm. That's strange. Try this instead:

In test1.tcl:
Code:
source {./test1.tk}

In test1.tk
Code:
tk_setPalette Grey
frame .frm -borderwidth 2 -relief sunken
pack .frm -fill x

label .frm.hello -text "Hello World"
entry .frm.ent -width 30
button .but -text "CLICK" -command GetText
button .quit -text Quit -command exit

pack .frm.hello -side left -padx 2
pack .frm.ent -after .frm.hello -padx "5 10"

pack .but -side left
pack .quit -after .but

update idletasks

proc GetText {} {
set data [.frm.ent get]
if {$data == "end"} {
    tk_messageBox -type ok -default ok \
        -message "This is a message" \
        -icon info \
        -title "ERROR"
}
}

Of course, you can put the full path in test1.tcl instead if it's not working (full path can be better because we don't know from where the interpreter starts).

If you see the GUI, try entering the word "end" and hit "CLICK". You should see a message box. From threre, we will continue if it's working.
Logged
jitsubh07
Guest
« Reply #13 on: March 26, 2009, 07:49:54 AM »

Hi asimo....

     The GUI is still not appearing.... It is giving the same error message..."can't load or execute test1.tcl"... I've given the full path......I've run the tcl file from RobCAD macROSE dialog box....actually here untill I'm writing the statement "exec wish84"...the gui is not appearing........

regards,
Subhrajit
Logged
asimo
Guest
« Reply #14 on: March 26, 2009, 06:53:56 PM »

Okay. It's probably because your *.tcl extensions are associated with tcl84.exe instead of wish84.exe. You have the choice of mapping *.tcl to wish84.exe (this one is probably not recommended as it may have an impact on other *.tcl programs), or associate *.tk with wish84 and try if this works with the last solution I provided, or doing it that way:

In test1.tcl:
Code:
# ...or set the full path to test1.tk
exec wish85 ./test1.tk

In test1.tk
Code:
tk_setPalette Grey
frame .frm -borderwidth 2 -relief sunken
pack .frm -fill x

label .frm.hello -text "Hello World"
entry .frm.ent -width 30
button .but -text "CLICK" -command GetText
button .quit -text Quit -command exit

pack .frm.hello -side left -padx 2
pack .frm.ent -after .frm.hello -padx "5 10"

pack .but -side left
pack .quit -after .but

update idletasks

proc GetText {} {
set data [.frm.ent get]
if {$data == "end"} {
    tk_messageBox -type ok -default ok \
        -message "This is a message" \
        -icon info \
        -title "ERROR"
}
}

Now, is it working when you enter "end" in the entry box?
Logged
Pages: [1] 2 3 Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!