home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxacad.txt < prev    next >
Text File  |  1995-06-27  |  18KB  |  580 lines

  1. Just thought I would share something that really makes it 
  2. nice to run Acad under OS/2!
  3. You can save your acad windows size to something small so
  4.  then you have room to work on other stuff.
  5. I used to do this under Unix using csh but then when I 
  6. found out how much better REXX is (csh can't work on 
  7. units smaller than strings) I now do this stuff under OS/2.
  8. I use REXX to make automated mass changes to multiple 
  9. acad dwg.s.  This is how (and why acad should be made 
  10. to work under OS/2):
  11. The following sections should be cut and saved to separate
  12.  ascii files and run as REXX cmd programs.
  13. Any problems/questions let me know.
  14. version 2:  Changed some prompts to look better.
  15.                Added a couple of rexx routines.
  16.                Added another piece of functionality to the main
  17.                  acad_run_scr_array.cmd routine.  See Below.
  18. Problems:  Programs in OS/2 seem to steal the Focus at different
  19.                 times from the user, like when they first start up. Because
  20.                the main acad run scr array.cmd routine is constantly
  21.                going into and out of autocad it is constantly stealing the
  22.                Focus from the user.  THIS IS LOUSY!  This does not happen
  23.                in Unix.  IBM needs to fix this problem.  I wrote to them about
  24.                this a long time ago and just recently and they said they have
  25.                it written down but do not have it as a problem to be worked
  26.                on.  They said to send in a problem report.  We need to complain
  27.                to get this fixed!
  28. Stan Towianski - CompuServe 74403,205
  29.  
  30. ==================================================
  31. /* c:\startup.cmd - called at boot time */
  32. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  33. call SysLoadFuncs
  34. exit
  35. ==================================================
  36.  
  37. ==================================================
  38. /* mklist.cmd */
  39. /* written by Stan Towianski  November 1994 */
  40. /*  This let's you easily get a list of files you want to modify.
  41. **  It gives you a file called "manylist" which is a list of files
  42. **  from the directories you input.  This list can then be simply
  43. **  editted and used directly by the "acad_run_scr.cmd" routine
  44. **  below.
  45. */
  46.  
  47. start_time=time()
  48. debug_flag = n
  49.  
  50. say "Enter full paths of directories to include 1 per line."
  51. say "or enter just directory name to have me assume path"
  52. say "from previous line."
  53. say "Enter 'end' when done."
  54. i=0
  55. parse upper pull ans
  56. pathlist.i = ans
  57. lp = lastpos( '\', pathlist.i )
  58. prev_path = substr( pathlist.i, 1, lp )
  59. pathlist.i = pathlist.i||"\*.dwg"
  60. say "path #" i "is "pathlist.i
  61. Do until ( ans = "END" )
  62.     i = i + 1
  63.     parse upper pull ans
  64.     pathlist.i = ans
  65.     lp = lastpos( '\', pathlist.i )
  66.     if ( lp = 0 ) then
  67.         pathlist.i = prev_path||pathlist.i
  68.      else
  69.         prev_path = substr( pathlist.i, 1, lp )
  70.     pathlist.i = pathlist.i||"\*.dwg"
  71.     say "path #" i "is "pathlist.i
  72. End
  73. max_path_idx = i - 1
  74. say "max_path_idx ="max_path_idx
  75.  
  76. /* open output file */
  77. if ( debug_flag = y ) then say "file 1 is manylist"
  78. if stream(manylist,"c",'query exists') \= '' then
  79.     DO
  80.     del manylist
  81.     say deleted preexisting file
  82.     END
  83. rc = stream(manylist,"c",'open write')
  84.  
  85. do i = 0 to max_path_idx
  86.     pathlist = pathlist.i
  87.     call SysFileTree pathlist, filelist.i, "FS", "*****"
  88.     say number of files is filelist.i.0
  89.  
  90.     Do fcount = 1 to filelist.i.0
  91.         tfile = word( filelist.i.fcount, 5 )
  92.         say "working with file # [" fcount "] = " tfile
  93.         rc = lineout( manylist, tfile)
  94.         say "lineout rc ="rc
  95.      End
  96. end /* do */
  97.  
  98. rc = stream(manylist,"c","close")
  99. say "Start Time = "start_time
  100. say "End   Time = "time()
  101. exit
  102. ==================================================
  103.  
  104. ==================================================
  105. /* mksixs.cmd program */
  106. /* written by Stan Towianski  November 1994 */
  107. /** Makes numbered .scr acad script files from a file list.
  108. **/
  109. start_time = time()
  110. debug_flag = n
  111.  
  112. rc=charout(  ,  "File list to subdivide ? " )
  113. parse upper pull in_file
  114.  
  115. rc = stream(in_file,"c",'open read')
  116. If rc \= 'READY:' then
  117. Do
  118.     say 'Problem with file ' in_file
  119. End
  120. prev_path = filespec( "path", in_file )
  121.  
  122. rc=charout(  ,  "Directory to save files to ("prev_path") ? " )
  123. parse upper pull out_file_path
  124. if ( out_file_path = '' ) then
  125.     out_file_path = prev_path
  126. else
  127.     Do
  128.     if ( right( out_file_path, 1 ) \= '\' ) then
  129.         out_file_path = out_file_path||"\"
  130.     End
  131.  
  132. rc = stream(out_file_path,"c",'query exists')
  133. If rc \= '' then
  134. Do
  135.     say 'Problem with file ' out_file_path
  136. End
  137.  
  138. filenum = 1
  139. done_flag = no
  140. Do until lines(in_file) = 0 | done_flag = yes
  141.     /* open output file */
  142.     out_file = out_file_path||"many"||filenum||".scr"
  143.     say "Working on file "out_file
  144.     if ( debug_flag = y ) then say "file 1 is "out_file
  145.     if stream(out_file,"c",'query exists') \= '' then
  146.         DO
  147.         del out_file
  148.         say deleted preexisting file
  149.         END
  150.     rc = stream(out_file,"c",'open write')
  151.  
  152.     rc = lineout( out_file, "attreq 0")
  153.     ins_val = 0
  154.     Do count = 1 to 6
  155.         if ( lines(in_file) = 0 ) then
  156.             Do
  157.             say "Quiting on end of file"
  158.             done_flag = yes
  159.             leave
  160.             End
  161.         Parse value linein(in_file) with in_line
  162.         tline = "insert "in_line
  163.         rc = lineout( out_file, tline)
  164.         tline = "0,"ins_val
  165.         rc = lineout( out_file, tline)
  166.         rc = lineout( out_file, "")
  167.         rc = lineout( out_file, "")
  168.         rc = lineout( out_file, "")
  169.         ins_val = ins_val + 24
  170.     End
  171.     rc = lineout( out_file, "_zoom e")
  172.     tline = "_saveas c:\pwd\manypl"||filenum
  173.     rc = lineout( out_file, tline)
  174.     rc = lineout( out_file, "quit y")
  175.  
  176.     rc = stream(out_file,"c","close")
  177.     filenum = filenum + 1
  178. /*
  179.     if ( filenum > 15 ) then
  180.         done_flag = yes
  181. */
  182. end /* do */
  183.  
  184. rc = stream(in_file,"c","close")
  185. say "Start Time = "start_time
  186. say "End   Time = "time()
  187. exit
  188. ==================================================
  189.  
  190. ==================================================
  191. /* acad_run_scr.cmd */
  192. /* written by Stan Towianski  November 1994 */
  193. /*  This routine works on files in a file list and brings each dwg up
  194. **  in acad and runs the chosen script on it, and so on for each
  195. **  dwg in the list.  Great when you need to modify a bunch of
  196. **  dwg's from one companies standard layering scheme etc... to
  197. **  anothers!
  198. ** Version 2:  Fixed a problem:  In the other wait loop scheme I think it waited 30 seconds
  199. **      and then started looking to see if the xx.dwk (lock file) was gone which assumed
  200. **      that acad was done with that process.  Unfortunately if the session had a problem
  201. **      and stopped and never created a xx.dwk file my loop thought it was done and would
  202. **      start the next acad session resulting in multiple sessions!  And worse was if the 2nd
  203. **      session had a problem (usually the same one) the same would happen and another
  204. **      session would get spawned and you would end up with acad starting all over the
  205. **      place.  So I now do better by waiting for an initial xx.dwk file so I know it started
  206. **      and then wait for it (xx.dwk) to leave meaning it finished.
  207. **      1.)  The first way is to create your list of files to work on thru mklist.cmd, then edit
  208. **      the list, then run acad_run_scr_array.cmd to have it bring up each dwg in the list
  209. **      and run the designated script on it.
  210. **      2.)  I also added the ability to start acad with a none file "x.dwg" and then have it
  211. **      run an array of scripts on this (blank) x.dwg.  The x.dwg is just a placeholder to start
  212. **      acad with no particular dwg.  Here I want to start with a blank dwg and run a script1
  213. **      to do what I want, in my case insert say 6 files and save it as one file many1.dwg.
  214. **      Then open x.dwg (blank) and run script2.scr (insert 6 dwg.s) and save to many2.dwg
  215. **       I was doing this to insert 6 dwg.s onto one to plot them and save paper.  Inserting
  216. **       multiple dwg.s has it's own headache though if one dwg has a layer "basic" that is
  217. **       thawed and the next has a "basic" layer unthawed, because the x.dwg set layer "basic" 
  218. **       to thawed and makes any later inserted layer "basic" take the first value of thawed
  219. **       meaning you miss the layer on the x.dwg which has the 6 dwg.s
  220. */
  221.  
  222. start_time=time()
  223. debug_flag = n
  224.  
  225. Do Until ( good_setup = "YES" )
  226.     rc=charout(   ,  "File list to work from or 'X' for none ? " )
  227.     parse upper pull in_file
  228.     if ( in_file \= 'X' ) then
  229.         Do
  230.         do_filelist=YES
  231.         rc = stream(in_file,"c",'open read')
  232.         If rc \= 'READY:' then
  233.             Do
  234.             say 'Problem with file ' in_file
  235.             exit
  236.             End
  237.         End
  238.     else
  239.         Do
  240.         in_line="x.dwg"
  241.         do_filelist=NO
  242.         End
  243.  
  244.     rc=charout(  , "AutoCAD script to run ? " )
  245.     parse upper pull script
  246.     if ( right( script, 4 ) = ".SCR" ) then
  247.         Do
  248.         script=left( script, length( script ) - 4 )
  249.         End
  250.  
  251.     rc=charout(  , "Do you want to run an array script (no) ? " )
  252.     parse upper pull ans
  253.     do_array=ck_yn( ans, "FULL", "NO" )
  254.     if ( do_array = "YES" ) then
  255.         Do
  256.         do_array = YES
  257.         rc=charout(  , "Starting index ? " )
  258.         parse upper pull array_start
  259.         rc=charout(  , "Maximum index ? " )
  260.         parse upper pull array_max
  261.         End
  262.     else
  263.         Do
  264.         do_array = NO
  265.         array_start = 1
  266.         array_max = 1
  267.         End
  268.  
  269.     if ( do_array = YES ) then
  270.         say "Will do array scripts from "script||array_start" to "script||array_max
  271.     else
  272.         say "Will do single script "script
  273.     rc = charout(    ,   "Is this correct (yes) ? " )
  274.     parse upper pull ans
  275.     say
  276.     good_setup=ck_yn( ans, "FULL", "YES" )
  277. End  /* until */
  278.  
  279.  
  280. /*
  281. if ( stream(script||".scr","c",'query exists') = '' ) then
  282.     DO
  283.     say script||".scr file does not exist"
  284.     exit
  285.     END
  286. */
  287.  
  288. fcount=1
  289. done = NO
  290. Do until done = YES
  291.     if ( do_filelist = YES ) then
  292.         Do
  293.         in_line = linein(in_file)
  294.         /* the line below will run acad in win-os2 full screen - not as useful
  295.            cannot keep working on other stuff
  296.         */
  297.         /*    line="c:\acadwin\acad" in_line script*/
  298.             baseline="start /win /min c:\acadwin\acad" in_line script
  299.             point=lastpos( '.dwg', in_line )
  300.             dwk_file=overlay( '.dwk', in_line, point )
  301.             del_bak="del "||overlay( '.bak', in_line, point )
  302.         End
  303.     else
  304.         Do
  305.             baseline="start /win /min c:\acadwin\acad" x script
  306.             dwk_file="c:\acadwin\x.dwk"
  307.             del_bak=''
  308.         End
  309. /*    say "before loop line ="baseline"="*/
  310.  
  311.     Do count = array_start to array_max
  312.         if ( do_array = YES ) then
  313.             Do
  314.             line=baseline||count
  315.             End
  316.         else
  317.             line=baseline
  318.  
  319. /*        say "would do line ="line"="*/
  320.         say "[dwg "fcount", script "count"]"
  321.         line
  322.  
  323.         /* Look for initial .dwk file to signify it started */
  324.         hold_on=yes
  325.         do while( hold_on = yes )
  326.             say "waiting for initial lock file "dwk_file
  327.             if ( stream( dwk_file, 'c', 'query exists' ) \= '' ) then
  328.                 Do
  329.                 hold_on=no
  330.                 End
  331.             else
  332.                 Do
  333.                 say "sleeping 3 seconds"
  334.                 say "[dwg "fcount", script "count"]"
  335.                 call SysSleep 3
  336.                 End
  337.         End
  338.  
  339.         hold_on=yes
  340.         do while( hold_on = yes )
  341.             say "waiting for lock file to leave"dwk_file
  342.              if ( stream( dwk_file, 'c', 'query exists' ) = '' ) then
  343.                  do
  344.                  hold_on=no
  345.                  end
  346.             else
  347.                 Do
  348.                 say "sleeping 3 seconds"
  349.                 say "[dwg "fcount", script "count"]"
  350.                 call SysSleep 3
  351.                 End
  352.         End
  353.         del_bak
  354.     end /* do */
  355.  
  356.     if ( do_filelist = YES ) then
  357.         Do
  358.         if ( lines(in_file) = 0 ) then done = YES
  359.         End
  360.     else
  361.         Do
  362.         done = YES
  363.         End
  364.     fcount = fcount + 1
  365. end /* do */
  366.  
  367. if ( do_filelist = NO ) then
  368.     Do
  369.     rc = stream(in_file,"c","close")
  370.     End
  371. say "Start Time = "start_time
  372. say "End   Time = "time()
  373. exit
  374. ==================================================
  375.  
  376. ==================================================
  377. ==================================================
  378. /* ck_yn */
  379.  
  380. test=substr( arg(1), 1, 1 )
  381. /*say "will test char ="test"="*/
  382. if ( arg(1) = ''  ) then
  383.     Do
  384.     ans=arg(3)
  385.     End
  386. else if ( test = Y | test = y ) then
  387.     Do
  388.     ans=YES
  389.     End
  390. else if ( test = N | test = n ) then
  391.     Do
  392.     ans=NO
  393.     End
  394. else
  395.     Do
  396.     return ERROR
  397.     End
  398.  
  399. if ( arg(2) = "FULL" ) then
  400.     return ans
  401. else
  402.     return substr( ans, 1, 1 )
  403.  
  404. ==================================================
  405. /* mkplotr12.cmd */
  406. /* written by Stan Towianski  February 1995 */
  407. /**  Makes a plotr12.scr file from all dwg.s in the directories you give to plot
  408. **   all the files.  Plot one file first to get setting correct.
  409. **   Then run acadplot.cmd
  410. **/
  411. start_time=time()
  412. debug_flag = n
  413.  
  414. say "Enter full paths of directories to include 1 per line."
  415. say "or enter just directory name to have me assume path"
  416. say "from previous line."
  417. say "Enter 'end' when done."
  418. i=0
  419. parse upper pull ans
  420. pathlist.i = ans
  421. lp = lastpos( '\', pathlist.i )
  422. prev_path = substr( pathlist.i, 1, lp )
  423. pathlist.i = pathlist.i||"\*.dwg"
  424. say "path #" i "is "pathlist.i
  425. Do until ( ans = "END" )
  426.     i = i + 1
  427.     parse upper pull ans
  428.     pathlist.i = ans
  429.     lp = lastpos( '\', pathlist.i )
  430.     if ( lp = 0 ) then
  431.         pathlist.i = prev_path||pathlist.i
  432.      else
  433.         prev_path = substr( pathlist.i, 1, lp )
  434.     pathlist.i = pathlist.i||"\*.dwg"
  435.     say "path #" i "is "pathlist.i
  436. End
  437. max_path_idx = i - 1
  438. say "max_path_idx ="max_path_idx
  439.  
  440. /* open output file */
  441. if ( debug_flag = y ) then say "file 1 is plotr12.scr"
  442. if stream(plotr12.scr,"c",'query exists') \= '' then
  443.     DO
  444.     del plotr12.scr
  445.     say deleted preexisting file
  446.     END
  447. rc = stream(plotr12.scr,"c",'open write')
  448.  
  449. do i = 0 to max_path_idx
  450.     pathlist = pathlist.i
  451.     call SysFileTree pathlist, filelist.i, "FS", "*****"
  452.     say number of files is filelist.i.0
  453.  
  454.     Do fcount = 1 to filelist.i.0
  455.         tfile = word( filelist.i.fcount, 5 )
  456.         say "working with file # [" fcount "] = " tfile
  457.         rc = lineout( plotr12.scr, "plot" )
  458.         rc = lineout( plotr12.scr, tfile )
  459.         rc = lineout( plotr12.scr, "e" )
  460.         rc = lineout( plotr12.scr, "n" )
  461.         rc = lineout( plotr12.scr, "lpt2" )
  462.         say "lineout rc ="rc
  463.      End
  464. end /* do */
  465.  
  466. rc = lineout( plotr12.scr, "quit" )
  467. rc = lineout( plotr12.scr, "y" )
  468.  
  469. rc = stream(plotr12.scr,"c","close")
  470. say "Start Time = "start_time
  471. say "End   Time = "time()
  472. exit
  473. ==================================================
  474.  
  475. ==================================================
  476. /* acadplot.cmd */
  477. cc="start /win /min /b c:\acadwin\acad -p c:\pwd\plotr12"
  478. cc
  479. ==================================================
  480.  
  481. ==================================================
  482. many1.scr    example array of script files.  would have many2.scr, many3.scr ...
  483. The attreq 0   says to not ask for attribute values upon inserting a dwg
  484. and just take the defaults.
  485. ==========
  486. attreq 0
  487. insert K:\CNTRL\M189PLOT\c65\189c6545.dwg
  488. 0,0
  489.  
  490.  
  491.  
  492. insert K:\CNTRL\M189PLOT\c65\189ecpl.dwg
  493. 0,24
  494.  
  495.  
  496.  
  497. insert K:\CNTRL\M189PLOT\c65\189c6506.dwg
  498. 0,48
  499.  
  500.  
  501.  
  502. insert K:\CNTRL\M189PLOT\c65\189c60l2.dwg
  503. 0,72
  504.  
  505.  
  506.  
  507. insert K:\CNTRL\M189PLOT\c65\189c6512.dwg
  508. 0,96
  509.  
  510.  
  511.  
  512. insert K:\CNTRL\M189PLOT\c65\189c6513.dwg
  513. 0,120
  514.  
  515.  
  516.  
  517. _zoom e
  518. _saveas c:\pwd\manypl1
  519. quit y
  520. ==================================================
  521.  
  522.  
  523. ==================================================
  524. /* ren_to_lower.cmd */
  525. /* written by Stan Towianski  November 1994 */
  526. /* Used to rename all filenames to lower case for use
  527. **  in a Unix/NFS environment.
  528. */
  529.  
  530. say "Start Time = "time()
  531. start_time=time()
  532. debug_flag = y
  533. filearg = "*"
  534.  
  535. if ( words(arg(1)) = 1 ) then
  536.     Do
  537.     treeoption = "F"
  538.     filearg = word(arg(1), 1)
  539.     say "Will work on input file list ="filearg
  540.     end
  541. else if ( words(arg(1)) = 2 ) then
  542.     Do
  543.     options = word(arg(1), 1)
  544.     filearg = word(arg(1), 2)
  545.     if ( (options = "-r") | (options = "-R") ) then
  546.         do
  547.         say "Got -R option"
  548.         treeoption = "BS"
  549.         end
  550.     else
  551.         treeoption = "F"
  552.     say "Will work on input file list ="filearg
  553.     end
  554. else
  555.     do
  556.     say "** Syntax error:  ren_to_lower {-r} files"
  557.     exit
  558.     end
  559.  
  560. call SysFileTree filearg, filelist, treeoption, "*****"
  561. say number of files is filelist.0
  562.  
  563.  
  564. Do fcount = 1 to filelist.0
  565.     tfile = word( filelist.fcount, 5 )
  566.     say "working with file # [" fcount "] = " tfile
  567.  
  568.     fpath = filespec( "drive", tfile)||filespec( "path", tfile )
  569.     upfile = filespec( "name", tfile )
  570.     lofile = translate( upfile, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
  571.     say "upfile ="upfile"="   "lofile ="lofile"="
  572.     say "Would do =rename "tfile lofile
  573.     rename tfile lofile
  574.  
  575. End
  576. say "Start   Time = "start_time
  577. say "End   Time = "time()
  578. exit
  579.  
  580.