copy color to clipboard

copy color to clipboard

andrea_ricci-ext
Contributor Contributor
1,426 Views
15 Replies
Message 1 of 16

copy color to clipboard

andrea_ricci-ext
Contributor
Contributor

Is there any autolisp to copy the color to clipboard?

Ideally I wish: if bylayer→ layer's color, otherwise the object's color, acad code or RGB.

Thank you

0 Likes
Accepted solutions (1)
1,427 Views
15 Replies
Replies (15)
Message 2 of 16

pendean
Community Legend
Community Legend
@andrea_ricci-ext what do you do with that information afterwards if I may ask?
0 Likes
Message 3 of 16

john.kaulB9QW2
Advocate
Advocate

Clipboard stuff is done via an HTML object.  -i.e. (vlax-create-object "htmlfile")

 

Tony Tanzillo had a nice writeup on TheSwamp about this subject (memory and leaks and stuff) which he gave a nice routine/method for clipboard access.

 

Michael Puckett also compiled a few routines in a discussion, on TheSwamp, with Patrick_35 and XShrimp I have used as well for clipboard access. 

another swamper
0 Likes
Message 4 of 16

paullimapa
Mentor
Mentor

Combination of this code that selects the object and returns the color #
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-get-color-number/td-p/8545039

and this subroutine

_SetClipBoardText

 that sends it to the clipboard 

https://www.cadtutor.net/forum/topic/62104-quick-lisp-to-put-of-objects-selected-to-the-clipboard/

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 16

Kent1Cooper
Consultant
Consultant

@andrea_ricci-ext wrote:

Is there any autolisp to copy the color to clipboard?

Ideally I wish: if bylayer→ layer's color, otherwise the object's color, acad code or RGB. ....


Getting it is not hard:

 

(defun C:eColor (/ ent)
  (setq
    ent (car (entsel "\nObject to get its color: "))
    eColor (getpropertyvalue ent "color")
    eColor
      (if (member eColor '(0 256))
        (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget ent))))))
        eColor
      )
  )
)

 

That results in a text string if it's a Truecolor object override, or an integer if it's an index color, and it seems if it's ByLayer/ByBlock and the Layer's color is Truecolor [it gets "rounded" to the closest index color].  I'm not sure how to get the Truecolor numbers of the Layer color, which are similarly "rounded" in (tblsearch) and (entget (tblobjname)) results.  But they must be available -- the Layer Manager list shows them.

 

Getting it to the clipboard is a little more complicated, but I agree -- how are you going to use the information?  That could affect what should be done with it.

Kent Cooper, AIA
0 Likes
Message 6 of 16

andrea_ricci-ext
Contributor
Contributor
Hi, I wish to paste it in another software


0 Likes
Message 7 of 16

Kent1Cooper
Consultant
Consultant

@andrea_ricci-ext wrote:
.... I wish to paste it in another software

And in what form / format does that other software want it?  Does it know that in AutoCAD, simple integers [1 through 255, anyway] can represent colors -- 1 is red, 2 is yellow, etc.?  Would it want only 3-number RGB-style information, meaning that AutoCAD index colors need to be converted to equivalent RGB values?  And with RGB values, does it want a comma-delimited text string, or something like an AutoLisp list of numbers, or...?  Etc., etc.

Kent Cooper, AIA
0 Likes
Message 8 of 16

pendean
Community Legend
Community Legend

@andrea_ricci-ext wrote:
Hi, I wish to paste it in another software

And what other software is that? And what in that software is the setting for and where will it be applied?

 

0 Likes
Message 9 of 16

andrea_ricci-ext
Contributor
Contributor

the "paste to" software is not defined. Sometimes is a blog post, sometimes is inside autocad itself. So maybe it would be interesting an easy-to-find spot in the code to easilly set the spacer (space, comma and so on).

Maybe it would be usefull to have separate commands as copyToACI, copyToRGBspace, copyToRGBcomma and so on.

 

0 Likes
Message 10 of 16

Sea-Haven
Mentor
Mentor

Am I interpreting this correctly that you want to copy text that has a color like red so when you paste it to some where else the text keeps the color, the reason I ask this just getting the COLOR will return just numbers like 1, 123,56,67 for rgb. If you copyclip a text it remains in the clipboard as a Autocad text object so trying to paste to some where else tends to not work. Like mtext each software has some form of coding to say do this for a text color. It may be simple like a bold is \b. The same as enter code is [code] in a lot of forums, the end of code is [/code]

 

Some one may know more about BBC coding.

0 Likes
Message 11 of 16

andrea_ricci-ext
Contributor
Contributor
correct, I wish simple text as 123 for acad color or 0,120,226 for RGB (eventually with the option for different separators as space or semicolon).
I run in this need when I was writing some blog post in markdown, but also when I wanted to put the color code in the dwg itself (as a text).
0 Likes
Message 12 of 16

komondormrex
Mentor
Mentor
Accepted solution

ladies first.

hey Andrea,

check the code attached.

 

Message 13 of 16

andrea_ricci-ext
Contributor
Contributor
that's great!
Thank you very much. I'm trying reading the code: very complicated for my knowledge.
0 Likes
Message 14 of 16

andrea_ricci-ext
Contributor
Contributor
My I publish your lisp in my blog, in the "tools" section? Maybe you wish to add credits in the head of the lisp?
https://andrearicci.it/howtocad/
Thank you again
0 Likes
Message 15 of 16

komondormrex
Mentor
Mentor

sure you may. i added credits to the code.

0 Likes
Message 16 of 16

andrea_ricci-ext
Contributor
Contributor
thank you again
0 Likes