barristann Posted April 7, 2023 Share Posted April 7, 2023 (edited) 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 August 16, 2023 by SLW210 Added Code Tags! Quote Link to comment Share on other sites More sharing options...
devitg Posted April 7, 2023 Share Posted April 7, 2023 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. Quote Link to comment Share on other sites More sharing options...
barristann Posted April 7, 2023 Author Share Posted April 7, 2023 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. Quote Link to comment Share on other sites More sharing options...
devitg Posted April 7, 2023 Share Posted April 7, 2023 (edited) 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 April 7, 2023 by devitg add comment Quote Link to comment Share on other sites More sharing options...
barristann Posted April 7, 2023 Author Share Posted April 7, 2023 Sorry I'm not allowed to upload "confidential" dwg, devitg. That's okay thanks for trying, devitg. Quote Link to comment Share on other sites More sharing options...
devitg Posted April 7, 2023 Share Posted April 7, 2023 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 . Quote Link to comment Share on other sites More sharing options...
barristann Posted April 7, 2023 Author Share Posted April 7, 2023 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. Quote Link to comment Share on other sites More sharing options...
devitg Posted April 7, 2023 Share Posted April 7, 2023 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) ) Please try it 1 Quote Link to comment Share on other sites More sharing options...
barristann Posted April 7, 2023 Author Share Posted April 7, 2023 It works 100% devitg! Thank you so much for your help. You're amazing, devitg! Quote Link to comment Share on other sites More sharing options...
devitg Posted April 7, 2023 Share Posted April 7, 2023 22 minutes ago, barristann said: It works 100% devitg! Thank you so much for your help. You're amazing, devitg! @barristann Feel free to ask for any further help. 1 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 7, 2023 Share Posted April 7, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
GolferRob Posted July 27, 2023 Share Posted July 27, 2023 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. Quote Link to comment Share on other sites More sharing options...
devitg Posted August 15, 2023 Share Posted August 15, 2023 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 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted August 15, 2023 Share Posted August 15, 2023 (edited) @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 August 16, 2023 by ronjonp 2 Quote Link to comment Share on other sites More sharing options...
GolferRob Posted June 3 Share Posted June 3 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.