Jump to content

Lisp to automatically draw rectangles where it intersects with specific points


BlacK_SmokE

Recommended Posts

ron, i don't know why, but it gives error sometimes when i select a rectangle (even when not in a blocked layer) and it only prompts me to select one rectangle, but doesn't let me make another selection to count how many rectangles, equal to the one i previously selected, are in the slection set

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • BlacK_SmokE

    17

  • ronjonp

    10

  • Tharwat

    1

  • Grrr

    1

Top Posters In This Topic

Posted Images

... and it only prompts me to select one rectangle, but doesn't let me make another selection to count how many rectangles, equal to the one i previously selected, are in the slection set

Not sure I understand this statement.

 

The code worked in the sample drawing you posted.

Link to comment
Share on other sites

i think that i'm the one who's not understanding your code then =(

 

i meant i need to select the rectangle and then make another selection to count how many equal rectangles are there

but your code only prompts me to select a rectangle and doesn't return me anything (which variable u assigned to give me a value?)

Link to comment
Share on other sites

Try replacing:

(sssetfirst nil n)

with:

(if (= 0 (sslength n))
   (alert "Nothing in selection!")
   (progn (sssetfirst nil n) (alert (strcat (itoa (sslength n)) " objects in selection!")))
 )

2018-03-28_9-17-16.png

Link to comment
Share on other sites

thanks ron, now i'm understanding a little better what your code does

the variable n retrieves me the amount of objects

but your code is finding the rectangle in the whole drawing, i want to find the rectangle inside another selection set, is that possible?

Link to comment
Share on other sites

Try this:

(defun c:foo (/ r o n s)
 (cond
   ((and (setq o (car (nentsel "\nPick your little rectangle: ")))
  (setq o (vlax-ename->vla-object o))
  (vlax-property-available-p o 'area)
  (setq r (vla-get-area o))
  (setq s (ssget '((0 . "*polyline"))))
  (setq n (ssadd))
    )
    (foreach b	(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      (cond ((and (vlax-property-available-p b 'area) (equal (vla-get-area b) r 1e-2))
      (ssadd (vlax-vla-object->ename b) n)
      (vl-catch-all-apply 'vla-put-color (list b 1))
     )
      )
    )
    (if (= 0 (sslength n))
      (alert "Nothing in selection!")
      (progn (sssetfirst nil n) (alert (strcat (itoa (sslength n)) " objects in selection!")))
    )
   )
 )
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

excellent ron!

we're almost reaching a perfect resolution for my problem

your code is working smoothly

 

But just so u can understand better what i need, this part of your code is not needed:

(if (= 0 (sslength n))
      (alert "Nothing in selection!")
      (progn (sssetfirst nil n) (alert (strcat (itoa (sslength n)) " objects in selection!")))
    )

 

what i need is the value that the variable n is returning to me in your code!

but that's okay, i can remove this last part

 

Now, the last big deal:

i see that your using the 'area' property to find the same rectangles...

so is there a way to add some other property to refine that filter a bit, like rectangles with the same area AND same length?

or same maybe, same area AND same position in X or same position in Y?

Link to comment
Share on other sites

Sorry .. this is the extent I'm willing to do for free. If you want to try and make changes , I'll help when I can ... but I have real work to do now. ;)

Link to comment
Share on other sites

ok ron, i understand, but thank you so much for your patience and contribution on the code, u have helped a lot

sorry if i bothered you

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.

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