View Single Post
Old 12th May 2006, 12:45 PM   #5
Andy
Administrator
Professional user
 
Andy's Avatar
 
Join Date: Jun 2003
Posts: 4,565
Default script for loading and saving background image configs

Until we add a 'Scripts and mods' section on this forum - here's a script which adds loading and saving of the background images.

Save this text into a file called 'viewsave.tcl' and place the file in the 'scripts' folder which is within the AC3D program folder.

When AC3D starts it will read this script and add two items to the Tools menu.


Code:
# simple AC3D script that adds two items to tool menu - to save and load the background image setup	
# for AC3D 6 - 24th Jan 2006
	
proc saveview { viewid file} {

	# get the view entity
	set v [ac3d viewid_to_entity $viewid]

	#get the background image entity from the view
	set image [ac3d entity_get_value $v "background_image" ]

	if {$image != 0 } {
		# if there's an image, read the relavent values for the layout, along with the image name from the image entity
		set x [ac3d entity_get_value $v "background_image_xoffset" ]
		set y [ac3d entity_get_value $v "background_image_yoffset" ]
		set scale [ac3d entity_get_value $v "background_image_scale" ]
		set picname [ac3d entity_get_value $image "name"]
		
		puts $file "$viewid|$picname|$x|$y|$scale"
	}
}


proc save_view_config { } {

    set filename [tk_getSaveFile -title "Save bg image config" -filetypes {{"AC3D project" { acp }}} -defaultextension .acp ]

    if { $filename == "" } {
	    return
	}
	    

	set path [file dirname $filename]
	set file [open $filename w]

	saveview 0 $file
	saveview 1 $file
	saveview 2 $file
	saveview 3 $file

	close $file
}

proc load_view_config { } {

    set filename [tk_getOpenFile -title "Load bg image config" -filetypes {{"AC3D project" { acp }}} -defaultextension .acp ]

    if { $filename == "" } {
	    return
	}
	    
	set file [open $filename r]
	gets $file line
	while {$line != ""} {
#		puts $line
		set parts [split $line "|" ]
		set vid [lindex $parts 0]
		set bgname [lindex $parts 1]
		set x [lindex $parts 2]
		set y [lindex $parts 3]
		set scale [lindex $parts 4]

		#puts "view $vid bg image $bgname, $x $y, $scale"

		set vent [ac3d viewid_to_entity $vid]
		ac3d entity_set_value $vent background_image_xoffset $x
		ac3d entity_set_value $vent background_image_yoffset $y
		ac3d entity_set_value $vent background_image_scale $scale 
		ac3d load_background_image $bgname $vid
		ac3d redraw_all

		gets $file line
		}
}


add_tools_menu_item "Load background image config" load_view_config "Load a view configuration"
add_tools_menu_item "Save background image config" save_view_config "Save the view configuration"
Note that we decided not to add this information into the .ac files since it would break many systems which use .ac files to store geometry. In the future the .ac file format will probably be changed so that it can store information like the background image setup.
Andy is offline   Reply With Quote