Jump to content

Set entity color


(car (entsel))

Recommended Posts

Hello everybody,

The following works with circle, line but not with lwpolyline, spline:

(defun C:RT ( / ent data )
(if (setq ent (car (entsel "\nSelect object to change its color")))
	(progn	
		(if (not (assoc 62 (setq data (entget ent))))
			(setq data (append (list (cons 62 1)) data))
			(setq data (subst (cons 62 1) (assoc 62 data) data))
		)
		(entupd (cdr (assoc -1 (entmod data))))
	)
)
(princ)
)

Is there an easy fix for this?

Link to comment
Share on other sites

Try this :-

 

(defun c:test ( / a b i)
 (if (setq a (ssget '((0 . "*line,circle,ellipse,point"))))
   (repeat (setq i (sslength a))
     (setq b (vlax-ename->vla-object (ssname a (setq i (1- i)))))
     (vla-put-color b 1)
   )
 )
 (princ)
)

Link to comment
Share on other sites

One more!

(defun C:RT ( / EOBJ )
(setq EOBJ (entsel "\nSelect object to change its color"))
(if EOBJ (vl-catch-all-apply 'vla-put-Color (list (vlax-ename->vla-object (car EOBJ)) 1)))
(princ)
)

Edited by tombu
Updated to avoid error for a null argument Lee Mac pointed out.
Link to comment
Share on other sites

Thanks guys, now I see the problem in my code:

(setq data (append (list (cons 62 1)) data))

must be:

(setq data (append data (list (cons 62 1))))

Link to comment
Share on other sites

One more!
(defun C:RT ( / EOBJ )
(if (setq EOBJ (vlax-ename->vla-object  (car (entsel "\nSelect object to change its color"))))
	(vl-catch-all-apply 'vla-put-Color (list EOBJ 1))
)
(princ)
)

 

Careful - vlax-ename->vla-object will error for a null argument ;)

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