Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why does vlax-get-property always return the color 256?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
cncah
583 Views, 7 Replies

Why does vlax-get-property always return the color 256?

I'm trying to use the vlax-get-property on several entities in a selection set and each entity is a different color, but when I use the:

(setq entColor (vlax-get-property oEnt 'Color))

 If keeps returning the color "256" on all entities in the selection set. Even though I know for a fact that they are all different colors. Is there a step I'm missing?

7 REPLIES 7
Message 2 of 8
dbroad
in reply to: cncah

256 means "bylayer".  So the objects may appear different colors because they are on different layers.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 8
cncah
in reply to: dbroad

So what would the proper way be of turning off "ByLayer" in lisp?

Message 4 of 8
cncah
in reply to: dbroad

Or a better question would be, how do I get the layer's color if the setting is "bylayer" instead of the 256?

Message 5 of 8
dgorsman
in reply to: cncah

First you need to test the entity color; if "fixed" then that is the color, if BYLAYER then you need to get the layer the entity is on and get the color of that layer, if BYBLOCK you need to check the parent block and get the color of that (which could in turn be BYLAYER).

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 6 of 8
Lee_Mac
in reply to: cncah

Below are example functions demonstrating how to obtain the colour of an entity or object (or the corresponding layer colour) using Vanilla AutoLISP or Visual LISP respectively:

 

Vanilla AutoLISP

 

(defun getentcolour ( ent / enx )
    (setq enx (entget ent))
    (cond
        (   (cdr (assoc 62 enx)))
        (   (abs (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 enx)))))))
    )
)

 

Test Program:

 

(defun c:test1 ( / ent )
    (if (setq ent (car (entsel)))
        (getentcolour ent)
    )
)

 

Visual LISP

 

(defun getobjcolour ( obj / col )
    (if (= acbylayer (setq col (vla-get-color obj)))
        (vla-get-color (vla-item (vla-get-layers (vla-get-document obj)) (vla-get-layer obj)))
        col
    )
)

 

Test Program:

 

(defun c:test2 ( / ent )
    (if (setq ent (car (entsel)))
        (getobjcolour (vlax-ename->vla-object ent))
    )
)

 

Message 7 of 8
cncah
in reply to: Lee_Mac

Thanks!

Message 8 of 8
dgorsman
in reply to: cncah

Getting the TrueColor property (returns as an AcCmColor object) provides a number of useful methods and properties, which also work with some useful constants like acRed and acByLayer.  These can make the code a little more human readable.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost