Jump to content

Change colour of ByLayer by selecting entity in drawing


woodman78

Recommended Posts

Those issues generally only exist when trying to entmod certain properties of newer type entities (MLeader, etc.) or any annotative object, but color/layer/linetype are not of that list.

 

As long as entities' colors being ByLayer it would have nil DXF 62 , that's what I experienced at least .

Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • woodman78

    5

  • Tharwat

    5

  • alanjt

    4

Top Posters In This Topic

Posted Images

As long as entities' colors being ByLayer it would have nil DXF 62 , that's what I experienced at least .

 

This is not an issue. Consider the following programs to change all primary entities to green. You can either test for the occurrence of the DXF 62 group code, altering it or appending it:

 

(defun c:alltogreen ( / el en ss )
   (if (setq ss (ssget "_X"))
       (while (setq en (ssname ss 0))
           (setq el (entget en))
           (entmod
               (if (assoc 62 el)
                   (subst (cons 62 3) (assoc 62 el) el)
                   (append el '((62 . 3)))
               )
           )
           (ssdel en ss)
       )
   )
   (princ)
)

 

Or, this could be simplified to:

 

(defun c:alltogreen ( / en ss )
   (if (setq ss (ssget "_X"))
       (while (setq en (ssname ss 0))
           (entmod (list (cons -1 en) '(62 . 3)))
           (ssdel en ss)
       )
   )
   (princ)
)

Link to comment
Share on other sites

I did not mean changing entity' color to a specific color but getting an entity's Color when its being ByLayer the DXF 62 would be equal to nil

Link to comment
Share on other sites

I did not mean changing entity' color to a specific color but getting an entity's Color when its being ByLayer the DXF 62 would be equal to nil

If the return is nil, then get it from the layer's entity dump.

 

(defun color (ename)
 ((lambda (entityData)
    (cdr (cond ((assoc 62 entityData))
               ((assoc 62 (tblsearch "LAYER" (cdr (assoc 8 entityData)))))
         )
    )
  )
   (entget ename)
 )
)

Link to comment
Share on other sites

If the return is nil, then get it from the layer's entity dump.

 

1+

 

I'd add the abs too:

 

(defun color ( ename )
 (
   (lambda ( entityData )
     (abs
       (cdr
         (cond
           ( (assoc 62 entityData))
           ( (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 entityData)))))
         )
       )
     )
   )
   (entget ename)
 )
)

Link to comment
Share on other sites

1+

 

I'd add the abs too:

 

(defun color ( ename )
 (
   (lambda ( entityData )
     (abs
       (cdr
         (cond
           ( (assoc 62 entityData))
           ( (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 entityData)))))
         )
       )
     )
   )
   (entget ename)
 )
)

Good point wasn't thinking about off layers, of course, it's kind of difficult to select objects on a layer that's turned off. LoL
Link to comment
Share on other sites

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