TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Vandyck on September 25, 2016, 09:19:11 AM

Title: Change hatch background color
Post by: Vandyck on September 25, 2016, 09:19:11 AM
I need to change hatch color and background color, but "vla-put-backgroundcolor" don't work !

Code - Auto/Visual Lisp: [Select]
  1. (vla-put-Color (vlax-ename->vla-object (entlast)) 5)
it's ok... work

Code - Auto/Visual Lisp: [Select]
  1. (vla-put-BackgroundColor (vlax-ename->vla-object (entlast)) 2 )
don't work :-( and the error message is "; error: lisp value has no coercion to VARIANT with this type:  2"

the same effect have:
Code - Auto/Visual Lisp: [Select]
  1. (vlax-put-property (vlax-ename->vla-object (entlast)) 'backgroundcolor 2)

...there is something wrong...  :whistling:
Title: Re: Change hatch background color
Post by: Lee Mac on September 25, 2016, 09:32:19 AM
The ActiveX backgroundcolor property requires the colour to be configured through the use of the AcCmColor object (similar to configuring the truecolor property for an object).

In my opinion, the easiest way to do this through ActiveX (without the need to create a version-dependent colour object) is to use the colour object returned when querying the current colour for the property, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / col ent obj )
  2.     (if
  3.         (and
  4.             (setq ent (car (entsel "\nSelect hatch: ")))
  5.             (= "HATCH" (cdr (assoc 0 (entget ent))))
  6.         )
  7.         (progn
  8.             (setq obj (vlax-ename->vla-object ent))
  9.             (vla-put-color obj 5)
  10.             (setq col (vla-get-backgroundcolor obj))
  11.             (vla-put-colorindex col 2)
  12.             (vla-put-backgroundcolor obj col)
  13.         )
  14.     )
  15.     (princ)
  16. )
Title: Re: Change hatch background color
Post by: Vandyck on September 25, 2016, 06:16:32 PM
thank you very much Lee