Jump to content

Syntax to specify non-standard colours


pixel8er

Recommended Posts

Hi everyone

I'm wondering what the syntax is to specify non-standard colours? For instance this code uses the standard ACI colour 150

 

(setq c 150)

 

How would I specify a Colourbook DIC or RAL colour? Or an RGB colour? Or a Pantone colour?

 

I've tried putting the numbers/text in brackets and in "quotes" but it didn't work.

 

Many thanks for any help

Paul

Link to comment
Share on other sites

As grrr said, tho oit is for index colors (like layers color 1rst tab). That function name is somehow misleading imo. If you want a "true color" (rgb, like the 2nd tab), it is a little bit more sneaky. You have to retrieve any object "true color", than you can set it to the RGB values you want and than apply that new color. Here's an example to change a layer's color to a rbg gray

 

(defun setlayrgbgray (lay / laytbl myColor)
  (setq laytbl  (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))))
  (setq myColor (vla-Get-TrueColor (vlax-ename->vla-object(tblobjname "layer"(cdr(assoc 2 (tblnext "layer" t)))))))
  ;(vlax-invoke-method myColor 'SetRGB  77 77 77)
  (vla-SetRGB myColor 94 133 151)
  (if (tblsearch "LAYER" lay)
    (vla-Put-TrueColor (vla-item laytbl lay) myColor)
    (princ (strcat "\nLayer " (strcase lay) " does not exist")) )
  (princ)
 )

If we were usefull, please mark our replies accordingly. Thanks
cheers. Beer-ô-clock! :)

Link to comment
Share on other sites

5 hours ago, Grrr said:

Use this and observe the return:


(acad_truecolordlg 1 t)

 

Hi Grrr. This brings up the select color dialogue box and has colour 1 selected. Sorry but I'm not sure how to use this to set an RGB or Pantone colour

Link to comment
Share on other sites

11 hours ago, pixel8er said:

How would I specify a

 

5 hours ago, pixel8er said:

Hi Grrr. This brings up the select color dialogue box and has colour 1 selected. Sorry but I'm not sure how to use this to set an RGB or Pantone colour

 

Hi Paul,

Specifying(prompting/getting) and setting are different things.

When you use that dialogue box to specify say to some colorbook->pantone colour you should get something like this returned:

