Jump to content

Select all Vertical/Horizontal Lines with Layer Name = PROCESS


barristann

Recommended Posts

Hi all, is it possible to modify this code to also only select Layer with Name = PROCESS

 

Thank you

https://www.cadeverything.com/help/showthread.php/7483-Vertical-horizontal-lines

---------------------

(defun c:VHlines (/ _Ang *error* kw s ss i sn e)
  ;;; Tharwat 13. Dec. 2012  ;;;
  (defun _Ang (e) (angle (cdr (assoc 10 e)) (cdr (assoc 11 e))))
  (defun *error* (msg) (princ "\n Error...*Cancelled*"))
  (if (and (progn (initget "Vertical Horizontal Both")
                  (setq kw (cond ((getkword "\n Specify one [Vertical/Horizontal/Both] <Both> :"))
                                 (t "Both")
                           )
                  )
           )
           (setq s  (ssadd)
                 ss (ssget "_x" (list '(0 . "LINE") (cons 410 (getvar 'ctab))))
           )
      )
    (progn
      (repeat (setq i (sslength ss))
        (setq sn (ssname ss (setq i (1- i)))
              e  (entget sn)
        )
        (cond ((eq kw "Vertical")
               (if (or (equal (_Ang e) (* pi 0.5)) (equal (_Ang e) (* pi 1.5)))
                 (ssadd sn s)
               )
              )
              ((eq kw "Horizontal")
               (if (or (equal (_Ang e) pi) (equal (_Ang e) 0.))
                 (ssadd sn s)
               )
              )
              (t
               (if (or (equal (_Ang e) (* pi 0.5)) (equal (_Ang e) (* pi 1.5)) (equal (_Ang e) pi) (equal (_Ang e) 0.))
                 (ssadd sn s)
               )
              )
        )
      )
      (sssetfirst nil s)
    )
  )
  (princ)
)

 

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

33 minutes ago, barristann said:

also only select Layer with Name = PROCESS

@barristann just change to 

 

(setq s  (ssadd)
                 ss (ssget "_x" (list '(0 . "LINE") ( 8 . "PROCESS") (cons 410 (getvar 'ctab))))
           )

  (8 . "PROCESS" ) do the trick to SSGET only at layer process. 

Link to comment
Share on other sites

Thanks for replying devitg. This is the error message if I do that

 

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).

Converting (command) calls to (command-s) is recommended.

Link to comment
Share on other sites

11 minutes ago, barristann said:

(command-s) is recommended.

@barristann

comment this line

 

;;;  (defun *error* (msg) (princ "\n Error...*Cancelled*"))

 

commen mean to put ;; before the line

 

Please upload your sample.dwg

 

 

Edited by devitg
add comment
Link to comment
Share on other sites

11 minutes ago, barristann said:

upload "confidential" dwg

Did you try by 

;;;  (defun *error* (msg) (princ "\n Error...*Cancelled*"))

  About your sample , just make a FAKE , non confidential DWG .

 

Link to comment
Share on other sites

I wished I were confident about doing that, devitg. I've just started this job so I'm so afraid that I'll accidentally upload something by mistake.

Link to comment
Share on other sites

2 minutes ago, barristann said:

so I'm so afraid that I'll accidentally upload something by mistake

@barristann Don worry, I make some changes . Please try this 

