Insert a block in point a & b, but if there's already same block, don't insert.

Insert a block in point a & b, but if there's already same block, don't insert.

unggansu2
Contributor Contributor
512 Views
8 Replies
Message 1 of 9

Insert a block in point a & b, but if there's already same block, don't insert.

unggansu2
Contributor
Contributor

Hello, it is me again.

How do you write a lisp that capable detects if there's a similar object around it?

Like, say, I wrote a lisp that need user's input for point a (start) & b (end).

I want it to insert a block in both point, but it will only insert the one that has no similar block in an area of 15 units.

0 Likes
513 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

Post a lisp you wrote and a sample dwg to see what 'similar' blocks look like.

Message 3 of 9

unggansu2
Contributor
Contributor

It was something simple like this.

Actually, what I want to make is a lisp, that do the following lisp (wall creating), along a set of rectangles that adjacent to each other, while adding column in every corner of the rectangle.

Oh and, the KP entity inside the lisp is the block that I was referring to.

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

I see no dwg.

 

Be aware, that if you divide an integer by an integer, you'll get an integer. 

If you presume that (/ 15 2) should return 7.5, you need to make at least one of those integers a real. Say (/ 15 2.)

Message 5 of 9

unggansu2
Contributor
Contributor

Ah sorry, missed the "a sample dwg" when reading. Here you go.

And also, thanks for letting me know about the integer problem. Though so far I haven't faced problems involving those yet.

0 Likes
Message 6 of 9

ВeekeeCZ
Consultant
Consultant

So what's the issue?

See THIS , there is a window type of selection listed. You need to calculate two points (use p1/p2 coordinates and POLAR function), then add a filter to cover the block with your name. '((0 . "INSERT") (2 . "KP")). 

Then insert your block just in case the above-described selection returns nil.

 

Come back if you get some issues with it.

 

 

 

And also, thanks for letting me know about the integer problem. Though so far I haven't faced problems involving those yet.

 

This was just an observation... your code does that.

 

BeekeeCZ_0-1667818749192.png

 

 

 

 

Message 7 of 9

unggansu2
Contributor
Contributor
I never knew there is "ssget" function. I guess I need to do more proper surfing before asking.

I'll be back in few days. Thanks for the site reference Becky.
0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant

Ok... good luck then.

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Re check is there a block at point can be done fairly simply, you just use "SSGET" "CP" co-ords, the "CP" is crossing polygon, so you make a little box of 4 points and it checks in that box is anything there. As you mentioned about using SSGET you can also add filters so in this case it becomes CP plus is it a block of name xxxx.

 

 

(if (ssget "CP" co-ords (list (cons 0 "INSERT")(CONS 2 Blockname)))
(Princ "\nBlock is there")
(command "-insert" blockname "s" 1 pt 0)
)

 

 

Do some more googling about using SSGET, start with "Lee-mac ssget" a good site for explanations.