tazzzz Posted December 3, 2014 Share Posted December 3, 2014 (edited) Hello, I have a LISP that used to work nice up until this morning when it start working only half way. This lisp is doing a bunch of tasks: -select attributes -asks for scale -asks for insertion point to insert a table -creates a table with attributes selected. Well, now I am able to perform only first 2 tasks and stops when I have to pick a point for insertion. (; error: Automation Error. Problem in loading application) Perhaps I change a variable and I don't know. Any idea? Thanks. ps: the same lisp is working ok in all other computers. Also I noticed another lisp stops short when I need to select a grip for a block.(Unable to interface with ObjectDBX.) Edited December 3, 2014 by tazzzz more info Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 3, 2014 Share Posted December 3, 2014 Are you using -Insert ? If using Insert it will attempt to use the default settings for Insert which can have stuff like scale and insert pt set to predefined which stuffs up your lisp. Do a plain Insert and un reset the values. See also text and styles that have stuff preset same problem. Good idea is to post code so others can have a look even if only the bit thats not working if you have privacy problems. Quote Link to comment Share on other sites More sharing options...
tazzzz Posted December 3, 2014 Author Share Posted December 3, 2014 this is the code (defun C:COUNTATT(/ acapp acol acsp adoc atable attdata attitem atts blkdata blkname blkobj col column colwidth datalist en headers pt row sset swap tabledata tags total txtheight widths x) ;private function (defun sum-and-groupby-three (lst / groups res sum tmp) (while lst (setq tmp (car lst) sum (apply '+ (mapcar 'atoi (mapcar 'cdadr (setq res (vl-remove-if-not '(lambda (a) (and (eq (cdr (nth 0 a)) (cdr (nth 0 tmp))) (eq (cdr (nth 1 a)) (cdr (nth 1 tmp))) (eq (cdr (nth 2 a)) (cdr (nth 2 tmp))))) lst ) ) )) ) groups (cons (subst (cons "QTY" (itoa sum))(cadr tmp) tmp) groups) lst (vl-remove-if '(lambda (a) (member a res)) lst ) ) ) (reverse groups) ) ; main part ; (if (setq sset (ssget (list (cons 0 "INSERT") (cons 66 1)))) (progn (setq tabledata nil attdata nil attitem nil ) (while (setq en (ssname sset 0)) (setq blkobj (vlax-ename->vla-object en) blkname (vla-get-effectivename blkobj) ) (setq atts (vlax-invoke blkobj 'getattributes)) (foreach attobj atts (setq attitem (cons (vla-get-tagstring attobj) (vla-get-textstring attobj))) (setq attdata (cons attitem attdata)) ) (setq tabledata (cons (reverse attdata) tabledata)) (setq attdata nil attitem nil ) (ssdel en sset) ) (setq headers (mapcar 'car (car tabledata)) tags headers ) (setq tabledata (sum-and-groupby-three tabledata)) (setq tabledata (mapcar '(lambda (x) (mapcar 'cdr x) ) tabledata ) ) ;; sort by "DES" : (setq tabledata (vl-sort tabledata '(lambda(a b)(< (car a)(car b))))) (setq total 0) (foreach i datalist (setq total (+ total (cdr i)))) (initget 6) (setq txtheight (getreal "\nSpecify Text height for the table <50>:")) (cond ((not txtheight)(setq txtheight 50))) ;<-- text height as for as in your drawing (or adoc (setq adoc (vla-get-activedocument (setq acapp (vlax-get-acad-object))))) (or acsp (setq acsp (vla-get-block (vla-get-activelayout adoc)))) (setq acCol (vla-GetInterfaceObject acapp(strcat "AutoCAD.AcCmColor." (itoa(atoi(getvar "acadver")))))) (setq pt (getpoint "\nSpecify table location:")) (setq atable (vla-addtable acsp (vlax-3d-point pt) (+ 2 (length tabledata)) (length headers) (* txtheight 1.2) (* txtheight 20) ) ) (vla-put-regeneratetablesuppressed atable :vlax-true) ;; calculate column widths : (setq swap (append (list headers) tabledata) widths nil) (while (car swap) (setq column (mapcar 'car swap)) (setq colwidth (* 1.2 (apply 'max (mapcar 'strlen column))txtheight)) (setq widths (cons colwidth widths)) (setq swap (mapcar 'cdr swap))) (setq widths (reverse widths)) ;; set column widths (setq col 0) (foreach wid widths (vla-setcolumnwidth atable col wid) (setq col (1+ col)) ) (vla-put-horzcellmargin atable (* txtheight 0.5)) (vla-put-vertcellmargin atable (* txtheight 0.3)) (vla-setTextheight atable 1 txtheight) (vla-setTextheight atable 2 txtheight) (vla-setTextheight atable 4 txtheight) (vla-setText atable 0 0 "SUMMARY") (vla-SetCellAlignment atable 0 0 acMiddleCenter) (vla-put-colorindex accol 3) (vla-setcellcontentcolor atable 0 0 accol) (setq col -1) (foreach descr headers (vla-setText atable 1 (setq col (1+ col)) descr) (vla-SetCellAlignment atable 1 col acMiddleCenter) (vla-setcellcontentcolor atable 1 col accol) ) (vla-put-colorindex accol 3) (setq row 2) (foreach record tabledata (setq col 0) (foreach item record (vla-setText atable row col item) (if (= 1 col) (vla-SetCellAlignment atable row col acMiddleCenter) (vla-SetCellAlignment atable row col acMiddleCenter) ) (vla-setcellcontentcolor atable row col accol) (setq col (1+ col)) ) (setq row (1+ row)) ) (vla-put-width atable (apply '+ widths)) (vla-put-height atable (* 1.2 (vla-get-rows atable)txtheight)) (vla-put-regeneratetablesuppressed atable :vlax-false) ) ) (if accol (vlax-release-object accol)) (if acapp (vlax-release-object acapp)) (princ) ) (prompt "\n\t---\tStart command with COUNTATT\t---\n") (prin1) (or (vl-load-com)) (princ) Quote Link to comment Share on other sites More sharing options...
tazzzz Posted December 3, 2014 Author Share Posted December 3, 2014 Before this 2 lisp stop working I played with this code: (defun C:SETUP1 () (setvar "BLIPMODE" 0) (setvar "CMDECHO" 0) (setvar "OSMODE" 0) (setq typ "e") (setq dcl_id (load_dialog "setup1.dcl")) (if (not (new_dialog "setup1" dcl_id) ) (exit) ) (set_tile "rb1" "1") (action_tile "rb1" "(setq typ \"e\")") (action_tile "rb2" "(setq typ \"a\")") (action_tile "rb3" "(setq typ \"c\")") (action_tile "rb4" "(setq typ \"el\")") (action_tile "rb5" "(setq typ \"b\")") (action_tile "cancel" "(done_dialog)(setq userclick nil)") (action_tile "accept" "(done_dialog) (setq userclick T)") (start_dialog) (unload_dialog dcl_id) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 4, 2014 Share Posted December 4, 2014 The codes you posted in reply No 3 works here, but I can't test the other codes in post No 4 due to lack of the dialog file ( setup1.dcl ). Quote Link to comment Share on other sites More sharing options...
tazzzz Posted December 4, 2014 Author Share Posted December 4, 2014 I know, and this is why I tried to figure out what is wrong with my acad. do you think a reset to default will fix the problem? Quote Link to comment Share on other sites More sharing options...
ReMark Posted December 4, 2014 Share Posted December 4, 2014 Resetting AutoCAD to its default settings would be as useless as pouring more gasoline (petrol) in your tank to fix a flat tire (tyre). Try responding to post #5 re: dialog file. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 4, 2014 Share Posted December 4, 2014 Resetting AutoCAD to its default settings would be as useless as pouring more gasoline (petrol) in your tank to fix a flat tire (tyre). .............. Quote Link to comment Share on other sites More sharing options...
tazzzz Posted December 4, 2014 Author Share Posted December 4, 2014 Yes, I just find out. Acad reset is useless. What can be the cause for those 2 errors and how can I fix them: 1. ;error: Automation error.Problem in loading application (first lisp) 2. Unable to interface with object DBX(second lisp) This is the code that I tried before those 2 errors and I think is missing from post 5: setup1 : dialog { label = "Initial Drawing Setup"; : boxed_radio_column { label = "Choose Sheet"; : radio_button { label = "&Engineering Sheets"; key = "rb1"; value = "1"; } : radio_button { label = "&Architectural Sheets"; key = "rb2"; } : radio_button { label = "&Civil Sheets"; key = "rb3"; } : radio_button { label = "&Electrical Sheets"; key = "rb4"; } : radio_button { label = "&Blank Sheets"; key = "rb5"; } } ok_cancel ; : paragraph { : text_part { label = "Designed and Created"; } : text_part { label = "by Kenny Ramage"; } } } Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 4, 2014 Share Posted December 4, 2014 I made a little modification on the routine , so try it and let me know . (defun C:COUNTATT (/ acapp acol acsp adoc atable attdata attitem atts blkdata blkname blkobj col column colwidth datalist en headers pt row sset swap tabledata tags total txtheight widths x ) ;private function (defun sum-and-groupby-three (lst / groups res sum tmp) (while lst (setq tmp (car lst) sum (apply '+ (mapcar 'atoi (mapcar 'cdadr (setq res (vl-remove-if-not '(lambda (a) (and (eq (cdr (nth 0 a)) (cdr (nth 0 tmp))) (eq (cdr (nth 1 a)) (cdr (nth 1 tmp))) (eq (cdr (nth 2 a)) (cdr (nth 2 tmp))) ) ) lst ) ) ) ) ) groups (cons (subst (cons "QTY" (itoa sum)) (cadr tmp) tmp) groups ) lst (vl-remove-if '(lambda (a) (member a res)) lst ) ) ) (reverse groups) ) ; main part ; (if (setq sset (ssget (list (cons 0 "INSERT") (cons 66 1)))) (progn (setq tabledata nil attdata nil attitem nil ) (while (setq en (ssname sset 0)) (setq blkobj (vlax-ename->vla-object en) blkname (vla-get-effectivename blkobj) ) (setq atts (vlax-invoke blkobj 'getattributes)) (foreach attobj atts (setq attitem (cons (vla-get-tagstring attobj) (vla-get-textstring attobj) ) ) (setq attdata (cons attitem attdata)) ) (setq tabledata (cons (reverse attdata) tabledata)) (setq attdata nil attitem nil ) (ssdel en sset) ) (setq headers (mapcar 'car (car tabledata)) tags headers ) (setq tabledata (sum-and-groupby-three tabledata)) (setq tabledata (mapcar '(lambda (x) (mapcar 'cdr x) ) tabledata ) ) ;; sort by "DES" : (setq tabledata (vl-sort tabledata '(lambda (a b) (< (car a) (car b))) ) ) (setq total 0) (foreach i datalist (setq total (+ total (cdr i)))) (initget 6) (setq txtheight (getreal "\nSpecify Text height for the table <50>:") ) (cond ((not txtheight) (setq txtheight 50))) ;<-- text height as for as in your drawing (or adoc (setq adoc (vla-get-activedocument (setq acapp (vlax-get-acad-object)) ) ) ) (or acsp (setq acsp (vla-get-block (vla-get-activelayout adoc))) ) (setq pt (getpoint "\nSpecify table location:")) (setq atable (vla-addtable acsp (vlax-3d-point pt) (+ 2 (length tabledata)) (length headers) (* txtheight 1.2) (* txtheight 20) ) ) (vla-put-regeneratetablesuppressed atable :vlax-true) ;; calculate column widths : (setq swap (append (list headers) tabledata) widths nil ) (while (car swap) (setq column (mapcar 'car swap)) (setq colwidth (* 1.2 (apply 'max (mapcar 'strlen column)) txtheight ) ) (setq widths (cons colwidth widths)) (setq swap (mapcar 'cdr swap)) ) (setq widths (reverse widths)) ;; set column widths (setq col 0) (foreach wid widths (vla-setcolumnwidth atable col wid) (setq col (1+ col)) ) (vla-put-horzcellmargin atable (* txtheight 0.5)) (vla-put-vertcellmargin atable (* txtheight 0.3)) (vla-setTextheight atable 1 txtheight) (vla-setTextheight atable 2 txtheight) (vla-setTextheight atable 4 txtheight) (vla-setText atable 0 0 "{\\C3;SUMMARY}") (vla-SetCellAlignment atable 0 0 acMiddleCenter) (setq col -1) (foreach descr headers (vla-setText atable 1 (setq col (1+ col)) (strcat "{\\C3;" descr "}") ) (vla-SetCellAlignment atable 1 col acMiddleCenter) ) (setq row 2) (foreach record tabledata (setq col 0) (foreach item record (vla-setText atable row col (strcat "{\\C3;" item "}")) (if (= 1 col) (vla-SetCellAlignment atable row col acMiddleCenter) (vla-SetCellAlignment atable row col acMiddleCenter) ) (setq col (1+ col)) ) (setq row (1+ row)) ) (vla-put-width atable (apply '+ widths)) (vla-put-height atable (* 1.2 (vla-get-rows atable) txtheight) ) (vla-put-regeneratetablesuppressed atable :vlax-false) ) ) (if acapp (vlax-release-object acapp) ) (princ) ) (prompt "\n\t---\tStart command with COUNTATT\t---\n") (prin1) (or (vl-load-com)) (princ) Quote Link to comment Share on other sites More sharing options...
tazzzz Posted December 4, 2014 Author Share Posted December 4, 2014 Thank you so much !!! Finally is working. Could you please be so kind and explain what you did ? Do you think something is missing in my autocad ? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 4, 2014 Share Posted December 4, 2014 Thank you so much !!!Finally is working. Excellent , You are welcome and I am happy to hear that . Could you please be so kind and explain what you did ? Do you think something is missing in my autocad ? I deleted all related codes to colors and replaced them with another way of coding and that's it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.