Leaderboard
Popular Content
Showing content with the highest reputation on 03/03/2020 in all areas
-
That is an age old problem, ever heard of Trigonometry? It is easy for a low number of points but when you start getting into bigger numbers it becomes more difficult, I beleive that after a certain amount it isn't actually possible, all you can do is go for the greatest distance between points but it won't be equal for all points.1 point
-
Can you post some of the actual drawing file?1 point
-
haven't checked what dlanorh said but you should listen to him because he's all over this forum anyways , your error also was caused by variable time1 in sub function ETIME because it is a local variable to c:login so maybe you should make it global by taking it out of the declaration list from your defun. Maybe something like this : (defun c:login (/ log-file-name fp a c d) ;(setq log-file-name "c:\\Temp\\Lisp\\Cad-Tutor\\AbdRF\\log.txt") (setq log-file-name "D:\\AfralispTut\\log.txt") (setq a (TODAY) time1 (TIME) c (getvar "dwgname") d (strcat "Drg Start " a " - " time1 " - " c)) (if (/= (getvar 'dwgtitled) 0) (progn (if (findfile log-file-name) (setq fp (open log-file-name "a")) (setq fp (open log-file-name "w"))) (if fp (progn (princ d fp) (princ "\n" fp) (close fp) (princ (strcat "\nLogged in at: " time1)) ) ) ) ) (princ) ) (defun c:logout (/ log-file-name a time2 c d fp) ;(setq log-file-name "c:\\Temp\\Lisp\\Cad-Tutor\\AbdRF\\log.txt") (setq log-file-name "D:\\AfralispTut\\log.txt") (setq a (TODAY) time2 (TIME) c (getvar "dwgname") d (strcat "Drg Exit " a " - " time2 " - " c)) (if (/= (getvar 'dwgtitled) 0) (progn (if (findfile log-file-name) (setq fp (open log-file-name "a")) (setq fp (open log-file-name "w"))) (if fp (progn (princ d fp) (princ "\n" fp) (close fp) (princ (strcat "\nLogged out at: " time2)) (etime) ) ) ) ) (princ) ) (defun ETIME ( / log-file-name hr1 m1 s1 tot1 hr2 m2 s2 tot2 total ht mt file fp) ;(setq log-file-name "c:\\Temp\\Lisp\\Cad-Tutor\\AbdRF\\log.txt") (setq log-file-name "D:\\AfralispTut\\log.txt") (or time1 (setq time1 (time))); *** error was caused because time1 was nil because its local to c:login (setq hr1 (* 60 (* 60 (atof (substr time1 1 2)))) m1 (* 60 (atof (substr time1 4 2))) s1 (atof (substr time1 7 2)) tot1 (+ hr1 m1 s1) hr2 (* 3600 (atof (substr time2 1 2))) m2 (* 60 (atof (substr time2 4 2))) s2 (atof (substr time2 7 2)) tot2 (+ hr2 m2 s2) total (- tot2 tot1) hr1 (/ total 3600) ht (fix hr1) hr1 (- hr1 ht) mt (* hr1 60) ht (rtos ht) mt (rtos mt)) (setq d (strcat "Editing Time This Session : " ht " Hours and " mt " minutes")) (if (findfile log-file-name) (setq fp (open log-file-name "a")) (setq fp (open log-file-name "w"))) (if fp (progn (princ d fp) (princ "\n" fp) (princ "==============================================================" fp) (princ "\n" fp) (close fp) ) ) (princ) ) ;calculate the current date (defun TODAY (/ d yr mo day) (setq d (rtos (getvar "CDATE") 2 6) yr (substr d 3 2) mo (substr d 5 2) day (substr d 7 2)) (strcat day "/" mo "/" yr) ) ;calculate the current time (defun TIME (/ d hr m s) (setq d (rtos (getvar "CDATE") 2 6) hr (substr d 10 2) m (substr d 12 2) s (substr d 14 2)) (strcat hr ":" m ":" s) ) (princ) And I agree with bigal , using princ to a file pointer does work perfectly but using write-line can make your code easier to read , but this is your own choise , just a matter of taste.1 point
-
If you check your ETIME defun, your are dividing a real by an integer which returns an integer answer hr1 (/ total 3600) ht (fix hr1) hr1 (- hr1 ht); This will always be 0 (zero) since hr1 & ht will be the same; as hr1 is an integer This should be hr1 (/ total 3600.0);; divide by real ht (fix hr1) hr1 (- hr1 ht)1 point
-
If you want logging software this may help. It also does a lot more. Ok a couple of suggestions you can redefine Autocad commands so you can do your own "open" and "close". As part of your logout you should save and close. I would normally use (write-line rather than (princ. A blank line (write-line "" fp) (defun c:login (/ file a time1 c d fp) (setq file (findfile "D:\\AfralispTut\\log.txt")) (if (not file) (open "D:\\AfralispTut\\log.txt" "w") ) (setq a (TODAY)) time1 (TIME) c (getvar "dwgname") d (strcat "Drg Start " a " - " time1 " - " c) ) (if (/= c "Drawing.dwg") (progn (setq file (findfile "D:\\AfralispTut\\log.txt") fp (open file "a") ) (write-line d fp) (write-line "" fp) (close fp) (write-line (strcat "\nLogged in at: " time1)) ) ) (princ) ) (defun c:logout (/ file a time2 c d fp) (setq a (TODAY) time2 (TIME) c (getvar "dwgname") d (strcat "Drg Exit " a " - " time2 " - " c) ) (if (/= c "Drawing.dwg") (progn (setq file (findfile "D:\\AfralispTut\\log.txt") fp (open file "a") ) (write-line d fp) (write-line "" fp) (close fp) (write-line (strcat "\nLogged out at: " time2)) (etime) ) ) (princ) ) (defun ETIME ( / hr1 m1 s1 tot1 hr2 m2 s2 tot2 total ht mt file fp) (setq hr1 (* 60 (* 60 (atof (substr time1 1 2)))) m1 (* 60 (atof (substr time1 4 2))) s1 (atof (substr time1 7 2)) tot1 (+ hr1 m1 s1) hr2 (* 3600 (atof (substr time2 1 2))) m2 (* 60 (atof (substr time2 4 2))) s2 (atof (substr time2 7 2)) tot2 (+ hr2 m2 s2) total (- tot2 tot1) hr1 (/ total 3600) ht (fix hr1) hr1 (- hr1 ht) mt (* hr1 60) ht (rtos ht) mt (rtos mt) ) (setq d (strcat "Editing Time This Session : " ht " Hours and " mt " minutes")) (setq file (findfile "D:\\AfralispTut\\log.txt") fp (open file "a") ) (write-line d fp) (write-line "" fp) (write-line "==============================================================" fp) (write-line "" fp) (close fp) (princ) ) ;calculate the current date (defun TODAY (/ d yr mo day) (setq d (rtos (getvar "CDATE") 2 6) yr (substr d 3 2) mo (substr d 5 2) day (substr d 7 2) ) (strcat day "/" mo "/" yr) ) ;calculate the current time (defun TIME (/ d hr m s) (setq d (rtos (getvar "CDATE") 2 6) hr (substr d 10 2) m (substr d 12 2) s (substr d 14 2) ) (strcat hr ":" m ":" s) ) (princ) There is something wrong in the etime calcs did not spend a lot of time. Drg Start 03/03/20 - 19:05:23 - Drawing1.dwg Drg Exit 03/03/20 - 19:05:39 - Drawing1.dwg Editing Time This Session : 0 Hours and 43.883 minutes change (defun etime ( / ) then you can check each variable after running using a simple method type ! then variable !ht !hr1, check the answer, rtos for me (rtos ht 2 0) Productivity_Analysis_Tool.lsp1 point
-
1 point
-
I don't think this is possible with text, but is possible with a block (see attached example dwg). The drawing contains a block (coords) which has a single attribute, which contains a field linked to the blocks insertion point. If you insert the block in will display the insertion point. If you move or copy the block you will need to do a regen. coord.dwg1 point
-
(vl-load-com) (defun c:mltp ( / *error* c_doc c_spc sv_lst sv_vals t_obj p_lst lyr p_vals ss cnt obj) (defun *error* (msg) (mapcar 'setvar sv_lst sv_vals) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : ( " msg " ) occurred."))) (princ) );end_error_on_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)) sv_lst (list 'cmdecho 'osmode) sv_vals (mapcar 'getvar sv_lst) );end_setq (mapcar 'setvar sv_lst (list 0 0)) (setq t_obj (vlax-ename->vla-object (car (entsel "\nSelect Template Line : "))) p_lst (list 'linetypescale) lyr (vlax-get t_obj 'layer) );end_setq (mapcar '(lambda (x) (setq p_vals (cons (vlax-get-property t_obj x) p_vals))) p_lst) (setq p_vals (reverse p_vals) ss (ssget (list '(0 . "*LINE,ARC,CIRCLE,ELLIPSE") (cons 8 lyr))) );end_setq (cond (ss (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (mapcar '(lambda (x y) (vlax-put-property obj x y)) p_lst p_vals) );end_repeat ) );end_cond (mapcar 'setvar sv_lst sv_vals) (princ) );end_defun If I've missed something let me know1 point