Jump to content

Recommended Posts

Posted

I am trying to change all 250 color to white in all layouts, but I receive an error: error: bad SSGET list

(foreach tab (layoutlist) (setvar 'CTAB tab)
(if (setq clr (ssget "X" (list '((-4 . "&=")(62 . 250) (cons 410 tab))))) (command "CHPROP" clr "" "C" 7 ""))
)

 

Posted (edited)

Command CCL, for Change Color Layouts.

I commented out the command that sets the active layout.  Put it back if you really want.

 

The main thing is entmod (modify entities by adding or changing the data group).

Obviously don't take my layoutlist function.
 

;; dummy function just for my simple test.  You have your own
(defun layoutlist ( / )
    (list
        "Layout1"
        "Layout2"
        "Layout3"
    )
)

(defun c:ccl ( / tab i clr ent col)
    (setq col 7)    ;; destination color
    (foreach tab (layoutlist) 
            ;; you don't need to set the layout active.  You can if you really want
        ;; (setvar 'CTAB tab)
        (if (setq clr (ssget "X" (list (cons 62 250) (cons 410 tab)) ))  (progn
            (setq i 0)
            (repeat (sslength clr)
                (setq ent (ssname clr i))
                ;; modify color
                (if (assoc 62 (entget ent))  
                    (entmod (subst (cons 62 col)     (assoc 62 (entget ent))     (entget ent) ))      ;; substitute color
                    (entmod (append (entget ent) (list (cons 62 col)  ) ))                            ;; add color
                )
                (setq i (+ i 1))
            )
        ))
    )
)

 

Edited by Emmanuel Delay
  • Like 2
Posted

@Emmanuel Delay good stuff. :)

Your code does not require the second entmod function because it won't reach it due to grapping objects on un-bylayer objects.

Posted
3 minutes ago, Tharwat said:

@Emmanuel Delay good stuff. :)

Your code does not require the second entmod function because it won't reach it due to grapping objects on un-bylayer objects.

Ah, indeed, it's not needed in this case

Posted

Just as a learning point, this is common I think that there is a confusion between (list and '(

 

Both create lists.

 

Look online for the differences in making up lists but hopefully below will give you something to think about.

 

Anything after '( is a fixed list, CAD won't evaluate anything in that list

Anything after (list and CAD can evaluate anything in that list

 

For example

'( 1 2 3 4 5) is OK, the list is (1 2 3 4 5)

'( (cons 1 2) 3 4 5) does not make a list '( (1 2) 3 4 5), the list is as typed ( (cons 1 2) 3 4 5) (and will be an error since 'cons' will be seen as a string, wanting it written as "cons")

 

(list 1 2 3 4 5) is also OK, the list is also (1 2 3 4 5)

(list (cons 1 2) 3 4 5) will make the list ( (1 2) 3 4 5), the (cons 1 2) is worked out to make a list (1 2) and used in the list

 

 

looking at your example

 

(ssget "X" (list '((-4 . "&=")(62 . 250) (cons 410 tab)))))


(list .....) will evaluate what is after that, and then the next characters '(.... will create a fixed list, as it is typed, the (cons 410 tab) will not be calculated and in fact, will be an error since the '(.... wants that written out as ("cons" 410 "tab"). It is wanting (ssget "X" (list '((-4 . "&=")(62 . 250) ("cons" 410 "tab"))))) - noting the "

 

Changing it about, make the '(... into (list....., CAD also likes list items to be specified as list items, often wanting what is in the list to have a '(, a (list, or a (cons before each item

 

 

the next problem is that the lists (eg (-4 . "&=") ) creating your list need to be specified as lists, put a ' before them, use cons or list to create a list

 

Which gives this, and that does what you want I think

 (ssget "X" (list '(-4 . "&=") '(62 . 250) (cons 410 tab) ))

 

(foreach tab (layoutlist) (setvar 'CTAB tab)
  (if (setq clr (ssget "X" (list '(-4 . "&=") '(62 . 250) (cons 410 tab) )) )
   (command "CHPROP" clr "" "C" 7 "")
  ) ; end if
) ;end foreach

 

 

and just to emphasise a point you can also do this like this

 

(foreach tab (layoutlist) (setvar 'CTAB tab)
  (if (setq clr (ssget "X" (list (cons -4 "&=") (cons 62 250) (cons 410 tab) )) )
   (command "CHPROP" clr "" "C" 7 "")
  ) ; end if
) ;end foreach

 

  • Like 1
Posted

I noticed that if I use in a script file:

(if (setq clr1 (ssget "X" (list '(-4 . "&=") '(62 . 250) (cons 410 "Model")))) (command "CHPROP" clr1 "" "C" 251 ""))
(if (setq clr2 (ssget "X" (list '(-4 . "&=") '(62 . 254) (cons 410 "Model")))) (command "CHPROP" clr2 "" "C" 253 ""))

The last line is changing the color to 251 instead 253. Why?
If I switch the lines, all it's OK.

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