Newsgroups: alt.cad.autocad
Date:         Mon, 21 Dec 1992 14:44:59 -0700
From:         Rebecca Esparza <rebeccae@KINGTUT.COLORADO.EDU>
Subject:      Re: NET stuff

In the spirit of sharing.....

This is a Sun script routine I typed in from Cadence December 1992.  It searches
for a partial name of a drawing and opens it.  I've found it VERY handy.
Does anyone know where I would find stuff like this already typed in?

Rebecca
rebeccae@kingtut.colorado.edu

--------------------------------------------------------------------------------
# Parameters: subdirectory under /kingtut/drawings to start looking for a
# drawing and a drawing name (or substring of a drawing name).
# This script was written for SunOS 4.1.1.  It may have to
# be modified for other flavors of Unix.
#

# Set up the environment vairiables needed for AutoCAD.
# These need to be customized for your environment.
#setenv ACAD "/kingtut/tools/acad/acad;/kingtut/tools/acad/sample"
#setenv ACADBGCOLOR black
#setenv ACADCFG /kingtut/users/rebeccae/config1

# Set up the top level starting search point.
# This should be changed for your environment.
set topdir = /kingtut/drawings

# If no parameters then prompt for a drawing name or drawing name
# substring.
if ($2 == "") then
  if ($1 == "") then
    echo -n "Enter drawing name: "
    set fname = $<
  else
    set fname = $1
  endif

# Show user list of project directories and prompt to pick one.
  \ls $topdir/
  echo -n "Enter project (or return to search all of $topdir): "
  set startdir = $topdir/$<
else
  set fname = $2
  set startdir = $topdir/$1
endif

# If user used the .dwg extension then strip it off, add wild-card
# character to each side of it and put .dwg back on.
set fname = `basename $fname .dwg`
set fname = "*$fname*.dwg"

echo ""

# Check to see if the starting point is a directory.  If it is,
# then continue.
# If not, then exit with error message.
if (-d $startdir) then
  if (-e /tmp/findsfile) then
    \rm -f /tmp/findsfile
  endif
# Issue the find command and direct outpot to a temporary file.
# Must have the / at the end of $startdir for the find command to
# follow $startdir if it is a link.

  echo "    Searching..."
  find $startdir/ -name "$fname" -print > /tmp/findsfile

# Count the number of files that were found matching the criteria.
  set numfiles = `wc -l < /tmp/findsfile`
# If none were found, then exit with a message.
  if ($numfiles == 0) then
     echo "No files found...exiting."
     \rm -f /tmp/findsfile
     exit 0
# If one was found, then change to that directory and start
# AutoCAD.
  else if ($numfiles == 1) then
     echo -n "Found "
     cat /tmp/findsfile
     set fullname = `cat /tmp/findsfile`
     set dname = `/bin/dirname $fullname`
     set fname = `basename $fullname`
     echo "Changing directory to $dname"
     cd $dname
     echo "Starting AutoCAD..."
     acad $fname &
     \rm -f /tmp/findsfile
     exit 0
  else
     echo "Found more than one file matching description: "
     echo ""
# Display the file with line numbers
     cat -n /tmp/findsfile
     echo ""
     echo -n "Enter number of file you'd like to edit (or return to quit): "
     set fnum = $<
# If user enters just a return, then clean up and exit.
     if ($fnum == "") then
       \rm -f /tmp/findsfile
     exit 0
     endif
# Use the awk program to get the filename associated with user's
# entry.
     set fullname = `awk "NR == $fnum {print}" /tmp/findsfile`
     \rm -f /tmp/findsfile
     set dname = `/bin/dirname $fullname`
     set fname = `basename $fullname`
     echo "Changing directory to $dname"
     cd $dname
     echo "Starting AutoCAD..."
     acad $fname &
     \rm -f /tmp/findsfile
     exit 0
  endif
else
  echo "$startdir does not exist...try again."
  \rm -f /tmp/findsfile
  exit 0
endif

#=========================================================================
# Modification History:
#
# Date          By              Changes
# #
#
#
#=========================================================================