LISP: entmod with patial list works on graphical entity but not on layer?
Try the two functions in the code below. EntTest works, but LayTest doesn't. Can anybody explain this behaviour?
(defun c:EntTest ( / ent col)
(setq
ent (entget (car (entsel)))
col (acad_colordlg (cdr (assoc 62 ent)))
)
(prin1
(entmod (list (assoc -1 ent) (cons 62 col)))
)
)
(defun c:LayTest ( / lay col)
(setq
lay (entget (tblobjname "LAYER" (cdr (assoc 8 (entget (car (entsel)))))))
col (acad_colordlg (cdr (assoc 62 lay)))
)
(prin1
(entmod (list (assoc -1 lay) (cons 62 col)))
)
)
Comments
-
I'm no help... I've never used entmod with just the entity name like that. Does it work for all entities? Does it fail for other tables?
0 -
One other thing... I just found out code 62 is optional... it may not be present if colour is By-Layer
0 -
Greg, thank you for responding. You are right: the group code for colour is optional for graphical entities. Although in BC this group code always seems to be present. But since the layer entity must have a group code 62, the presence or absence of the group code doesn't explain the different behaviour. The whole idea behind a partial list is to avoid having to check for the presence of an existing group code. According to this german tutorial this is possible in AutoCAD. Using EntTest2 I conclude that missing group codes are not added in BC.
(defun c:EntTest2 ( / ent col)
(setq
ent (entget (car (entsel)))
col (acad_truecolordlg (abs (cdr (assoc 62 ent))) nil)
)
(prin1
(entmod (list (assoc -1 ent) (assoc 62 col)))
)
(if (assoc 420 col)
(prin1
(entmod (list (assoc 420 col) (assoc -1 ent)))
)
)
)0 -
I made a very quick test here to try to change a text height in a text style in the STYLE table using the same (assoc -1 ...) approach and it does not work. My guess is it does not work for objects in tables.
The odd part is entmod returns the list as though it did succeed. It should return NIL if it fails.
I am still no help :-(
0 -
Greg, thanks for "playing" along with me. I have filed a support request.
0