Jump to content

Select Polylines (Right Direction) Of Block


Recommended Posts

Posted (edited)

I want to select Polylines either at Right or Left  Direction Of The Block

Edited by Engineer_Yasser
Posted

I don't understand why your asking so many ways to do this without code. 

 

Select the blocks ;

Change layer using properties or the "Bylayer" via "Entity properties toolbar"

Change color using properties or the "color Bylayer" via "Entity properties toolbar"

Change one block and use the matchprop option

Chprop command

Posted (edited)

@BIGAL

 

Sorry for the inconvenience

you didn't get my point ... i have thousands of these in drawing

 

i can't determine the polylines at the right direction of the block .. this is the part i need help with

 

i need code to select the polylines at ( right direction ) of the block

Edited by Engineer_Yasser
  • Engineer_Yasser changed the title to Select Polylines (Right Direction) Of Block
Posted (edited)

Explain how 'right'  is calculated when in this scenario the two blocks have the same rotation?

image.thumb.png.b6ea60bbb3d7c8341d108edd81dc7d6b.png

 

Having the block definition at a random rotation does not help either...

image.png.b08d7d11897c5583ed7c55d7d172e314.png

Edited by ronjonp
Posted

Sorry I don't follow. The geometry is drawn with all start points originating from the block so what is "right"? To me the bottom example is visually left. The block rotation is the same even in a mirrored situation. Look at the visual below.

image.thumb.png.bdb6cc63814625f8c068ab9d344f7c20.png

 

Posted

I got your point .. can you change the color of any direction right or left .. so the right differ than the left

 

all polylines connected to block base point

Posted
2 minutes ago, Engineer_Yasser said:

I got your point .. can you change the color of any direction right or left .. so the right differ than the left

 

all polylines connected to block base point

I can't change your drawing because I still don't know what the 'right' side is. 😂 Could the 'right' side be the one that has the shorter or longer amount of polylines and your example is wrong?

However this is drafted ( by code ? ) the blocks need to have unique rotations and a set of rules to discern the correct side.

Posted (edited)

when you look at the block .. some polyline at one side of the block and other polylines at the other side of the block .

 

 

Edited by Engineer_Yasser
Posted (edited)

🤣 Well that's pretty easy to do. 'Right' is not orientation but one or the other. The code below will select the side with the smallest cumulative length ( because I'm a dork ).

 

Enjoy :)

