PDuMont Posted February 3, 2016 Posted February 3, 2016 Hello All, I hope the new year finds you well. While both of these routine "work", I am getting errors after running them. I think it may be something obvious, but it's apparently not obvious to me. I think I may be handling the foreach incorrectly. Version #1: (defun c:PLO (/ cmde doc sset ent) (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) ) (princ (strcat "\nError: " msg)) ) (if cmde (setvar 'cmdecho cmde) ) (if doc (vla-endundomark doc) ) (princ) ) ;_ end of defun (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark doc) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) (if (setq sset (ssget '((0 . "circle") (40 . 0.05)))) (progn (foreach ent (mapcar 'cadr (ssnamex sset)) (command "_.offset" "0.1" ent "0,0" "") ) ;_ end of foreach ) ;_ end of progn ) ;_ end of if (setvar 'cmdecho cmde) (vla-endundomark doc) (princ) ) ;_ end of defun (vl-load-com) This creates the offsets but I get errors "Unknown Command 0,0" and "Unknown Command PLO". Like it's going through the command sequence again. Version #2 (defun c:PLO (/ cmde doc sset ent obj ) (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) ) (princ (strcat "\nError: " msg)) ) (if cmde (setvar 'cmdecho cmde) ) (if doc (vla-endundomark doc) ) (princ) ) ;_ end of defun (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark doc) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) (if (setq sset (ssget '((0 . "circle") (40 . 0.05)))) (progn (foreach ent (mapcar 'cadr (ssnamex sset)) (setq obj (vlax-ename->vla-object ent)) (vla-Offset obj 0.1) ) ;_ end of foreach ) ;_ end of progn ) ;_ end of if (setvar 'cmdecho cmde) (vla-endundomark doc) (princ) ) ;_ end of defun (vl-load-com) This creates the offsets but I get "error: bad argument type: lentityp (0 (-3.41352 31.3948 0.0))" Any help would be greatly appreciated. Quote
Tharwat Posted February 3, 2016 Posted February 3, 2016 The problem with the first routine is that you have a list of should be removed since you want only entity names to iterate through. eg: (vl-remove-if 'listp(mapcar 'cadr (ssnamex sset))) And update the codes to the second routine accordingly as well. Quote
PDuMont Posted February 3, 2016 Author Posted February 3, 2016 Ahh, that makes sense now. Thank you very much Tharwat! Quote
Lee Mac Posted February 3, 2016 Posted February 3, 2016 FWIW, the efficiency could be improved, as looping over the same data three times is unnecessary when a single loop will suffice, e.g.: (foreach ent (ssnamex sset) (if (= 'ename (type (cadr ent))) ... ) ) However, in general, the ssnamex function is known to be relatively slow in comparison to other methods of processing selection set entities. Quote
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.