Jump to content

Recommended Posts

Posted

I found a Interesting Routine file to Convert Selected Object bylayer to True Colour.

I tried to modify the Lisp for my Drawing but I got Error as below.

To change objects' Bylayer colors to their Layers' colors as overrides,; error: Automation Error. Invalid argument color in IAcadEntity::put_Color
 

I want to select all the Object Automatically and convert to Index color. but when i try to run the lisp I got the error.

Can someone help me out on this.

 

Quote
Quote


(defun C:SECLC (/ ss obj )
  ;; = Selected Entity Colors to their Layer's Color [if Bylayer]
  (vl-load-com)
   (prompt "\nTo change objects' Bylayer colors to their Layers' colors as overrides,")
 (setq ss (ssget "_X" ))
  ;(setq ss (ssget))
  (repeat (sslength ss)

    (if (not (assoc 62 (entget (setq ent (ssname ss 0))))); color = Bylayer

      (progn ; then
        (setq obj (vlax-ename->vla-object ent))
        (vla-put-Color
          obj
          (cdr (assoc 62 (tblsearch "layer" (vla-get-Layer obj))))
        ); put-color

      ); progn

    ); if
    (ssdel ent ss)

  ); end repeat
); end defun

 

 

 

Thanks in Advance.

Posted

something like this?


;; = Selected Entity Colors to their Layer's Color [if Bylayer]
(vl-load-com)
(defun c:seclc (/ i ss ent)
  (prompt "\nChanging objects' Bylayer colors to their Layers' colors as overrides.")
  (setq i 0)
  (if (setq ss (ssget "_X"))
    (while (setq ent (ssname ss i))
      (if (not (assoc 62 (entget ent)))
        (vla-put-color (vlax-ename->vla-object ent) (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget ent)))))))
      )
      (setq i (1+ i))
    )
  )
  (princ)
)

Posted

Try this:

(defun vle-color-bylayer->layercolor (/ AcDoc LayerCol ssetObj)
	(ssget "_X"  (quote ((62 . 256))))
	(setq		AcDoc (vla-get-activedocument (vlax-get-acad-object))
				LayerCol (vla-get-layers AcDoc)
				ssetObj (vla-get-activeselectionset AcDoc)
	)
	(vlax-for Obj ssetObj
		(vl-catch-all-apply (function vla-put-color) (list Obj (vla-get-color (vla-item LayerCol (vla-get-layer Obj)))))
	)
	(vla-delete ssetObj)
	(princ)
)

 

Posted

Hey Rlx and Lido

Thank you so much for your Code, i have checked both of your code, 

@rlx your code working well as what i want,

@lido Thanks for your code, unfortunately this code didn't change anything.

 

Thanks again:celebrate:

Posted

Hm...

Strange. Please try one more time. I added an counter.

(defun vle-color-bylayer->index (/ AcDoc LayerCol n ssetObj)
	(ssget "_X"  (quote ((62 . 256))))
	(setq AcDoc (vla-get-activedocument (vlax-get-acad-object))
			LayerCol (vla-get-layers AcDoc)
			n 0
			ssetObj (vla-get-activeselectionset AcDoc)
	)
	(vlax-for Obj ssetObj
		(if (not (vl-catch-all-error-p (vl-catch-all-apply (function vla-put-color) (list Obj (vla-get-color (vla-item LayerCol (vla-get-layer Obj)))))))
		  (setq n (1+ n))
		)
	)
	(vla-delete ssetObj)
	(prompt (strcat "\n" (itoa n) " found."))
	(princ)
)

 

Posted (edited)

@lido : with colors it's not allways about what's there but also about what's not there : if an entity has a color it has a color code (group 62) , but if entity is color bylayer.....guess what's not there 🙂

 

what you want is probably something like this :

(defun c:tst ( / AcDoc AcLays)(vl-load-com)
  (setq AcDoc (vla-get-activedocument (vlax-get-acad-object)) AcLays (vla-get-layers AcDoc))
    (vlax-for layout (vla-get-layouts AcDoc) (vlax-for o (vla-get-block layout) (if (eq (vla-get-color o) 256)
      (vl-catch-all-apply 'vla-put-color (list o (vla-get-color (vla-item AcLays (vla-get-layer o)))))))))

Edited by rlx
Posted

@rlx

Yeah, you're right.

If the current color is set Bylayer, group code 62 is missing for entities that are drawn to these settings.
On the other hand, (ssget "_X" '((62 . 256))) creates a selection set that respects the selection filter but also includes the entities on the locked layers and the function vla-put-color crashes. Trying  (ssget "_:L+A" '((62 . 256))) I received nil, so that I used  the sequence with vl-catch-all-apply function.

Please check your function for the situation where you have locked layers into your drawing.

Posted

@lido

if object is on locked layer , function vla-put-layer will error / do nada , but that's where the catch-all-error is for. So I didn't forget , just wasn't in the mood to use is-write-enabled... 😛

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