(defun c:foo (/ a b c fz bks p s x)
  ;; RJP » 2025-01-08
  (cond	((and (setq s (ssget "_X" '((0 . "INSERT") (2 . "blll"))))
	      (setq bks (mapcar 'cadr (ssnamex s)))
	      (setq s (ssget "_X" '((0 . "LWPOLYLINE") (8 . "Poly"))))
	      (setq s (mapcar 'cadr (ssnamex s)))
	 )
	 (setq
	   s (mapcar
	       '(lambda	(x)
		  ;; Startpoint, length, startangle, ename
		  (list	(setq p (vlax-curve-getstartpoint x))
			(vlax-curve-getdistatpoint x (vlax-curve-getendpoint x))
			(angle '(0 0 0) (vlax-curve-getfirstderiv x (vlax-curve-getparamatpoint x p)))
			x
		  )
		)
	       s
	     )
	 )
	 (setq fz 2)
	 (foreach p (mapcar '(lambda (x) (cdr (assoc 10 (entget x)))) bks)
	   (and	(setq a (vl-remove-if-not '(lambda (x) (equal p (car x) fz)) s))
		(setq b (vl-remove-if-not '(lambda (x) (equal (caddr (car a)) (caddr x) fz)) a))
		(setq c (vl-remove-if '(lambda (x) (equal (caddr (car a)) (caddr x) fz)) a))
		(foreach e (if (< (apply '+ (mapcar 'cadr b)) (apply '+ (mapcar 'cadr c)))
			     b
			     c
			   )
		  (entmod (append (entget (last e)) '((8 . "SHORTSTACK") (420 . 16711680))))
		)
	   )
	 )
	)
  )
  (princ)
)

2025-01-08_11-20-19.gif.ad6116a24e27c9c9554860fcd0cc748b.gif

Edited by ronjonp
  • Thanks 1
Posted (edited)

Hi @Engineer_Yasser,

 

I agree with @ronjonp, i'v tried many option to choose the true "right" side from to block (which I also don't know where it is), but, after all I made something (which "I hope") that will help you for this situation (or even help to someone to improve this code or even made a new one).

 

Try the following:

 

; ************************************************************************
; Functions     :  CHCOLPL
; Description   :  Change the colors of the Polylines into the yellow
; Author        :  SAXLLE
; Date          :  January 08, 2025
; ************************************************************************

(defun c:CHCOLPL ( / ss len i ssn ename ent_pl data spt ept 2ndpt 3rdpt midpt lenn tlen k)
  (setq ss (ssget "X" '((0 . "INSERT") (8 . "BLK") (2 . "blll")))
	len (sslength ss)
	i 0
	)
  (while (< i len)
    (setq ssn nil)
    (setq ename (ssname ss i))
    (command-s "_explode" ename "")
    (setq ent_pl (ssget "x" '((0 . "LWPOLYLINE") (8 . "BLK") (62 . 1) (70 . 1)))
	  data (entget (ssname ent_pl 0))
	  spt (cdr (nth 15 data))
	  2ndpt (cdr (nth 20 data))
	  3rdpt (cdr (nth 25 data))
	  ept (cdr (nth 30 data))
	  midpt (polar spt (angle spt ept) (/ (distance spt ept) 2))
	  )
    (command-s "_undo" 1 "")
    (setq ssn (ssget "_F" (list spt ept) '((0 . "LWPOLYLINE") (8 . "Poly")))
	  lenn (sslength ssn)
	  )
    (if (= lenn 1)
      (setq k 0)
      (setq k 1)
      )
    (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn 0)) 'Length))
    (while (< k lenn)
      (if (< tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length))
	(progn
	  (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length)
		sssn (ssname ssn k)
		)
	  )
	(progn
	  (setq sssn (ssname ssn k))
	  )
	)
      (setq k (1+ k))
      )
    (setq eptn (vlax-curve-getEndPoint (vlax-ename->vla-object sssn)))
    (if (> (cadr midpt) (cadr eptn))
      (progn
	(setq ssn (ssget "_F" (list spt ept) '((0 . "LWPOLYLINE") (8 . "Poly"))))
	(command-s "_chprop" ssn "" "c" 2 "")
	)
      (progn
	(setq ssn (ssget "_F" (list 2ndpt 3rdpt) '((0 . "LWPOLYLINE") (8 . "Poly")))
	      lenn (sslength ssn)
	      )
	(if (= lenn 1)
	  (setq k 0)
	  (setq k 1)
	  )
	(setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn 0)) 'Length))
	(while (< k lenn)
	  (if (< tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length))
	    (progn
	      (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length)
		    sssn (ssname ssn k)
		    )
	      )
	    (progn
	      (setq sssn (ssname ssn k))
	      )
	    )
	  (setq k (1+ k))
	  )
	(setq midpt (polar 2ndpt (angle 2ndpt 3rdpt) (/ (distance 2ndpt 3rdpt) 2)))
	(setq eptn (vlax-curve-getEndPoint (vlax-ename->vla-object sssn)))
	(setq ssn (ssget "_F" (list midpt eptn) '((0 . "LWPOLYLINE") (8 . "Poly"))))
	(command-s "_chprop" ssn "" "c" 2 "")
	)
      )
    (setq i (1+ i))
    )
  (princ)
  )

 

From the attached picture, I can't change the color of polylines into the yellow from the blue "circle" (it changed the color from the "wrong" side).

image.thumb.png.a72bc7d5297ef5aebc4afe5e1337c381.png

Edited by Saxlle
  • Thanks 1
Posted

Thanks for your effort

 

@ronjonp

when I tried on a little bit larger scale drawing, not all polylines were coloured

 

@Saxlle
when I tried on a little bit larger scale drawing, not all polylines were coloured and the code gave error
error: bad argument type: lselsetp nil

 

I attached the file i tested on it , thanks.

Test 2.dwg

Posted (edited)
1 hour ago, Engineer_Yasser said:

error: bad argument type: lselsetp nil

The error occured because the "layer name" of the "blll" block was changed into "HH Block" (old "layer name" was "BLK"), that is the reason.

 

;; OLD
(setq ss (ssget "X" '((0 . "INSERT") (8 . "BLK") (2 . "blll")))

;; NEW
(setq ss (ssget "X" '((0 . "INSERT") (8 . "HH Block") (2 . "blll")))

 

Try this modified code:

 

; ************************************************************************
; Functions     :  CHCOLPL
; Description   :  Change the colors of the Polylines into the yellow
; Author        :  SAXLLE
; Date          :  January 08, 2025
; ************************************************************************

(prompt "\nTo run a LISP type: CHCOLPL")
(princ)

(defun c:CHCOLPL ( / ss len i ssn ename ent_pl data spt ept 2ndpt 3rdpt midpt lenn tlen k)
  (setq ss (ssget "X" '((0 . "INSERT") (8 . "HH Block") (2 . "blll")))
	len (sslength ss)
	i 0
	)
  (while (< i len)
    (setq ssn nil)
    (setq ename (ssname ss i))
    (command-s "_explode" ename "")
    (setq ent_pl (ssget "x" '((0 . "LWPOLYLINE") (8 . "BLK") (62 . 1) (70 . 1)))
	  data (entget (ssname ent_pl 0))
	  spt (cdr (nth 15 data))
	  2ndpt (cdr (nth 20 data))
	  3rdpt (cdr (nth 25 data))
	  ept (cdr (nth 30 data))
	  midpt (polar spt (angle spt ept) (/ (distance spt ept) 2))
	  )
    (command-s "_undo" 1 "")
    (setq ssn (ssget "_F" (list spt ept) '((0 . "LWPOLYLINE") (8 . "Poly"))))
    (if (/= ssn nil)
      (progn
	(setq lenn (sslength ssn))
	(if (= lenn 1)
	  (setq k 0)
	  (setq k 1)
	  )
	(setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn 0)) 'Length))
	(while (< k lenn)
	  (if (< tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length))
	    (progn
	      (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length)
		    sssn (ssname ssn k)
		    )
	      )
	    (progn
	      (setq sssn (ssname ssn k))
	      )
	    )
	  (setq k (1+ k))
	  )
	(setq eptn (vlax-curve-getEndPoint (vlax-ename->vla-object sssn)))
	(if (> (cadr midpt) (cadr eptn))
	  (progn
	    (setq ssn (ssget "_F" (list spt ept) '((0 . "LWPOLYLINE") (8 . "Poly"))))
	    (command-s "_chprop" ssn "" "c" 2 "")
	    )
	  (progn
	    (setq ssn (ssget "_F" (list 2ndpt 3rdpt) '((0 . "LWPOLYLINE") (8 . "Poly"))))
	    (if (/= ssn nil)
	      (progn
		(setq lenn (sslength ssn))
		(if (= lenn 1)
		  (setq k 0)
		  (setq k 1)
		  )
		(setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn 0)) 'Length))
		(while (< k lenn)
		  (if (< tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length))
		    (progn
		      (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length)
			    sssn (ssname ssn k)
			    )
		      )
		    (progn
		      (setq sssn (ssname ssn k))
		      )
		    )
		  (setq k (1+ k))
		  )
		(setq midpt (polar 2ndpt (angle 2ndpt 3rdpt) (/ (distance 2ndpt 3rdpt) 2)))
		(setq eptn (vlax-curve-getEndPoint (vlax-ename->vla-object sssn)))
		(setq ssn (ssget "_F" (list midpt eptn) '((0 . "LWPOLYLINE") (8 . "Poly"))))
		(command-s "_chprop" ssn "" "c" 2 "")
		)
	      )
	    )
	  )
	)
      (progn
	(setq ssn (ssget "_F" (list 2ndpt 3rdpt) '((0 . "LWPOLYLINE") (8 . "Poly"))))
	(if (/= ssn nil)
	  (progn
	    (setq lenn (sslength ssn))
	    (if (= lenn 1)
	      (setq k 0)
	      (setq k 1)
	      )
	    (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn 0)) 'Length))
	    (while (< k lenn)
	      (if (< tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length))
		(progn
		  (setq tlen (vlax-get-property (vlax-ename->vla-object (ssname ssn k)) 'Length)
			sssn (ssname ssn k)
			)
		  )
		(progn
		  (setq sssn (ssname ssn k))
		  )
		)
	      (setq k (1+ k))
	      )
	    (setq eptn (vlax-curve-getEndPoint (vlax-ename->vla-object sssn)))
	    (setq midpt (polar 2ndpt (angle 2ndpt 3rdpt) (/ (distance 2ndpt 3rdpt) 2)))
	    (setq eptn (vlax-curve-getEndPoint (vlax-ename->vla-object sssn)))
	    (setq ssn (ssget "_F" (list midpt eptn) '((0 . "LWPOLYLINE") (8 . "Poly"))))
	    (command-s "_chprop" ssn "" "c" 2 "")
	    )
	  )
	)
      )
    (setq i (1+ i))
    )
  (princ)
  )

 

After the test, i get this (see attached picture). The "white" color is sections which I made for testing, the "magenta" color present the polylines which are not changed, and the "red" color present the "one" polyline which are not starting from the "base point" of the "blll" block and the color was not changed into the "yellow". The "cyan" color present the position where the block "blll" is missing, and colors of the polylines didn't changed.

 

image.png.2f3e0b24ba3cf9e50ee36547b10834d2.png

 

 

Best regards.

Edited by Saxlle
Upload new picture and explanation in text
  • Thanks 1
Posted

For me, the code is working perfectly 100% 

That's all I need , Thanks again for your time and effort 🙏🌹

Posted (edited)

@Engineer_Yasser Some of your linework is not drawn as tight as your first example. Look at the start point of this polyline in relation to your block insertion point. To 'fix' my code up the variable 'fz' to something like 2.

image.thumb.png.157c82f9886b14bc3e03acffbd4704b4.png

 

In the scenario where the block is located on an end does it still pick a route since they are both on the same side?

image.png.cf08962ca5fafe542a7d7841faa99893.png

 

I'm curious, what are these drawings used for?

Test 2-FZ=2.dwg

Edited by ronjonp
  • Thanks 1
Posted
6 hours ago, Saxlle said:

You're welcome. I'm glad it helped. 🙂

@Saxlle IMO you should leave they layer filter out of the block: (ssget "X" '((0 . "INSERT") (2 . "blll")))

Posted

@ronjonp

I tested the code now and it worked very fast like a charm  💯
Thank you for your efforts in the testing and follow-up to reach the best result  💙

Posted
17 minutes ago, Engineer_Yasser said:

@ronjonp

I tested the code now and it worked very fast like a charm  💯
Thank you for your efforts in the testing and follow-up to reach the best result  💙

Glad to help .. if you don't mind what are these drawings used for?

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