Jump to content

Recommended Posts

Posted

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...:unsure:

 

Thank you,

Ramis

Posted

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

Posted

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)

)

Posted
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 ?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...