Jump to content

trying to figure out how to do this function


Recommended Posts

Hello guys, 
I hope you are all fine. I am looking for a LISP, because I tried to create for myself and unluckt it does not work.

I want to explain :
this is my DWG, i mean how it looks like:

As you can see there is 2 type of Blocks. one is small and the other is big one. These types is not always square, they could be circle/rectangle etc.
I can count first block with select similar or qselect, also I can count second object. But I want to count these objects that I marked. 

I created myself a lsp like this: Select block one, select block two, calculate distance, add tolarence +-5 to this distance and find these that they have same distance, but did not work.

Can you help me please?

Link to comment
Share on other sites

So you could use ssget (see http://lee-mac.com/ssget.html ) to select block 1:

This will select all blocks.


 (setq ss (ssget "_X" ' ((0. "INSERT") (2. "Block Name"))) )


Then loop through the selection set with a while, repeat foreach or however loop


Using the selected block you can get it's insert point:

(setq MyBlock (ssname ss count)) ; where count is the item number in the selection set
(set pt (cdr (assoc 10 (entget Myblock)))) ; gets the insertion point of the block


And then back to selection set, select all block 2 that lie within an area of this insertion point:

(setq pt1 (mapcar '+ (-5 -5 0) pt)) ; 4 corners of a rectabgle round the block
(setq pt2 (mapcar '+ (-5 +5 0) pt))
(setq pt3 (mapcar '+ (+5 +5 0) pt))
(setq pt4 (mapcar '+ (+5 -5 0) pt))

(setq ss2 (ssget "_CP" (list pt1 pt2 pt3 pt4) '((2 . "Block Name 2")) ))


and work out if ss2 is nil or a list - if it is a list then count it.


Might work (CAD is off for today so the above is untested but might point you near to what you want)



As Dan above, post your LISP if you can and it might be a simple change in that to make it work - keeping the work you did 

  • Like 2
Link to comment
Share on other sites

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.

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