arka69 发表于 2022-7-6 17:08:54

Putting DXF's codes in, A

I´ve made a little function for changing easily attributes in entities
It goes like this
 
(defun atribsubst (valorcambiado grupocodigo nombreobjeto)
(entmod
(subst
(cons grupocodigo valorcambiado)
(assoc grupocodigo (entget nombreobjeto))
(entget nombreobjeto)
)
)
)
 
Works pretty well, but for dxf group codes which are on default (for which there's no entry in entities atribute's list to be SUBStituted doesn´t work.
 
So I added one fix with IF function...
 
(defun atribsubst2 (valorcambiado grupocodigo nombreobjeto)   
(entmod
    (if (not (assoc grupocodigo (entget nombreobjeto)))
;;;so if there are no entry I add it
      (cons (cons grupocodigo valorcambiado)
              (entget nombreobjeto))
;;;otherwise It works with same routine
      (subst                                                      
            (cons grupocodigo valorcambiado)                           
                  (assoc grupocodigo (entget nombreobjeto))                  
                  (entget nombreobjeto))                                    
    )
)
)
Which seem to work, no error, return the list. But after that, nothing changes...
 
I´ve used it to change color (dxf code 62) to red (n 1) of one poly wich was on "bylayer" (default, so there's no entry in its atrib list)
(atribsubst2 1 62 (car (entsel)))
 
It returns
((62 . 1) (-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "1B0") (100 . "AcDbEntity") so on...
 
But no color change, and doing
(entget (car (entsel)))
on same object returns
(-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "1B0") (100 . "AcDbEntity") so on...
 
:?
 
What am I doing wrong? I´m using acad 2008 :wink:

Lee Mac 发表于 2022-7-6 17:25:57

have you included the following code in your LISP:
 

(defun c:colourtest (/ ent1)   (setq ent1 (entget (car (entsel))))   (if (assoc 62 ent1)         (setq ent1 (subst (cons 62 1) (assoc 62 ent1) ent1))         (setq ent1 (cons (cons 62 1) ent1))   ) ;end if   (entmod ent1)   (princ))

arka69 发表于 2022-7-6 17:39:18

Yes, Check it, "entmod" it's just before the "if" function, so I don't have to write it two timesit works with the "if"output case.
 
I'm checking if your code works on my ACAD2008...
I'll let you know instantly

arka69 发表于 2022-7-6 17:45:37

Aha, it doesn´t work neither.
 
Guess it´s supossed to change the enitity color to red, even if it was set on "bylayer", but in this case doesn´t work.
 
Maybe it needs to have its right position on atrib list? I mean in acad 2008...?

Lee Mac 发表于 2022-7-6 18:06:46

ahh, sorry Arka - didnt spot the "entmod" in there.
 
All I can think is that it must be an ACAD 08 thing, because the LISP I posted works fine on ACAD 04.

arka69 发表于 2022-7-6 18:18:35

Yeah, I think so, it's one of the many advantages of having a too recent version...
Anyway, just for confirmation purposes... anybody can test the code "colortest" on an entity with color "bylayer" and running autocad 2008?
页: [1]
查看完整版本: Putting DXF's codes in, A