#!/bin/csh -f ############################################################################ # DXFconvert Version 1.0 # Author: Heath Beres hberes@vt.edu # Created: 12/12/97 Last Modified 12/14/97 # Copyright 1997 Heath P. Beres ############################################################################ # COPYRIGHT NOTICE: # # DXFconvert may be used and modified free of charge by anyone so long as # this copyright notice and the comments above remain intact. By using # this code you agree to indemnify Heath P. Beres from any liability that # might arise from its use. # # Selling the code for this program without prior written consent is # expressly forbidden. In other words, please ask first before you try # and make money off of my program. # # Obtain permission before redistributing this software over the Internet # or in any other medium. In all cases copyright and header must remain # intact. # # All subroutines (C programs) used in this script correspond to their # respective copyright. ############################################################################## # # There are several C programs to convert from AutoCAD format to # CAVE/Performer, but running the 4 programs for every drawing gets tedious. # This script takes the input .DXF file and converts it to .pfb format. # # C Programs that must exist for conversion: # DxfToIv - converts .dxf (AutoCAD) to .iv (Inventor) format # ivToVRML - converts .iv (Inventor) to .wrl (Virtual Web) format # pfbounds - looks at an .iv and displays the bounds in the x, y, and # z-coordinates # pftransform - converts .iv (Inventor) to .pfb (Performer) which can # can be displayed in the CAVE with 'pfnav' # ############################################################################ # # Command Line Instructions: # # DXFconvert [input.dxf file] [scale factor] [x-rotation angle] # [y-rotation angle] [z-rotation angle] # # For example: # DXFconvert EXAMPLE.DXF 0.80 90 0 0 # # This generates: EXAMPLE.iv - the inventor file # EXAMPLE.bounds - text file with the bounds of the # drawing for the x, y, and z-coordinates # EXAMPLE.wrl - the VRML file # EXAMPLE.pfb - the Performer file, which has been # rotated 90 degrees around the x-axis, and scaled # down 80% # # NOTE: You can leave the rotation angles and scale factor blank. If you # leave the rotation angles blank, the default script values will be used. # As well, you can set a scale factor default or have the program generate # the best suitable one for you. By passing in a scale of 0.0 (or leaving # blank), it reverts to the default, which is to calculate a good scale # factor. # ############################################################################ # # Set Default Variables # # Filenames # set inputDXF = "" set outputIV = "" set outputVRML = "" set outputPFB = "" set outputBounds = "" # # Rotation Angles # set Xangle = -90 set Yangle = 0 set Zangle = 0 # # Scale Maximum Values # --- Maximum values to scale the coordinates to. For example, the VT CAVE # is 120in. x 120in. x 120in., so a good maximum value would be # 100in. for each dimension # set XMAX = 100.0; set YMAX = 100.0; set ZMAX = 100.0; # # Scale Factor # # NOTE: You can set a scale factor other than 0. If default is 0, and no # scale is passed to the command line, then one is generated. If you # specify a non-zero default or one on the commandline it uses the value # you set (and does not calculate one). # set scale = 0 # ############################################################################# # Process Command Line # # If no command arguments, ERROR if ($#argv < 1) then echo "No input .dxf file specified." exit 1 endif # # Set Scale Factor if passed in if ($#argv > 1) then set scale = $argv[2] endif # # Set X-rotation angle if passed in if ($#argv > 2) then set Xangle = $argv[3] endif # # Set Y-rotation angle if passed in if ($#argv > 3) then set Yangle = $argv[4] endif # # Set Z-rotation angle if passed in if ($#argv > 4) then set Zangle = $argv[5] endif # Assign Filenames # set inputDXF = $argv[1] set outputIV = ${inputDXF:r}'.iv' set outputVRML = ${inputDXF:r}'.wrl' set outputPFB = ${inputDXF:r}'.pfb' set outputBounds = ${inputDXF:r}'.bounds' # # #First Step in the Conversion Process: # # Convert from .dxf to .iv format using 'DxfToIv' # echo echo "***** Converting .dxf to .iv format...." DxfToIv $inputDXF $outputIV echo "***** Finished." #Second Step in the Conversion Process: # # Convert from .iv to .wrl format using 'ivToVRML' # echo echo "***** Converting .iv to .wrl format...." ivToVRML -o $outputVRML $outputIV echo "***** Finished." #Third Step in the Conversion Process: # # Check the bounds. If Scale = 0, the default, then run the 'pfbounds' # program and check the bounds. Approximate a scale factor if needed. # If scale is not = 0, then a scale factor has been specified already, # and don't bother running the 'pfbounds' program. # echo echo "***** Verifying the bounds of the .iv file...." pfbounds $outputIV > $outputBounds echo "***** Finished." if ($scale == 0) then echo echo "***** Calculating Scaling Factor...." set scale = `scaleBounds $outputBounds $XMAX $YMAX $ZMAX` echo "***** Finished." endif #Final Step in the Conversion Process: # # Run 'pftransform' on the .iv (Inventor) file and convert to .pfb # (Performer) format. # echo echo "***** Transforming .iv to .pfb format...." pftransform -r $Xangle $Yangle $Zangle -s $scale $outputIV $outputPFB echo "***** Finished." echo echo "Input AutoCAD .dxf file: $inputDXF" echo echo "Created Inventor file... $outputIV" echo "Created VRML file... $outputVRML" echo "Created Performer file... $outputPFB" echo echo "X-Rotation Angle: $Xangle" echo "Y-Rotation Angle: $Yangle" echo "Z-Rotation Angle: $Zangle" echo "Scaling Factor: $scale" echo echo "DXFconvert version 1.0. 1997 Heath P. Beres." echo exit 0