Author Topic: Select all objects on a color  (Read 6549 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Select all objects on a color
« Reply #15 on: May 24, 2005, 07:47:50 PM »
danny, I'd do it by placing each pair of colors/layers into a list, then calling the function in a foreach or mapcar, like this:
Code: [Select]

(setq colorlist '((7 . "_XBOLD")
 (2 . " _BOLD")
 (4 . "_MED")
 (1 . " _FINE")
 (5 . "_XFINE")
 (8 . "_XXFINE")
 ))

(foreach x colorlist
  (color2layer (car x) (cdr x))
  )


danny

  • Guest
Select all objects on a color
« Reply #16 on: May 24, 2005, 08:05:25 PM »
hmm.  I got an error
Code: [Select]
Automation Error. Calling method SetObjectId of interface IAcadBaseObject failed
this what I used
Code: [Select]
(defun color2layer (color layer / atts doc lay lays lokt)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for lay (vla-get-layers doc)
    (if (and (= color (vla-get-color lay))
    (not (vl-string-search "|" (vla-get-name lay)))
    )
(setq lays (cons (vla-get-name lay) lays))
      )
    (if (eq :vlax-true (vla-get-lock lay))
      (progn
(setq lokt (cons (vla-get-name lay) lokt))
(vla-put-lock lay :vlax-false)
)
      )
    )
  (vla-startundomark doc)
  (setq lay (vla-add (vla-get-layers doc) layer))
  (vla-put-color lay color)
  (vlax-for blk (vla-get-blocks doc)
    (vlax-for ent blk
      (if (or (eq (vla-get-color ent) color)
     (member (vla-get-layer ent) lays)
     )
(vla-put-layer ent layer)
)
      (if (and (vlax-property-available-p ent "hasattributes")
      (vla-get-hasattributes ent)
      (setq atts (vlax-invoke ent "getattributes"))
      )
(progn
 (foreach att atts
   (if (or (eq (vla-get-color att) color)
   (member (vla-get-layer att) lays)
   )
     (vla-put-layer att layer)
     )
   (vla-update att)
   )
 )
);
     
      )
    )
  (if lokt
    (foreach lay lokt
      (vla-put-lock (vla-item (vla-get-layers doc) lay) :vlax-true)
      )
    )
  (vla-endundomark doc)
  (princ)
  )

;;sample usage
(defun c:col2lay ()
(setq colorlist '((7 . "_XBOLD")
        (2 . " _BOLD")
        (4 . "_MED")
        (1 . " _FINE")
        (5 . "_XFINE")
        (8 . "_XXFINE")
        ))

(foreach x colorlist
  (color2layer (car x) (cdr x))
  )
  (princ)
  )

It set "_XBOLD" to all the layers.  Forced colors as well as bylayer.[/quote]

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Select all objects on a color
« Reply #17 on: May 24, 2005, 09:53:08 PM »
Quote from: danny
hmm.  I got an error
Code: [Select]
Automation Error. Calling method SetObjectId of interface IAcadBaseObject failed

This is due to there being a leading space in a layer name. Check the list and remove any spaces......I know the list I posted had them, sorry about that, I didn't check it before posting.
Quote from: danny

this what I used
<snip>
It set "_XBOLD" to all the layers.  Forced colors as well as bylayer.

Try it again with the revised list. If it still comes out funky could you email me a portion of the drawing in R2000 format?

danny

  • Guest
Select all objects on a color
« Reply #18 on: May 24, 2005, 10:14:15 PM »
cool....Its working.
Much mahalo's Jeff  :D