Jump to content

lisp to change lines by color stoped working - error ----- Error around expression ----- ; (CADDR EDATA)


Recommended Posts

Posted (edited)

Hi.

I have a lisp that move lines from layers to layers by their coloros.

the original lines come from 3 layers:

1. MAINLINE_PIPES

2. ZONE_PIPES

3. SPRAYLINES

fro some reason the lisp convert the lines from MAINLINE_PIPES layer and stop there and raise an error.

I attached a sample file and the lisp.

Any help will be appreciated!!

thanks,

aridzv.

PipeConvert_IRRI_UPDATE.lsp test.dwg

Edited by aridzv
Posted

As a helpful hint to us... what error did it tell you? Just to make sure we're getting the same error

Posted

Try this, not sure if it the right fix. The errors it was giving me was for bad dxf group 8 and 43 which are used in the entmake part, (cons 8 and (cons 43 referring to variable f. Looking at that some of the foreach loop 'ent' don't get anything from the datalist.... so ignore them - see if it works

 

 

(defun c:PipeConvert_IRRI_UPDATE (/ Datalist ss f i ent eData)
 
  (setq Datalist ; Color | Layer | Global Width
          '((174  "P_DN20-4" 0.05)
            (54  "P_DN25-4" 0.05)
            (51  "P_DN25-6" 0.05)
            (21  "P_DN32-4" 0.1)
            (22  "P_DN32-6" 0.1)
            (26  "P_DN32-8" 0.1)
            (122  "P_DN40-4" 0.1)  
            (94  "P_DN40-6" 0.1)
            (116  "P_DN40-8" 0.1)  
            (6  "P_DN50-6" 0.15)
            (230  "P_DN50-8" 0.15)
            (214  "P_DN50-10" 0.15)
            (4  "P_DN63-6" 0.15)
            (120  "P_DN63-8" 0.15)
            (58  "P_DN63-10" 0.15)
            (202  "P_DN75-6" 0.15)
            (208  "P_DN75-8" 0.15)
            (206  "P_DN75-10" 0.15)
            (178  "P_DN75-12.5" 0.15)
            (1  "P_DN90-6" 0.2)
            (238  "P_DN90-8" 0.2)
            (14  "P_DN90-10" 0.2)
            (3  "P_DN110-6" 0.25)
            (134  "P_DN110-8" 0.25)
            (81  "P_DN110-10" 0.25)
            (91  "P_DN110-12.5" 0.25)
            (254  "P_DN125-6" 0.2)  
            (8  "P_DN140-6" 0.2)
            (121  "P_DN140-8" 0.2)
            (111  "P_DN140-10" 0.2)
            (5  "P_DN160-6" 0.3)
            (172  "P_DN160-8" 0.3)
            (171  "P_DN160-10" 0.3)
            (176  "P_DN160-12.5" 0.3)  
            (231  "P_DN200-6" 0.3)
            (20  "P_DN225-6" 0.3)
            (200  "P_DN225-8" 0.3)
            (201  "P_DN225-10" 0.3)
            (204  "P_DN225-12.5" 0.3)
            (2  "P_DN250-6" 0.3)
            (56  "P_DN250-12.5" 0.3)
            (82  "P_DN280-6" 0.3)
            (92  "P_DN280-8" 0.3)
            (86  "P_DN280-10" 0.3)
            (96  "P_DN280-12.5" 0.3)
            (7  "P_DN315-6" 0.3)
            (9  "P_DN315-8" 0.3)
            (253  "P_DN315-10" 0.3)
            (252  "P_DN315-12.5" 0.3)
            (112  "P_DN355-6" 0.3)
            (52  "P_DN450-6" 0.3)
	  ) ; end list
  ) ; end setq Datalist

  (setvar 'CECOLOR "BYLAYER") ;;Remember to change variable back to what it was after
  
  (if (setq ss (ssget "_X" '((0 . "LINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,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)
      (if (setq f (assoc (car edata) Datalist))
        (progn
          (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))
                    ) ; end list
          ) ; end entmake
        ) ; end progn
      ) ; end if
    ) ; end foreach
  ) ; end if
  (princ)
)

 

 

I'd also consider taking out the (setvar line and putting in a (cons 62 256) line in the entmakex part, something linke:

 

          (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0)
                           (cons 8 (cadr f))
                           (cons 43 (caddr f))
                           (cons 62 256)
                           (cons 10 (cadr eData))
                           (cons 10 (caddr eData))
                    ) ; end list
          ) ; end entmakex

 

Just saves recording a system variable, change it and change it back at the end of the LISP and adding an error function - so that the user gets left with their system as they started. 1 line instead of many to go wrong

 

Posted
15 minutes ago, Steven P said:

As a helpful hint to us... what error did it tell you? Just to make sure we're getting the same error

Hi @Steven P

I did some digging and found two problems:

 

1. in the SPRAYLINE layer there where 2D POLYLINE objects and the lisp only looking for lines.

2. the objects in the SPRAYLINE layer where with color 234, and in the lisp there no layer with that color defenition.

 

when I corrected those two mistakes the lisp run good.

 

that leads me to ask fpr help on those two issues:

1. is it possible to add error handeler that will make the lisp to ignor errors and continue?

2. I tried to add 2D polylines to the selection set this way, but failed:

