A Program for a drafting test

A Program for a drafting test

harilalmn
Advocate Advocate
701 Views
2 Replies
Message 1 of 3

A Program for a drafting test

harilalmn
Advocate
Advocate

Dear All,

I request a help to fix this issue;

 

The Scenario:

We have to conduct a CAD test for candidates in our company. For this we give them a new drawing and a print out  of a floor plan. The test is for 30 minutes. 

I wrote a list program. By running the CADTEST command, lisp would save the current file at a location with the filename format as follows;

 

<candidate_name>_<timestamp>_<experience>yrs.dwg

 

The program will alert the candidate when it is 30 minutes and should save and force close the file when it is 35 minutes.

 

The Problem:

When I run it, it throws an error as follows;

error: no function definition: TO_MINUTES

 

My code is as follows. Could someone kindly help..??

(vl-load-com)

;;; ***********************************************************************************
;;; Global Declarations
;;; ***********************************************************************************

(setq started_at nil)
(setq diff nil)
(setq thisdoc nil)
(setq alerted nil)
(setq time_allowed 1)
(setq max_time_allowed 2)
(setq file_path "C:/Users/hari/Desktop/")


;;; ***********************************************************************************
;;; Function to return current timestamp
;;; ***********************************************************************************

(defun timestamp_now ( / timestamp yyyy mm dd h m s time_now)
  (setq timestamp (rtos (getvar "CDATE") 2 8))
  (setq yyyy (substr timestamp 1 4))
  (setq mm (substr timestamp 5 2))
  (setq dd (substr timestamp 7 2))
  (setq h (substr timestamp 10 2))
  (setq m (substr timestamp 12 2))
  (setq s (substr timestamp 14 2))
  (setq time_now (strcat dd "/" mm "/" yyyy " " h ":" m ":" s))
)


;;; ***********************************************************************************
;;; Function to extract minutes from timestamp
;;; ***********************************************************************************

(defun to_minutes (timestamp / h m minutes)
  (setq h (substr timestamp 10 2))
  (setq m (substr timestamp 12 2))
  (setq minutes (+ (* (atoi h) 60) (* (atoi m))))
)

;;; ***********************************************************************************
;;; Function to write logs
;;; ***********************************************************************************

(defun writelog (message / f)
  (setq   f (open (strcat file_path "Log.txt") "w"))
  (write-line (strcat (timestamp_now) message))
  (close f)
)

;;; ***********************************************************************************
;;; Function to Print Messages
;;; ***********************************************************************************

(defun print_it  ( / alerted)
  (if (eq diff time_allowed)
    (progn
      (if (eq alerted nil)
                (prompt
                  (strcat
                    "\nTIME UP. IT IS "
                    (itoa diff)
                    " minutes. Document will close automatically in "
                    (itoa (- max_time_allowed time_allowed))
                    " minutes."
                  )
                )
      )
    )
  )
  (if (eq diff max_time_allowed)
    (progn
      (vla-save thisdoc)
      (writelog (timestamp_now))
      (writelog "Document force-closed : ")
      (writelog file_name)
      )
      (vla-close thisdoc)
    )
  )


;;; ***********************************************************************************
;;; Function set up the environment
;;; ***********************************************************************************

(defun c:cadtest (/               name      experience     confirm
                                  time_now  file_name name      n               thisdoc
                                  now
                                )
  (while (eq name nil)

    (setq name (getstring T "\nCandidate Name: "))
    (setq experience
                   (itoa
                     (fix
                       (getreal
                                "\nHow many years of experience you have in AutoCAD?: "
                       )
                     )
                   )
    )
  )

  (textscr)
  (prompt
    "************************* INSTRUCTIONS **********************"
  )
  (prompt "Some instructions for test...")
  (prompt
    "\n\n\n*************************************************************\n\n\n"
  )

  (while (or (eq confirm nil) (eq confirm "No"))
    (initget 1 "Yes No")
    (setq confirm (getkword "\nStart the test now?[Yes/No]: "))
  )

  (setq n 1)
  (while (not (eq n nil))
    (setq name (vl-string-subst "_" " " name))
    (setq n (vl-string-search " " name))
  )

  (setq time_now (vl-string-subst "_" "." (rtos (getvar "CDATE") 2 4)))
  (setq   file_name
                (strcat
                   file_path
                   name
		              "_"
                   time_now
		              "_"
                   experience
		              "yrs"
                   ".dwg"
                  )
  )

  (setvar "FILEDIA" 0)
  (command "_SAVEAS" "" file_name "")
  (setvar "FILEDIA" 1)
  (setq full_file_name (strcat (getvar "dwgprefix") (getvar "dwgname")))
  (setq thisdoc (vla-get-activedocument (vlax-get-acad-object)))
  (writelog (timestamp_now))
  (writelog "Document opened : ")
  (writelog full_file_name)
  (c:starttest)
  (princ)
)


;;; ***********************************************************************************
;;; Function to start Test
;;; ***********************************************************************************

(defun c:starttest ( / started_at to_minutes)
  (setq started_at (to_minutes (rtos (getvar "CDATE") 2 8)))
  (vlr-command-reactor
    "Testing"
    '((:vlr-commandEnded . test))
  )
)

;;; ***********************************************************************************
;;; Function which monitors the time
;;; ***********************************************************************************


(defun test (calling-reactor endcommandInfo / thecommandend current_time)
  (setq thecommandend (nth 0 endcommandInfo))
  (setq current_time (to_minutes (rtos (getvar "CDATE") 2 8)))
  (setq diff (- current_time started_at))
  (prompt (strcat "Elapsed : " (itoa diff) " minutes"))
  (vla-save thisdoc)
  (print_it)
)
0 Likes
Accepted solutions (1)
702 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

I expect it's this line:

 

(defun c:starttest ( / started_at to_minutes)

 

Having that listed as a localized variable  means that it begins at nil  for the internal purposes of the command.  So when the function is called for in the line below, there's nothing to work with.

 

Either remove that from the localized variables list, or bring the definition of the function inside  the definition of the command [and before it is called for], instead of in the preliminaries outside the command definition.

Kent Cooper, AIA
Message 3 of 3

harilalmn
Advocate
Advocate

Thanks a ton..!! Such a silly mistake..!! I spent a whole day fiddling with it, but it my eyes failed to catch it..! Thanks a lot...!

0 Likes