Author Topic: Change hatch background color  (Read 1898 times)

0 Members and 1 Guest are viewing this topic.

Vandyck

  • Newt
  • Posts: 24
Change hatch background color
« 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:

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Change hatch background color
« Reply #1 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. )

Vandyck

  • Newt
  • Posts: 24
Re: Change hatch background color
« Reply #2 on: September 25, 2016, 06:16:32 PM »
thank you very much Lee