When selecting a rectangle

When selecting a rectangle

saitoib
Advocate Advocate
987 Views
10 Replies
Message 1 of 11

When selecting a rectangle

saitoib
Advocate
Advocate

Hi all!

If I select rectangles, is there any way to know which side I have selected ?

best reagards.

 

Saitoib
0 Likes
Accepted solutions (3)
988 Views
10 Replies
Replies (10)
Message 2 of 11

pbejse
Mentor
Mentor

@saitoib wrote:

Hi all!

If I select rectangles, is there any way to know which side I have selected ?

best reagards.

 


The question is not clear @saitoib , are you referring to the Length and Width as sides?  which way is length and which way is width?

 

 

 

0 Likes
Message 3 of 11

saitoib
Advocate
Advocate

Sorry
I am not a native English speaker, so I am not good at explaining.
For example, here is what I wrote
rectang 0,0 100,100
And when you select a polyline by clicking on one of the four edges
I would like to know how to know which edge was selected.

I have written the following program.
If there are any improvements, please let me know.

 

(defun c:test( / obj pt pl sside)
	(mapcar 'set '(obj pt) (entsel "\nSelect a side"))
	(setq pl (mapcar 'cdr (_aassoc 10 (entget obj))))
	(setq pl (append pl (list (car pl))))
	(setq sside (_sel_side pl pt))
	(princ sside)
)
; all assoc
(defun _aassoc (no lst)
  	(vl-remove-if-not '(lambda (x) (= (car x) no)) lst)
)
; select side
(defun _sel_side (pl pt / n i j pt1 cent dist mini side)
	(setq n (length pl))
	(setq i 0)
	(repeat (1- n)
		(setq cent (mapcar '(lambda(a b) (/(+ a b) 2)) (nth i pl) (nth (1+ i) pl)))
		(setq cent (append cent '(0.0)))
		(setq dist (distance cent pt))
		(if (= mini nil)
			(progn
				(setq mini dist)
				(setq j i)
			)
			(if (< dist mini)
				(progn
					(setq mini dist)
					(setq j i)
				)
			)
		)
		(setq i (1+ i))
	)
	(setq side (list (nth j pl)))
	(setq side (append side (list (nth (1+ j) pl))))
)
Saitoib
Message 4 of 11

pbejse
Mentor
Mentor

@saitoib wrote:

.... And when you select a polyline by clicking on one of the four edges
I would like to know how to know which edge was selected.

If there are any improvements, please let me know.

 


Sorry @saitoib  but I still dont understand. In what way would the user "know" the selected edge?  The user select the edge of the polyline on screen yes? so you know which side it is.

In your case i think its better to post a picture to describe what "know which edge was selected"

 

And you wrote this bit? and _sel_side sub?

 

(mapcar 'set '(obj pt) (entsel "\nSelect a side"))

 

Very impressive for a beginner.

EDIT: I see now, You want the before and after points (xyz) of the selected edge

look into this functions

  • vlax-curve-getPointAtParam
  • vlax-curve-getParamAtPoint
  • vlax-curve-getClosestPointTo

HTH

 

0 Likes
Message 5 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

Something like this, perhaps [untested]?

 

(vl-load-com); [in case not yet loaded]

(defun C:WSP (/ plsel pl); = Which Segment Picked?

  (if

    (and

      (setq plsel (entsel "\nSelect Polyline on desired segment: "))

      (wcmatch (cdr (assoc 0 (entget (setq pl (car plsel))))) "*POLYLINE")

    ); and

    (prompt ; then

      (strcat

        "\nPolyline was selected on segment number "

        (itoa (1+ (fix (vlax-curve-getParamAtPoint pl (osnap (cadr plsel) "_nea")))))

        "."

      ); strcat

    ); prompt

    (prompt "\nNo Polyline selected."); else

  ); if

  (princ)

); defun

Kent Cooper, AIA
0 Likes
Message 6 of 11

saitoib
Advocate
Advocate

Oh, I get it.
I was wrong in wanting to know the selected edge.
I want to get the data of the selected edge of the polyline, and then move on to the next step.
When I entsel a polyline, I get a lot of point data back, so I wondered if there was an easy way to know which edge was selected.

Saitoib
0 Likes
Message 7 of 11

pbejse
Mentor
Mentor
Accepted solution

@saitoib wrote:


And when you select a polyline by clicking on one of the four edges


 

The result is similar to your function TEST

 

(defun c:demo ( / e param)
  (setq e (entsel))
  (setq	param (vlax-curve-getParamAtPoint
		(Car e)
		(vlax-curve-getClosestPointTo (Car e) (Cadr e))
	      )
  )
  (list	(vlax-curve-getPointAtParam (Car e) (fix param))
	(vlax-curve-getPointAtParam (Car e) (1+ (fix param)))
  )
)

 

HTH

 


@saitoib wrote:

Oh, I get it.
I was wrong in wanting to know the selected edge.
....


EDIT:

Really @saitoib ? right after i post a sample code thats when you decided it was wrong 🙂

The code above mimics your original intent.

 

Do what you wish with it. I'm throwing in the towel.

 

0 Likes
Message 8 of 11

john.uhden
Mentor
Mentor
Accepted solution

I am just guessing (guessing, mind you) that you want the pair of coordinates of the side selected.

See if this helps...

(defun @getside ( / pick p e ent etyp obj param p2 p2 result)
  (and
    (setq pick (nentsel "\nSelect polyline segment: "))
    (setq p (trans (nth 1 pick) 1 0)
          e (car pick)
          ent (entget e)
          etyp (cdr (assoc 0 ent))
    )
	(or
	  (wcmatch etyp "*POLYLINE")
	  (prompt (strcat "  Entity selected is a(n) " etyp))
    )
	(setq obj (vlax-ename->vla-object e))
	(setq p (vlax-curve-getClosestPointTo obj p))
	(setq param (vlax-curve-getparamatpoint obj p))
	(setq p1 (vlax-curve-getpointatparam obj (fix param)))
	(setq p2 (vlax-curve-getpointatparam obj (1+ (fix param))))
	(setq result (list p1 p2))
  )
  result
)

John F. Uhden

0 Likes
Message 9 of 11

saitoib
Advocate
Advocate

Hi, everyone

Thank you for all the great advice.
I had a very hard time understanding all the commands, which I have never seen before.
I learned a lot.
Thank you very much.

Saitoib
0 Likes
Message 10 of 11

ВeekeeCZ
Consultant
Consultant

Not sure how you cope with the parameter but in case you're not sure what the value actually means, HERE is nice Kent's explanation  

0 Likes
Message 11 of 11

john.uhden
Mentor
Mentor

Of course, Owen Wengerd has warned us publicly not to rely on parameters, but the alternative of using pointatdistance and distanceatpoint makes for a little more cumbersome code.

I have never had a problem using parameters, but that's not to say I never will.

John F. Uhden