Jump to content

need help with nested OR condition for looping through layers


aridzv

Recommended Posts

Hi.

I have a lisp that select all the objects in a drawing that are lines and belong to a specipic layer,

and then change them to differant layer according to a list.

I have 3 layers to check and change,

and I have tried to do it in one go, but I'm geeting an error ; error : bad argument type <(-4 . "<OR")> ; expected <INTEGER> at [invalid DXF/XED data].

here is the original lisp:

(defun c:test1 (/ Datalist ss f i ent eData)
 
(setq Datalist ; Color | Layer | Global Width

          '((54  "P_DN25-4" 0.05)
            (22  "P_DN32-6" 0.05)
            (94  "P_DN40-6" 0.1)  
            (6  "P_DN50-6" 0.15)
            (214  "P_DN50-10" 0.15)
	  )
  )

 (setvar 'CECOLOR "BYLAYER")
  
  (if (setq ss (ssget "_X" (append
			 '((0 . "LINE")(8 . "MAINLINE_PIPES")(-4 . "<OR"))
			     (mapcar '(lambda (c)(cons 62 c))
				       (mapcar 'car Datalist))
			 '((-4 . "OR>"))))
	    )
    (repeat (setq i (sslength ss))
      (setq ent (entget (setq e (ssname ss (setq i (1- i))))))
      (setq eData (mapcar '(lambda (d)
		 	(Cdr (assoc d ent))) '(62 10 11)))	
      
      (setq f (assoc (Car edata) Datalist))
      (entdel e)
      (entmakex
		(append (list (cons 0 "LWPOLYLINE")
	                          (cons 100 "AcDbEntity")
	                          (cons 100 "AcDbPolyline")
	                          (cons 90 (length (Cdr eData)))
	                          (cons 70 0)
			          (cons 8 (cadr f))
			      	  (cons 43 (caddr f))
			      )
	                    (mapcar (function (lambda (p) (cons 10 p))) (Cdr eData)))
			)
	    )
	  )
	  (princ)

  (if (setq ss (ssget "_X" (append
			 '((0 . "LINE")(8 . "ZONE_PIPES")(-4 . "<OR"))
			     (mapcar '(lambda (c)(cons 62 c))
				       (mapcar 'car Datalist))
			 '((-4 . "OR>"))))
	    )
    (repeat (setq i (sslength ss))
      (setq ent (entget (setq e (ssname ss (setq i (1- i))))))
      (setq eData (mapcar '(lambda (d)
		 	(Cdr (assoc d ent))) '(62 10 11)))	
      
      (setq f (assoc (Car edata) Datalist))
      (entdel e)
      (entmakex
		(append (list (cons 0 "LWPOLYLINE")
	                          (cons 100 "AcDbEntity")
	                          (cons 100 "AcDbPolyline")
	                          (cons 90 (length (Cdr eData)))
	                          (cons 70 0)
			          (cons 8 (cadr f))
			      	  (cons 43 (caddr f))
			      )
	                    (mapcar (function (lambda (p) (cons 10 p))) (Cdr eData)))
			)
	    )
	  )
	  (princ)
 
  (if (setq ss (ssget "_X" (append
			 '((0 . "LINE")(8 . "Circular sectors")(-4 . "<OR"))
			     (mapcar '(lambda (c)(cons 62 c))
				       (mapcar 'car Datalist))
			 '((-4 . "OR>"))))
	    )
    (repeat (setq i (sslength ss))
      (setq ent (entget (setq e (ssname ss (setq i (1- i))))))
      (setq eData (mapcar '(lambda (d)
		 	(Cdr (assoc d ent))) '(62 10 11)))	
      
      (setq f (assoc (Car edata) Datalist))
      (entdel e)
      (entmakex
		(append (list (cons 0 "LWPOLYLINE")
	                          (cons 100 "AcDbEntity")
	                          (cons 100 "AcDbPolyline")
	                          (cons 90 (length (Cdr eData)))
	                          (cons 70 0)
			          (cons 8 (cadr f))
			      	  (cons 43 (caddr f))
			      )
	                    (mapcar (function (lambda (p) (cons 10 p))) (Cdr eData)))
			)
	    )
	  )
	  (princ)
  
  (if (setq ss (ssget "_X" (append
			 '((0 . "LINE")(8 . "SPRAYLINES")(-4 . "<OR"))
			     (mapcar '(lambda (c)(cons 62 c))
				       (mapcar 'car Datalist))
			 '((-4 . "OR>"))))
	    )
    (repeat (setq i (sslength ss))
      (setq ent (entget (setq e (ssname ss (setq i (1- i))))))
      (setq eData (mapcar '(lambda (d)
		 	(Cdr (assoc d ent))) '(62 10 11)))	
      
      (setq f (assoc (Car edata) Datalist))
      (entdel e)
      (entmakex
		(append (list (cons 0 "LWPOLYLINE")
	                          (cons 100 "AcDbEntity")
	                          (cons 100 "AcDbPolyline")
	                          (cons 90 (length (Cdr eData)))
	                          (cons 70 0)
			          (cons 8 (cadr f))
			      	  (cons 43 (caddr f))
			      )
	                    (mapcar (function (lambda (p) (cons 10 p))) (Cdr eData)))
			)
	    )
	  )
	  (princ)

	)

 

and here is what I tried to do but gettig the error:

(defun c:test2 (/ Datalist ss f i ent eData)
 
(setq Datalist ; Color | Layer | Global Width

          '((54  "P_DN25-4" 0.05)
            (22  "P_DN32-6" 0.05)
            (94  "P_DN40-6" 0.1)  
            (6  "P_DN50-6" 0.15)
            (214  "P_DN50-10" 0.15)
	  )
  )

 (setvar 'CECOLOR "BYLAYER")
  
  (if (setq ss (ssget "_X" (append '((0 . "LINE") ((-4 . "<OR") (8 . "MAINLINE_PIPES") (8 . "ZONE_PIPES") (8 . "Circular sectors") (8 . "SPRAYLINES") (-4 . "OR>")) (-4 . "<OR")) (mapcar '(lambda (c)(cons 62 c))  (mapcar 'car Datalist))  '((-4 . "OR>")))))
			 			     				      				    
    (repeat (setq i (sslength ss))
      (setq ent (entget (setq e (ssname ss (setq i (1- i))))))
      (setq eData (mapcar '(lambda (d)
		 	(Cdr (assoc d ent))) '(62 10 11)))	
      
      (setq f (assoc (Car edata) Datalist))
      (entdel e)
      (entmakex
		(append (list (cons 0 "LWPOLYLINE")
	                          (cons 100 "AcDbEntity")
	                          (cons 100 "AcDbPolyline")
	                          (cons 90 (length (Cdr eData)))
	                          (cons 70 0)
			          (cons 8 (cadr f))
			      	  (cons 43 (caddr f))
			      )
	                    (mapcar (function (lambda (p) (cons 10 p))) (Cdr eData)))
			)
	    )
	  )
	  (princ)

	)

 

what am I doing wrong here?...

 

Thanks,

Ari.

Edited by aridzv
Link to comment
Share on other sites

The sections of ssget that are strings you can just use , to select multiples instead of (-4 . "<or").

simplified the color filter by removing the mapcar since its short list.

Also used the foreach method instead of using i

 

(defun c:test (/ Datalist ss ent eData f)
  (setvar 'CECOLOR "BYLAYER")
  (setq Datalist '((6 "P_DN50-6" 0.15)(22 "P_DN32-6" 0.05)(54 "P_DN25-4" 0.05)(94 "P_DN40-6" 0.10)(214 "P_DN50-10" 0.15)))
    (if (setq ss (ssget "_X" '((0 . "LINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,Circular sectors,SPRAYLINES") (-4 . "<or") (62 . 6) (62 . 22) (62 . 54) (62 . 94) (62 . 214) (-4 . "or>"))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq eData (mapcar '(lambda (d) (cdr (assoc d (entget ent)))) '(62 10 11)))
      (entdel ent)
      (setq f (assoc (car edata) Datalist))
      (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0)
                      (cons 8 (cadr f))
                      (cons 43 (caddr f))
                      (cons 10 (cadr eData))
                      (cons 10 (caddr eData))
                )
      )
    )
  )
  (princ)
)

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@mhupp

Thanks!!! (Again... 🙂  )

What I did not realized is that i can use this: (8 . "MAINLINE_PIPES,ZONE_PIPES,Circular sectors,SPRAYLINES") and the "," is like OR condition.

 

I've made a small change to the code, deleteing the OR condition of the colors since they appear in the list and the loop compare the original color and assign the lines to the new layer that have the color and the line width according to the condition in the list.

here is the relevant code segment that I've changed a little (the actual datalist contains about 35 layers so I obviously didn't copied all of them...) :

 

    (if (setq ss (ssget "_X" '((0 . "LINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,Circular sectors,SPRAYLINES"))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq eData (mapcar '(lambda (d) (cdr (assoc d (entget ent)))) '(62 10 11)))
      (entdel ent)
      (setq f (assoc (car edata) Datalist))
      (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0)
                      (cons 8 (cadr f))
                      (cons 43 (caddr f))
                      (cons 10 (cadr eData))
                      (cons 10 (caddr eData))
                )
      )
    )
  )	

 

I've attached the full lisp here as a file.

Thanks Again,

Ari.

test3.lsp

Edited by aridzv
  • Like 2
Link to comment
Share on other sites

  • aridzv changed the title to need help with nested OR condition for looping through layers

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