Author Topic: DCL file to Lisp subroutine  (Read 7947 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
DCL file to Lisp subroutine
« on: April 24, 2004, 05:38:02 PM »
For those of you that have a dcl file to include with a lisp offering,
this method eliminates the need for two files and assures it is placed
in the ACAD search path.

A subroutine is needed to create the dcl file when the main lisp is
run for the first time. That is what this routine does.
Run the Dcl2Lisp routine on the dcl file you want to include and it
will create a new file called YourName-dcl.lsp where "YourName" is
the name of the original dcl file. Then copy the contents of the new
lisp file into the main lisp routine.
Add a call to the new function like this ( create_dcl "YourName" )
If the dcl file exist the routine returns, If the file is not found
it creates the needed dcl file in the same directory where ACAD.PAT
if found, usually /SUPPORT/

If the needed dcl file is deleted by mistake the lisp routine will
create another one.

CAB
Code: [Select]
;;;  Dcl2Lisp.lsp by Charles Alan Butler
;;;         Copyright 2004
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at TheSwamp.org
;;;
;;;   Version 1.0 Beta  April 24, 2004
;;;   Version 1.1 Beta  June 25, 2004
;;;     Formatting Bug fix
;;;   Version 1.2 Beta  July 4, 2004
;;;     Added code to detect a Revision flag & overwrite the DCl
;;;     file if different
;;;
;;; DESCRIPTION
;;; This routine creates the function that will create a dcl file
;;; if the dcl file is not found. You select the original dcl file
;;; and this routine writes a new file containing the lisp routine
;;; needed to create the dcl file.
;;; I think that confused me! :)
;;; Creates the lisp file in the same directory as the dcl file
;;; was found. The Lisp file created will create the dcl file in
;;; the same directory as ACAD.PAT is located.
;;;
;;;  Limitations : Unknown at this time
;;;
;;; Command Line Usage to create the lisp
;;; Command: Dcl2Lisp
;;;
;;; To call the new routine you may use something like this:
;;;
;|
  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ;;  Check the Dialog Box
  (setq dclfile "<file name>.dcl")
  (cond
    ((not (create_dcl dclfile)) ; check version
     (alert (strcat "Cannot find " dclfile))
    )
    ((< (setq dcl# (load_dialog dclfile)) 0) ; Error
     (prompt (strcat "\nCannot load " dclfile "."))
    )
    ((not (new_dialog "<your dcl name>" dcl#)) ; Error
     (prompt (strcat "\nProblem with " dclfile "."))
    )
    ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    (t ; No DCL problems: ok to fire it up
      ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
     
      ;;
      ;;  run your DCL routine now
      ;;
     
    )
  ) ; end cond stmt

  ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|;
;;;
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;                                                                    ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice below appear in all supporting documentation.              ;
;;;  You must contact me if you want to use it commercially            ;

(defun c:Dcl2Lisp (/ files fn fname dlist ln newln x)
  ;;  User pick DCL source file w/ path
  (setq files (getfiled "Select the DCL source file:" "" "dcl" 0))
  (if files
    (progn
      ;;  Create Destination file name "SourceName-dcl.lsp"
      (setq fname (strcat
                    (substr files 1 (- (strlen files) 4)) "-dcl.lsp")
      )
      ;;  Create a Revision Flag Using current Date & Time
      (setq tmp (rtos (getvar 'cdate) 2 4)
            rvprefix "//  Revision Control ")
      (setq rvflag (strcat  rvprefix
                       (substr tmp 5 2) "/" (substr tmp 7 2) "/"
                       (substr tmp 1 4) "@" (substr tmp 10 2) ":"
                       (substr tmp 12 2)
                   )
      )
      ;;  Create the detination file in same
      ;;   directory as the DCL source file
      (setq fn (open fname "w"))
      ;;  Open the source file
      (setq files (open files "r"))

      ;;  Write header to destination file
      (setq dlist
             (list
                ";; ***************************************************"
                ";;     create_dcl  function to create a dcl support   "
                ";;                 file if it does not exist          "
                ";;     Usage : (create_dcl \"file name\")               "
                ";;     Returns : T if successful else nil             "
                ";; ***************************************************"
                "(defun create_dcl (fname / acadfn dcl-rev-check)"
                "  ;;======================================="
                "  ;;      check revision date Routine          "
                "  ;;======================================="
                "  (defun dcl-rev-check (fn / rvdate ln lp)"
                "    ;;  revision flag must match exactly and must"
                "    ;;  begin with //"
                (strcat "    (setq rvflag \"" rvFlag "\" )" )
                "    (if (setq fn (findfile fn))"
                "      (progn ; check rev date"
                "        (setq lp 5) ; read 4 lines"
                "        (setq fn (open fn \"r\")) ; open file for reading"
                "        (while (> (setq lp (1- lp)) 0)"
                "          (setq ln (read-line fn)) ; get a line from file"
                "          (if (vl-string-search rvflag ln)"
                "            (setq lp 0)"
                "          )"
                "        )"
                "        (close fn) ; close the open file handle"
                "        (if (= lp -1)"
                "          nil ; no new dcl needed"
                "          t ; flag to create new file"
                "        )"
                "      )"
                "      t ; flag to create new file"
                "    )"
                "  )"
                "  (if (null(wcmatch (strcase fname) \"*`.DCL\"))"
                "    (setq fname (strcat fname \".DCL\"))"
                "  )"
                "  (if (dcl-rev-check fname)"
                "    ;; create dcl file in same directory as ACAD.PAT  "
                "    (progn"
                "      (setq acadfn (findfile \"ACAD.PAT\")"
                "            fn (strcat (substr acadfn 1 (- (strlen acadfn) 8))fname)"
                "            fn (open fn \"w\")"
                "      )"
                "      (foreach x (list"
                "                   \"// WARNING file will be recreated if you change the next line\""
                "                   rvflag"

              ) ; end list
      ) ; end setq
      ;;  Wright the Header
      (foreach x dlist (princ x fn) (write-line "" fn))

      ;;  Add DCL file to output file
      ;;  Loop, reading source, writting to destination file
      (while (setq ln (read-line files)) ; get a line from file
        (cond
          ((or (vl-string-search rvprefix ln); found a revision flag
               (vl-string-search "// WARNING file" ln); found Warning Line
           )
           (setq ln nil) ; delete it
           ) ; end cond
          ((vl-string-search "\"" ln); found a quote char
            ;;  Add backslash to hide quotes
            (setq ln    (vl-string->list ln)
                  newln nil
            )
            (foreach x ln
              (if (= x 34)(setq newln (cons 92 newln)))
              (setq newln (cons x newln))
            ) ; end foreach
            (setq ln (vl-list->string (reverse newln)))
          ) ; end cond
        ) ; end cond stmt
        (if ln
          (progn
            ;;  add line to output file
            (princ (strcat "                   \"" ln "\"") fn)
            (write-line "" fn) ; add CR
          )
        )
      ) ; end while

      ;;  Create the footer code in a list
      (setq dlist
             '("                  ) ; endlist"
               "        (princ x fn)"
               "        (write-line \"\" fn)"
               "      ) ; end foreach"
               "      (close fn)"
               "      (setq acadfn nil)"
               "      (alert (strcat \"\\nDCL file created, please restart the routine\""
               "               \"\\n again if an error occures.\"))"
               "      t ; return True, file created"
               "    )"
               "    t ; return True, file found"
               "  )"
               ") ; end defun"
              ) ; end list
      ) ; end setq
      ;;  Write footer to destination file
      (foreach x dlist (princ x fn) (write-line "" fn))

      ;;  Close source & Destination files
      (close fn)
      (close files)
      (prompt (strcat "\nFile Created --> " fname))
    ) ; end progn
    (prompt "\n***--  User Quit  --***")
  ) ; endif FileS
  (princ)
) ; end defun
(prompt "\n***--  Dcl2Lisp loaded, Enter Dcl2Lisp to run.  --***")
(princ)
;;        End Of File         
« Last Edit: November 08, 2014, 02:11:43 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
DCL file to Lisp subroutine
« Reply #1 on: April 24, 2004, 05:46:03 PM »
This is a sample of the file that is created:
Code: [Select]
;; ***************************************************
;;     create_dcl  function to create a dcl support  
;;                 file if it does not exist          
;;     Usage : (create_dcl "file name")              
;;     Returns : T if successful else nil            
;; ***************************************************
(defun create_dcl (fn / acadfn)
  (if (null (wcmatch (strcase fn) ".DCL"))
    (setq fn (strcat fn ".DCL"))
  )
  (if (not (findfile fn))
    ;; create dcl file in same directory as ACAD.PAT  
    (progn
      (setq acadfn (findfile "ACAD.PAT")
            fn (strcat (substr acadfn 1 (- (strlen acadfn) 8))fn)
            fn (open fn "w")
      )
      (foreach x '(
                   "dhatch : dialog {"
                   "label = \"Quick Hatch\" ;"
                   "      : list_box {"
                   "      label = \"Choose Pattern:\";"
                   "      key = \"selections\";"
                   "      }"
                   "      : edit_box {"
                   "      key = \"eb1\";"
                   "      edit_limit = 5;"
                   "      edit_width = 6;"
                   "      label = \"Hatch Scale:\";"
                   "      }"
                   "   ok_cancel ;"
                   "}"
                  ) ; endlist
        (princ x fn)
        (write-line "" fn)
      ) ; end foreach
      (close fn)
      (setq acadfn nil)
      t ; return True
    ) ; end progn
    nil ; return nil
  ) ; endif
) ; end defun


From this dcl file:
Code: [Select]
dhatch : dialog {
label = "Quick Hatch" ;
      : list_box {
      label = "Choose Pattern:";
      key = "selections";
      }
      : edit_box {
      key = "eb1";
      edit_limit = 5;
      edit_width = 6;
      label = "Hatch Scale:";
      }
   ok_cancel ;
}
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
DCL file to Lisp subroutine
« Reply #2 on: April 24, 2004, 09:56:23 PM »
You must have been reading my hard drive.... I was working on just such a routine last week.....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
DCL file to Lisp subroutine
« Reply #3 on: April 24, 2004, 10:28:45 PM »
I must have caught your vibes... :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
DCL file to Lisp subroutine
« Reply #4 on: April 25, 2004, 08:25:45 PM »
Hey I went out of Horseshoe today... first we had a time with the ladyfish eating all of the bait, then we managed to find a nice spot with lots of spanish mackerel... later in the day we went to the end of the jetties and tore up the sheepshead....it was a good day... despite the fishing report...I think sometimes the fishing guys say that just to keep us amatures out of the water...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
DCL file to Lisp subroutine
« Reply #5 on: April 25, 2004, 10:37:50 PM »
Man, I jealous... :?

Sounds like you had plenty of action. Lady fish are fun to catch.
Awfully slimy though. And those spanish, good eating.
Sheepshead are fun to catch but I'm not much for eating them.
Although I don't throw them back, unless there are under size..

Seems like all I do is talk & dream of fishing. I got to get out more.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
DCL file to Lisp subroutine
« Reply #6 on: April 26, 2004, 01:44:28 PM »
everything we caught was legal with the exception of one sheepshead that was only 8" ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
DCL file to Lisp subroutine
« Reply #7 on: April 26, 2004, 02:40:41 PM »
Yep, that's cool!  

I worked on that idea too once (in fact, I used an "on the fly dialog" in that Binny progy) but never got that (^) far. ...great job man.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
DCL file to Lisp subroutine
« Reply #8 on: June 25, 2004, 08:20:37 AM »
Updated this routine if anyone interested.
Just recopy the code in the first post.
Minor Bug fix.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nivuahc

  • Guest
DCL file to Lisp subroutine
« Reply #9 on: June 29, 2004, 07:39:43 AM »
What a great piece of code!

And, regarding eating sheepshead... we used to do one of two things with them. Either we used them to make seafood patties (mix with breadcrumbs, butter, onions, egg... form into patties and fry) or we wrapped the whole fish (sans the stinky bits) in cheesecloth and dropped it in crab boil.

Sheepshead is very similar to crab meat in texture and taste when cooked properly.


...goes off to start a fishing thread in Lagniappe