pixel8er Posted November 9, 2018 Posted November 9, 2018 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 Quote
Grrr Posted November 9, 2018 Posted November 9, 2018 Use this and observe the return: (acad_truecolordlg 1 t) Quote
Jef! Posted November 10, 2018 Posted November 10, 2018 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! Quote
pixel8er Posted November 10, 2018 Author Posted November 10, 2018 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 Quote
Grrr Posted November 10, 2018 Posted November 10, 2018 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. 1 Quote
pixel8er Posted November 11, 2018 Author Posted November 11, 2018 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 Quote
pixel8er Posted November 11, 2018 Author Posted November 11, 2018 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 Quote
pixel8er Posted November 11, 2018 Author Posted November 11, 2018 (edited) 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 November 11, 2018 by pixel8er Quote
pixel8er Posted November 11, 2018 Author Posted November 11, 2018 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... Quote
marko_ribar Posted November 11, 2018 Posted November 11, 2018 (setq c (list '(62 . 135) '(420 . 5415845) '(430 . "PANTONE+ CMYK Uncoated$PANTONE P 121-13 U") )) Quote
Jef! Posted November 12, 2018 Posted November 12, 2018 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. Quote
ronjonp Posted November 13, 2018 Posted November 13, 2018 (edited) Since all your values are hard coded quote the list like so: Ooops ... guess I need to read all the replies closer @Jef! already touched on this. Edited November 13, 2018 by ronjonp Quote
pixel8er Posted November 16, 2018 Author Posted November 16, 2018 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 ' Quote
pixel8er Posted November 16, 2018 Author Posted November 16, 2018 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 Quote
pixel8er Posted November 16, 2018 Author Posted November 16, 2018 On 11/14/2018 at 1:59 AM, ronjonp said: Since all your values are hard coded quote the list like so: 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 Quote
pixel8er Posted November 16, 2018 Author Posted November 16, 2018 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) Quote
ronjonp Posted November 16, 2018 Posted November 16, 2018 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) Quote
pixel8er Posted November 17, 2018 Author Posted November 17, 2018 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. Quote
BIGAL Posted November 17, 2018 Posted November 17, 2018 (edited) 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 November 17, 2018 by BIGAL Quote
pixel8er Posted November 29, 2018 Author Posted November 29, 2018 On 11/18/2018 at 6:24 AM, BIGAL said: Search here did the different colour for areas geeee maybe 4 years ago ? Thanks @BIGAL but I couldn't find it. Quote
Recommended Posts
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.