ramis Posted September 3, 2008 Posted September 3, 2008 Good morning, I have a little problem in a Lisp function. I only use AutoCAD for a specific part of my work (and not very often) and it didn't have a training or courses. The things that I do are basics but I have some problems... I'm trying to do a Lisp function to select some type of blocks of my drawing and to draw a point at the coordinates of each block. I can't do this manually because i have many files and i can't forget one block (and there are many many blocks!!). And then i will put the lisp function in a script to run it. it's a lisp function that was working to draw a point at the center of circle... nearly the same things but with blocks, it doesn't work:oops: Here is the lisp file (defun c:bck2pt () (princ "\nSelect blocks: ") (setq ss (ssget '((0 . "INSERT")(8 . "WPI26")))) (setq Item 0) (repeat (sslength ss) (setq Ename (ssname ss Item)) (setq Coord (cdr (assoc 10 (entget Ename)))) (command "._point" Coord) (setq Item (+ 1 Item)) ) (princ) ) It returns ; error: bad argument type: lselsetp nil. I think that the filter to select the blocks works... But the problem seems to come from the way i get the coordinates of the block... Thank you, Ramis Quote
CarlB Posted September 3, 2008 Posted September 3, 2008 Code looks OK to me, except you may get that error if nothing is selected. Is "WPI26" the layer name or block name-Group Code 8 is for layer name, 2 is block name. Are you certain you have blocks on this layer? You could add a check for items selected: (if ss (repeat (sslength ss) (setq Ename (ssname ss Item)) (setq Coord (cdr (assoc 10 (entget Ename)))) (command "._point" Coord) (setq Item (+ 1 Item)) ) (princ "\nNothing selected") );if Quote
ramis Posted September 3, 2008 Author Posted September 3, 2008 thank you for your answer, CarlB!! The selection seems to be empty indeed... But now it seems to work... I have change the line (setq ss (ssget '((0 . "INSERT")(2 . "WPI2601")))) by (setq ss (ssget "_x" '((0 . "INSERT")(2 . "WPI2601")))) If someone can tell me the difference between the two... what does "_x" means in this command? because with it, the selection is not empty... ramis This is the correct Lisp function to select some blocks and put point on it automatically, if it helps someone... (defun c:bck2pt () (princ "\nSelect blocks: ") (setq ss (ssget "_x" '((0 . "INSERT")(8 . "WPI26")))) (setq Item 0) (repeat (sslength ss) (setq Ename (ssname ss Item)) (setq Coord (cdr (assoc 10 (entget Ename)))) (command "._point" Coord) (setq Item (+ 1 Item)) ) (princ) ) Quote
ASMI Posted September 3, 2008 Posted September 3, 2008 If someone can tell me the difference between the two... what does "_x" means in this command?because with it, the selection is not empty... "_X" selects all entities include entities on locked and frozen layers and Paper Space (allowed by filter). Can you attach part of your drawing? My function does not work http://www.cadtutor.net/forum/showthread.php?t=26757 ? 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.