(defun c:VHlines-devitg (/ _Ang *error* kw s ss i sn e)
  ;;; Tharwat 13. Dec. 2012  ;;;
  (defun _Ang (e) (angle (cdr (assoc 10 e)) (cdr (assoc 11 e))))
  (defun *error* (msg) (princ "\n Error...*Cancelled*"))
  (if (and (progn (initget "Vertical Horizontal Both")
                  (setq kw (cond ((getkword "\n Specify one [Vertical/Horizontal/Both] <Both> :"))
                                 (t "Both")
                           )
                  )
           )
           (setq s  (ssadd))
            (setq   ss (ssget "_x" (list (cons 0  "LINE") (cons 8  "process") (cons 410 (getvar 'ctab)))))
      );end and
    
    (progn
      (repeat (setq i (sslength ss))
        (setq sn (ssname ss (setq i (1- i)))
              e  (entget sn)
        )
        (cond ((eq kw "Vertical")
               (if (or (equal (_Ang e) (* pi 0.5)) (equal (_Ang e) (* pi 1.5)))
                 (ssadd sn s)
               )
              )
              ((eq kw "Horizontal")
               (if (or (equal (_Ang e) pi) (equal (_Ang e) 0.))
                 (ssadd sn s)
               )
              )
              (t
               (if (or (equal (_Ang e) (* pi 0.5)) (equal (_Ang e) (* pi 1.5)) (equal (_Ang e) pi) (equal (_Ang e) 0.))
                 (ssadd sn s)
               )
              )
        )
      )
      (sssetfirst nil s)
    )
  )
  (princ)
)

 

image.png.6b4295f66f9138ab2451655627f63403.png

 Please try it 

 

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, devitg said:

@barristann

comment this line

 

;;;  (defun *error* (msg) (princ "\n Error...*Cancelled*"))

 

The problem is with your addition that you forgot to add quote ( ' ) in front of the open bracket.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Can this routine be revised to select only the lines that are not Vertical or Horizontal.  Just lines that are not 0, 90, 180, 270 degrees. My skills are limited and what I tried did not work out. 

Link to comment
Share on other sites

  • 3 weeks later...
On 7/27/2023 at 10:02 AM, GolferRob said:

are not Vertical or Horizontal

@GolferRob  here you have , you can chose  Ver-Hor- Both-none , none by default

 

 

(defun c:VHBNlines-devitg (/ _Ang *error* kw s ss i sn e)
  ;;; Tharwat 13. Dec. 2012  ;;;
  (defun _Ang (e) (angle (cdr (assoc 10 e)) (cdr (assoc 11 e))))
  (defun *error* (msg) (princ "\n Error...*Cancelled*"))
  (if (and (progn (initget "Vertical Horizontal Both None")
                  (setq kw (cond ((getkword "\n Specify one [Vertical/Horizontal/Both/None] <None> :"))
                                 (t "None")
                           )
                  )
           )
           (setq s  (ssadd))
            (setq   ss (ssget "_x" (list (cons 0  "LINE")  (cons 410 (getvar 'ctab)))))
      );end and
    
    (progn
      (repeat (setq i (sslength ss))
        (setq sn (ssname ss (setq i (1- i)))
              e  (entget sn)
        )
        (COND ((EQ KW "Vertical")
               (IF (OR (EQUAL (_ANG E) (* PI 0.5)) (EQUAL (_ANG E) (* PI 1.5)))
                 (SSADD SN S)
                 )
               )
              ((EQ KW "Horizontal")
               (IF (OR (EQUAL (_ANG E) PI) (EQUAL (_ANG E) 0.))
                 (SSADD SN S)
                 )
               )

              ((EQ KW "Both")
               (IF (OR (EQUAL (_ANG E) (* PI 0.5)) (EQUAL (_ANG E) (* PI 1.5)) (EQUAL (_ANG E) PI) (EQUAL (_ANG E) 0.))
                 (SSADD SN S)
                 )
               )

              (T
               (IF (NOT
                     (OR (EQUAL (_ANG E) (* PI 0.5)) (EQUAL (_ANG E) (* PI 1.5)) (EQUAL (_ANG E) PI) (EQUAL (_ANG E) 0.)))
                 (SSADD SN S)
                 )
               )

              );COND
      );repeat
      (sssetfirst nil s)
    );progn
  );if
  (princ)
); C:VHBNLINES-DEVITG

image.thumb.png.b492736b0c711019fb9aa811ee16b94a.png

Link to comment
Share on other sites

@devitg FWIW the code could be simplified like so using (REM ANGLE PI)
 

(defun c:vhlines-rjp (/ *error* ang e i s sn ss)
;;; Tharwat 13. Dec. 2012  ;;;
  ;; RJP » 2023-08-15
  (if (and (progn (initget "Vertical Horizontal Both")
		  (setq	kw (cond ((getkword "\n Specify one [Vertical/Horizontal/Both] <Both> :"))
				 ("Both")
			   )
		  )
	   )
	   (setq s (ssadd))
	   (setq ss (ssget "_X" (list '(0 . "LINE") (cons 410 (getvar 'ctab)))))
      )
    (progn ;; RJP - moved check out of loop
	   (setq kw (cadr (assoc kw
				 '(("Vertical" (equal ang (* pi 0.5) 1e-8))
				   ("Horizontal" (equal ang 0. 1e-8))
				   ("Both" (or (equal ang (* pi 0.5) 1e-8) (equal ang 0. 1e-8)))
				  )
			  )
		    )
	   )
	   (repeat (setq i (sslength ss))
	     (setq sn (ssname ss (setq i (1- i)))
		   e  (entget sn)
	     )
	     ;; RJP mod to return 0 or (* pi 1.5)
	     (setq ang (rem (angle (cdr (assoc 10 e)) (cdr (assoc 11 e))) pi))
	     (and (eval kw) (ssadd sn s))
	   )
	   (sssetfirst nil s)
    )
  )
  (princ)
)

 

(defun c:vhlines-rjp2 (/ *error* ang e i s sn ss)
;;; Tharwat 13. Dec. 2012  ;;;
  ;; RJP » 2023-08-15
  ;; Returns all lines NOT vertical or horizontal
  (if (and (setq s (ssadd)) (setq ss (ssget "_X" (list '(0 . "LINE") (cons 410 (getvar 'ctab))))))
    (progn (repeat (setq i (sslength ss))
	     (setq sn (ssname ss (setq i (1- i)))
		   e  (entget sn)
	     )
	     (setq ang (rem (angle (cdr (assoc 10 e)) (cdr (assoc 11 e))) pi))
	     (or (or (equal ang (* pi 0.5) 1e-8) (equal ang 0. 1e-8)) (ssadd sn s))
	   )
	   (sssetfirst nil s)
    )
  )
  (princ)
)
Edited by ronjonp
  • Like 2
Link to comment
Share on other sites

  • 9 months later...

Thank you for the reply. It was exactly what I was looking for. Just made a few tweaks for layers and line types for my application. 

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