View Single Post
Old 12th November 2007, 08:33 PM   #2
lisa
Senior Member
Professional user
 
lisa's Avatar
 
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 917
Default Re: AC3D scripts? Please help me!

Here's a tutorial on TCL:
http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

The easiest thing to do is to just open up the scripts that are there and see what they do.

This script from the SDK is a good example, and it will produce a dump so you will know what all of the commands are:

#!/usr/local/bin/wish


# TCL Shell for AC3D - Version 1.0 by Andy Colebourne
# interfaces on to the internal TCL socket in AC3D so that commands
# can be sent to AC3D
# note that commands should usually start with 'ac3d' e.g. 'ac3d select_all'
# this shell prepends 'ac3d' to each command entered in the bottom text field

# the first line of this file should be #! followed by the path where 'wish'
# resides - 'which wish' should tell you where this is
# socket_num shoudl be set to the same number as tcl_socket_port in the
# ac3d prefs file. Also, ac3d_host should be set to 'localhost' i.e. this
# machine, or the IP address/hostname of the machine where AC3D is running

# the AC3D socket to connect to :
set socket_num 1655

# the host to connect to e.g. IP number, symbolic name or localhost
set ac3d_host localhost

toplevel .shell
set p .shell


proc disp_text { text } {
# append some text to the main window display
.shell.text insert end $text
.shell.text insert end "\n"
.shell.text see end
}


proc do_com {} {
# send the command to the AC3D socket
# reply is in two parts - one line containing the string length of the
# next line, which contains the reply string

global p string dest sock

if { $string == "" } { return }
puts $string
$p.text insert end $string
$p.text insert end "\n"
$p.text see end

# send the command with 'ac3d' prepended
puts $sock "ac3d $string"; flush $sock

# read the length of the reply
gets $sock len

# read that many bytes
set res [read $sock $len]

# display the reply
$p.text insert end $res
$p.text insert end "\n"
$p.text see end

set string ""
}



# try to connect to the AC3D socket - if it fails, quit

set er [ catch { set sock [socket $ac3d_host $socket_num] } ]

if { $er != 0 } {
puts "can't connnect to AC3D socket $socket_num on $ac3d_host\nAC3D may not be running on this machine ($ac3d_host) or \nthe socket number of AC3D may be different to $socket_num - exiting."
exit
}



puts "socket $sock"

wm withdraw .

set string ""

wm title $p "AC3D Shell"

text $p.text -yscrollcommand "$p.ys set" \
-xscrollcommand "$p.xs set" \
-wrap none -padx 4 -pady 4 \
-exportselection true

scrollbar $p.ys -command "$p.text yview"
scrollbar $p.xs -command "$p.text xview" -orient horizontal
entry $p.entry -textvariable string
pack $p.entry -fill x -side bottom
pack $p.xs -side bottom -fill both -expand 0

pack $p.ys -side left -fill y -expand 0
pack $p.text -fill both -expand 1

disp_text "AC3D command shell\n\nEnter 'list' for a list of the commands available\n\n"

focus $p.entry

bind $p.entry <Return> "do_com"
lisa is offline   Reply With Quote