((62 . 135) (420 . 5415845) (430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U"))

If you specify a true color, via the "True Color" menu tab it will return something like this:

((62 . 135) (420 . 5415845))

However if you just specify ACI color it will be:

((62 . 135))

If you observe the group codes - 62 is for the ACI, 420 is for True Color, and 430 is for ColorBook.

And as you can see, the value for the True Color isn't RGB, what you'd expected.

So depending on the purpose of your program you might want to use Jef!'s activex approach (which is more comfortable for RGB) or use some of Lee's color conversion functions

 

BTW for setting, you just need to append the color returned from the dialog to the entity's dxf list and entmod(update) it:

(entmod (append (entget (car (entsel "\nPick an entity: "))) (acad_truecolordlg 1 t)))

or just use a hardcoded color value, obtained from the dialog.

  • Like 1
Link to comment
Share on other sites

On 11/10/2018 at 8:01 AM, Jef! said:

You have to retrieve any object "true color", than you can set it to the RGB values you want and than apply that new color. Here's an example to change a layer's color to a rbg gray

 

Thanks Jef! I'm not sure how to implement that approach with my basic lisp knowledge. In the code I have

(setq c 150)

sets the colour of solid hatch that will be created

Link to comment
Share on other sites

16 hours ago, Grrr said:

Specifying(prompting/getting) and setting are different things.

 

Aah ok, I didn't know that. Setting the colour for future use is what I want to do

 

16 hours ago, Grrr said:

or just use a hardcoded color value, obtained from the dialog.

 

if I use this

(setq c ((62 . 135) (420 . 5415845) (430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U") ))

 

it returns ; error: bad argument type: consp 5415845

Link to comment
Share on other sites

25 minutes ago, pixel8er said:

it returns ; error: bad argument type: consp 5415845

 

so after doing some reading on Lee Mac's awesome website the consp part means 

Quote

A function requiring a list argument has been passed an argument of incorrect data type with the value noted in the error message. Can be generated by passing any of thec..r functions, foreach, member, nth, or vl-sort-i functions an invalid list argument.

 

mmmm...not sure why it's an incorrect data type 

Edited by pixel8er
Link to comment
Share on other sites

8 minutes ago, pixel8er said:

(setq c ((62 . 135) (420 . 5415845) (430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U") ))

 

the 5415845 part in the error: bad argument type: consp 5415845 is from the True Colour text part of the code...

Link to comment
Share on other sites

On 11/10/2018 at 10:30 PM, pixel8er said:

the 5415845 part in the error: bad argument type: consp 5415845 is from the True Colour text part of the code...

Lisp evaluates everything, so if you want/need to set a list without evaluating any part (like here, in your example) to a variable I would recommend quoting (once) the whole list

(setq c '((62 . 135) (420 . 5415845) (430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U") ))

If you need to evaluate a part, ie lets say you use the same code for different layers, and the layer name would be in a variable "lay",  and need to build the appropriate portion then I would use the list function (that gets evaluated.). With that approach you quote sublists that don'T need to be evaluated, and can evaluate what needs to be, like that

(setq lay "mylayer")
(setq c (list ;list gets evaluated
           (cons 0 lay); gets/needs to get evaluated to a dotted pair (0 . "mylayer")
           '(62 . 135) ;quoted, that part wont be evaluated and just inserted as is
           '(420 . 5415845) ;quoted, that part wont be evaluated and just inserted as is
           '(430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U") ;quoted, that part wont be evaluated and just inserted as is
))

With the above what would be returned (and stored in the c variable) is the following

((0 . "mylayer") (62 . 135) (420 . 5415845) (430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U"))

 

Basically, since functions are lists you need to tell the machine "this is a list, not a function"

(setq ha(+ 2 7)) would bound the returned value of 9 to ha...

(setq ha '(+ 2 7)) would bound the following list of 3 elements to ha, (+ 2 7). + as a car, 2 as a cadr, 7 as a caddr.... then you could evaluate it by using the eval function. (eval ha) would then return 9.

Link to comment
Share on other sites

Since all your values are hard coded quote the list like so:

image.thumb.png.08c249dc91c4e400881959ef77f8a919.png

Ooops ... guess I need to read all the replies closer @Jef! already touched on this. 😳

Edited by ronjonp
Link to comment
Share on other sites

On 11/11/2018 at 1:49 PM, marko_ribar said:

(setq c (list '(62 . 135) '(420 . 5415845) '(430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U") ))

 

Thanks @marko_ribar I wasn't sure how to use this info so have been doing some research and testing the use of the humble '

Link to comment
Share on other sites

On 11/13/2018 at 12:15 AM, Jef! said:

Lisp evaluates everything, so if you want/need to set a list without evaluating any part (like here, in your example) to a variable I would recommend quoting (once) the whole list

Thanks @Jef! there's so much info in there for me to process. I've copied this out to play with and test the info. Just when I thought I'm learning a lot, there's so much more to learn

Link to comment
Share on other sites

On 11/14/2018 at 1:59 AM, ronjonp said:

Since all your values are hard coded quote the list like so:

image.thumb.png.08c249dc91c4e400881959ef77f8a919.png

Ooops ... guess I need to read all the replies closer @Jef! already touched on this. 😳

Thanks @ronjonp yes my values will be hard coded. I'm looking into quoting and how that functions

Link to comment
Share on other sites

So I tried to use a True Colour like this:

 

(setq c (list '((62 . 244) (420 . 11737633))))

 

which returns this error:

error: bad argument type: fixnump: (((62 . 244) (420 . 11737633)))
 

This is the full code

 


;; Written by PBEJSE on CADTutor
;; Post #4 https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/multiple-polyline-area-labels/td-p/3459894
;; Relies on TEXTSIZE variable for text size
;; 280316 - Tharwat updated field properties in post #2 in above link
;; 040416 - Tharwat updated to add hatch based on area ranges

(command "-dimstyle" "R" "Standard")

(defun c:MFAH (/ BitVersion acsp ss e ptList ID StrField txt p ar c clr sum verts)      
     
(setq ins (getvar "insunits"))
   
(cond
((= (setq ins (getvar "insunits")) 4) ;if insunits=4 then apply 1 x cannoscale
(setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE"))))
((= ins 6) ;if insunits=6 then apply 0.001 x cannoscale
(setvar "dimscale" (/ 0.001 (getvar "CANNOSCALEVALUE"))))
)

(setq scale (getvar "DIMSCALE"))
(setq ln (strcat "U-TEXT-AREA-"(rtos scale 2 0)))
(command "-LAYER" "m" ln "co" "7" ln "p" "p" ln "")

(setvar "TEXTSTYLE" "Standard") 
(setvar "TEXTSIZE" (* 1.8(getvar "DIMSCALE")))

;(if (not (or (tblsearch "LAYER" "U-AREA-HTCH-BDRY")))) 
;             (tblsearch "LAYER" "U-AREA-HTCH")
         
;(progn
;(command "-layer" "Make" "U-AREA-HTCH-BDRY" "Plot" "No" "" "Colour" "6" "" "description" "Area Hatch Boundary" "U-AREA-HTCH-BDRY" "")
;(command "-layer" "Make" "U-AREA-HTCH" "Colour" "254" "" "description" "AREA Hatch" "U-AREA-HTCH" "")

(setq BitVersion (if (> (strlen (vl-prin1-to-string (vlax-get-acad-object))) 40) T nil)
           acsp       (vla-get-block (vla-get-activelayout (vla-get-activedocument
                                                             (vlax-get-acad-object)))))
     (if (setq ss (ssget "_X" '((0 . "*POLYLINE") (8 . "U-AREA-HTCH-BDRY") (-4 . "&") (70 . 1)(410 . "Model"))))
       (repeat (sslength ss)
         (setq e     (ssname ss 0)
               sum   '(0 0)
               verts  (cdr (assoc 90 (entget e))))
         (setq ptList (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e))))
         (foreach x ptList (setq sum (mapcar '+ x sum)))
         (setq ID   (if BitVersion (vlax-invoke-method  (vla-get-Utility (vla-get-ActiveDocument
                                                                           (vlax-get-acad-object)))
                                     'GetObjectIdString (vlax-ename->vla-object e) :vlax-False)
                      (itoa (vla-get-objectid (vlax-ename->vla-object e))))
               StrField (strcat  "%<\\AcObjProp Object(%<\\_ObjId " id ">%).Area \\f \"%lu2%pr0%ps[, m²]%ds44\">%")
               txt (vla-addMText acsp (setq p (vlax-3d-point (mapcar '/ sum (list verts verts)))) 0  StrField)
               )
           (vla-put-AttachmentPoint txt  acAttachmentPointMiddleCenter)
         (vla-put-InsertionPoint txt p)
         (setq c nil clr (getvar 'CECOLOR))
       (cond ((< 185 (setq ar (read (rtos (vla-get-area (vlax-ename->vla-object e)) 2 0))) 190)(setq c (list '((62 . 244) '(420 . 11737633)))))
             ((< 301 ar 351)(setq c (list '((62 . 244) (420 . 11737633)))));(setq c 170))
             )
       (if c (setvar 'CECOLOR (itoa c)))

       (command "_.-HATCH" "_P" "SOLID" "_S" e "" "")
       (setvar 'CECOLOR clr)
           (ssdel e ss)
           )(princ "\0 Objects found:"))
     (princ)
     )(vl-load-com)

Link to comment
Share on other sites

You can't set CECOLOR to a list value .. furthermore you cannot use ITOA on a list? ITOA is used to convert an integer to a string.

 

Here is what I think you're trying to accomplish:

;; Written by PBEJSE on CADTutor
;; Post #4 https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/multiple-polyline-area-labels/td-p/3459894
;; Relies on TEXTSIZE variable for text size
;; 280316 - Tharwat updated field properties in post #2 in above link
;; 040416 - Tharwat updated to add hatch based on area ranges

(command "-dimstyle" "R" "Standard")

(defun c:mfah (/ bitversion acsp ss e ptlist id strfield txt p ar c clr sum verts)
  (setq ins (getvar "insunits"))
  (cond	((= (setq ins (getvar "insunits")) 4) ;if insunits=4 then apply 1 x cannoscale
	 (setvar "dimscale" (/ 1.0 (getvar "CANNOSCALEVALUE")))
	)
	((= ins 6)			;if insunits=6 then apply 0.001 x cannoscale
	 (setvar "dimscale" (/ 0.001 (getvar "CANNOSCALEVALUE")))
	)
  )
  (setq scale (getvar "DIMSCALE"))
  (setq ln (strcat "U-TEXT-AREA-" (rtos scale 2 0)))
  (command "-LAYER" "m" ln "co" "7" ln "p" "p" ln "")
  (setvar "TEXTSTYLE" "Standard")
  (setvar "TEXTSIZE" (* 1.8 (getvar "DIMSCALE")))
					;(if (not (or (tblsearch "LAYER" "U-AREA-HTCH-BDRY")))) 
					;             (tblsearch "LAYER" "U-AREA-HTCH")
					;(progn
					;(command "-layer" "Make" "U-AREA-HTCH-BDRY" "Plot" "No" "" "Colour" "6" "" "description" "Area Hatch Boundary" "U-AREA-HTCH-BDRY" "")
					;(command "-layer" "Make" "U-AREA-HTCH" "Colour" "254" "" "description" "AREA Hatch" "U-AREA-HTCH" "")
  (setq	bitversion (> (strlen (vl-prin1-to-string (vlax-get-acad-object))) 40)
	acsp	   (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
  )
  (if (setq ss (ssget "_X" '((0 . "*POLYLINE") (-4 . "&") (70 . 1) (410 . "Model"))))
    (repeat (sslength ss)
      (setq e	  (ssname ss 0)
	    sum	  '(0 0)
	    verts (cdr (assoc 90 (entget e)))
      )
      (setq ptlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e))))
      (foreach x ptlist (setq sum (mapcar '+ x sum)))
      (setq id	     (if bitversion
		       (vlax-invoke-method
			 (vla-get-utility (vla-get-activedocument (vlax-get-acad-object)))
			 'getobjectidstring
			 (vlax-ename->vla-object e)
			 :vlax-false
		       )
		       (itoa (vla-get-objectid (vlax-ename->vla-object e)))
		     )
	    strfield (strcat "%<\\AcObjProp Object(%<\\_ObjId "
			     id
			     ">%).Area \\f \"%lu2%pr0%ps[, m²]%ds44\">%"
		     )
	    txt	     (vla-addmtext
		       acsp
		       (setq p (vlax-3d-point (mapcar '/ sum (list verts verts))))
		       0
		       strfield
		     )
      )
      (vla-put-attachmentpoint txt acattachmentpointmiddlecenter)
      (vla-put-insertionpoint txt p)
      (setq c	nil
	    clr	(getvar 'cecolor)
      )
      (if (or (< 185 (setq ar (vla-get-area (vlax-ename->vla-object e))) 190) (< 301 ar 351))
	(entmod (append (entget e) '((62 . 244) (420 . 11737633))))
	;;(setq c '((62 . 244) '(420 . 11737633)))
      )
;;;      (if c
;;;	(entmod (append (entget e) c))
;;;	;; (setvar 'cecolor (itoa c))
;;;      )
      (command "_.-HATCH" "_P" "SOLID" "_S" e "" "")
      (setvar 'cecolor clr)
      (ssdel e ss)
    )
    (princ "\0 Objects found:")
  )
  (princ)
)
(vl-load-com)

 

Link to comment
Share on other sites

12 hours ago, ronjonp said:

You can't set CECOLOR to a list value .. furthermore you cannot use ITOA on a list? ITOA is used to convert an integer to a string.

Thanks @ronjonp - after changing colours from ACI to True Colour and Colour Book I didn't realise the same syntax wouldn't work

 

12 hours ago, ronjonp said:

Here is what I think you're trying to accomplish:

Close. I noticed the linework changed colour, but it's the hatch I want to be coloured depending on the closed polyline m² area. Different m² areas will be different hatch colours. I'd also like to put each m² hatch on a seperate layer. 

Link to comment
Share on other sites

Search here did the different colour for areas geeee  maybe 4 years ago ? Trying to find it may be on a different computer. Make a list of pairs (area objectid) sort area then change colour.

Edited by BIGAL
Link to comment
Share on other sites

  • 2 weeks later...

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