(if (setq ss (ssget "_X" '((0 . "LINE,POLYLINE,LWPOLYLINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,SPRAYLINES"))))

 

Any help will be appreciated!!

thanks,

aridzv.

  • Like 1
Posted (edited)

1. See above - think we were typing at the same time

2. 2d polylines, use a wild card, should get everything.

(if (setq ss (ssget "_X" '((0 . "*LINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,SPRAYLINES"))))

In the code you are looking at the coordinates for the ends of the line using dxf groups 10 and 11, polyline coordinates only use code 10 for each vertex, you might need to adjust how you get the start and end points to do the same as you are doing. Might be tempted to do as you are doing for lines and then since you want to end with polylines do a second ssget and foreach loop with them and entmod the polylines you have at the moment to colour, layer and so on (I'd have o check, entmod a line to (0 . "LWPOLYLINE"), will it all go wrong?)

Edited by Steven P
Posted

@Steven P

Hi and thanks for the help.

the foreach didn't work unfortunately...

it did skip the empty items and assign the line to the correct layer and as polyline,

but it give a white color to the lines, while the color property show "by layer" and the layer has a spesipic color...

 

thanks any how,

aridzv.

 

Posted

it is working for me I think, just had another look. There are a couple of lines in the example that will be black because of the layer colour but all the rest go by-layer - for me

 

Just to check which lines are white colour? Is it the lines you change top be polylines or is it the lines that are polylines to start with?

Posted (edited)

@Steven P

Hi.

see in this topic - 

@mhupp helped me with the error handeling if a line color dosn't excist in the list,

and changed the code a bit, using only CONS10,

change that allowed me to make this change to include polylines:

 the original code - only for LINE:
(if (setq ss (ssget "_X" '((0 . "LINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,SPRAYLINES"))))

changed to this to include polylines as well:
 (if (setq ss (ssget "_X" '((0 . "LINE,LWPOLYLINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,SPRAYLINES"))))

 

here is the final code that I'm using:

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

          '((174  "P_DN20-4" 0.05)
            (24  "P_DN16-4" 0.05)
            (234  "P_DN16-6" 0.05)
            (54  "P_DN25-4" 0.05)
            (51  "P_DN25-6" 0.05)
            (21  "P_DN32-4" 0.1)
            (22  "P_DN32-6" 0.1)
            (26  "P_DN32-8" 0.1)
            (122  "P_DN40-4" 0.1)  
            (94  "P_DN40-6" 0.1)
            (116  "P_DN40-8" 0.1)  
            (6  "P_DN50-6" 0.15)
            (230  "P_DN50-8" 0.15)
            (214  "P_DN50-10" 0.15)
            (4  "P_DN63-6" 0.15)
            (120  "P_DN63-8" 0.15)
            (58  "P_DN63-10" 0.15)
            (202  "P_DN75-6" 0.15)
            (208  "P_DN75-8" 0.15)
            (206  "P_DN75-10" 0.15)
            (178  "P_DN75-12.5" 0.15)
            (1  "P_DN90-6" 0.2)
            (238  "P_DN90-8" 0.2)
            (14  "P_DN90-10" 0.2)
            (3  "P_DN110-6" 0.25)
            (134  "P_DN110-8" 0.25)
            (81  "P_DN110-10" 0.25)
            (91  "P_DN110-12.5" 0.25)
            (254  "P_DN125-6" 0.2)  
            (8  "P_DN140-6" 0.2)
            (121  "P_DN140-8" 0.2)
            (111  "P_DN140-10" 0.2)
            (5  "P_DN160-6" 0.3)
            (172  "P_DN160-8" 0.3)
            (171  "P_DN160-10" 0.3)
            (176  "P_DN160-12.5" 0.3)  
            (231  "P_DN200-6" 0.3)
            (20  "P_DN225-6" 0.3)
            (200  "P_DN225-8" 0.3)
            (201  "P_DN225-10" 0.3)
            (204  "P_DN225-12.5" 0.3)
            (2  "P_DN250-6" 0.3)
            (56  "P_DN250-12.5" 0.3)
            (82  "P_DN280-6" 0.3)
            (92  "P_DN280-8" 0.3)
            (86  "P_DN280-10" 0.3)
            (96  "P_DN280-12.5" 0.3)
            (7  "P_DN315-6" 0.3)
            (9  "P_DN315-8" 0.3)
            (253  "P_DN315-10" 0.3)
            (252  "P_DN315-12.5" 0.3)
            (112  "P_DN355-6" 0.3)
            (52  "P_DN450-6" 0.3)
	  )
  )

 (setvar 'CECOLOR "BYLAYER")

  (if (setq ss (ssget "_X" '((0 . "LINE,LWPOLYLINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,SPRAYLINES"))))
    (foreach ent (mapcar 'cadr (ssnamex SS))
      (setq eData (mapcar '(lambda (d) (cdr (assoc d (entget ent)))) '(62 10 11)))
      (if (setq f (assoc (car edata) Datalist)) ;if f # isnt found skip entity
        (progn
          (ssdel ent ss) 
          (entmake (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))
                   )
          )
        )
      )
    )
  )	

  ;;(vla-endundomark doc)
  (princ)
)  

 

thanks for your help - it gave me lids on how to get it right!!!

aridzv.

Edited by aridzv
  • Like 1
Posted

No problem, I'd seen MHupps answer - usually a good solution - and thought he'd fix a few things in it too but didn't get chance to look at it working yet.

  • Thanks 1

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