eyeofnewt555 Posted December 15, 2016 Posted December 15, 2016 Let's say I have 6 objects selected. Is there a lisp I can run that will copy "6" to the clipboard? This is part of how I count/label blocks and I'd like to reduce human error where possible. And before anyone asks why I don't use block count, just trust that my method works better for me. Thanks! Quote
Grrr Posted December 15, 2016 Posted December 15, 2016 I don't think its possible to copy to clipboard something else than text via lisp, due what I've seen being posted so far by MP here (or/and maybe Lee Mac). BUT, some thinking outside the box: -It would be possible to collect the list of object's handles -Copy the handles to clipboard -Retrieve the objects from the clipboard data Not sure what to do with them after that ... maybe someone else has other thought to offer. Quote
Hippe013 Posted December 15, 2016 Posted December 15, 2016 I don't think its possible to copy to clipboard something else than text via lisp I believe the OP is only looking to copy text to clipboard via text. I use DOS_LIB to copy text to clipboard. (dos_clipboard [string]) Quote
Grrr Posted December 15, 2016 Posted December 15, 2016 Oh I see now, he only wants their count and not the actual entities: (defun C:test ( / SS ) (and (setq SS (vl-some 'ssget (list "_I" nil))) (_SetClipBoardText (itoa (sslength SS))) ) (princ) ) This code requires MP's _SetClipBoardText subfunction. Quote
eyeofnewt555 Posted December 15, 2016 Author Posted December 15, 2016 Worked like a charm! Thank you so much! Quote
eyeofnewt555 Posted December 15, 2016 Author Posted December 15, 2016 Now lets say I wanted whatever I have selected to also change color once I run this lisp. How would I go about integrating this small routine for changing color into the lisp you've written? I tried it a couple different ways and couldn't get it. Color change component: (Defun C:Y ( / change) (setq ss1 (ssget)) (command "change" ss1 "" "p" "c" "2" "") (princ) ) Lisp to add it into: (defun C:test ( / SS ) (and (setq SS (vl-some 'ssget (list "_I" nil))) (_SetClipBoardText (itoa (sslength SS))) ) (princ) ) (defun _SetClipBoardText ( text / htmlfile result ) ;; Caller's sole responsibility is to pass a ;; text string. Anything else? Pie in face. ;; Attribution: Reformatted version of ;; post by XShrimp at theswamp.org. ;; ;; See http://tinyurl.com/2ngf4r. (setq result (vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow ) 'ClipBoardData ) 'SetData "Text" text ) ) (vlax-release-object htmlfile) text ) Thanks for any help! Quote
Grrr Posted December 15, 2016 Posted December 15, 2016 Worked like a charm! Thank you so much! The whole magic is from Michael Puckett's code. EDIT: Try (defun C:test ( / SS ) (and (setq SS (vl-some 'ssget (list "_I" nil))) (not (command "_.CHANGE" SS "" "p" "c" "2" "")) (_SetClipBoardText (itoa (sslength SS))) ) (princ) ) And be careful, because it works with implied selection (if you already selected something, and run the command-call). Quote
eyeofnewt555 Posted December 15, 2016 Author Posted December 15, 2016 Thanks Grrr! Unfortunately, it's giving me: "Point or option keyword required. ; error: Function cancelled Specify change point or [Properties]:" I'm definitely selecting first and then running the command. Not sure if I'm doing something else wrong though. Quote
Grrr Posted December 15, 2016 Posted December 15, 2016 I believe its because of the command-call that behaves differently whether the selection is implied or you are prompted for selection. However its achievable with a "PutIndexColor" subfunction I suggested in a recently-created-related thread: [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / SS i [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq SS [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"_:L-I"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]_SetClipBoardText [b][color=MAROON]([/color][/b]itoa [b][color=GREEN]([/color][/b]sslength SS[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]repeat [b][color=MAROON]([/color][/b]setq i [b][color=GREEN]([/color][/b]sslength SS[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]PutIndexColor [b][color=GREEN]([/color][/b]ssname SS [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1- i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] 2[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]defun PutIndexColor [b][color=FUCHSIA]([/color][/b] e col / enx [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]eq 'ENAME [b][color=MAROON]([/color][/b]type e[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]eq 'INT [b][color=MAROON]([/color][/b]type col[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]<= 0 col 256[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq enx [b][color=MAROON]([/color][/b]vl-remove-if [b][color=GREEN]([/color][/b]function [b][color=BLUE]([/color][/b]lambda [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]= 420 [b][color=PURPLE]([/color][/b]car x[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entget e[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [color=#8b4513]; remove the true color if present[/color] [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]assoc 62 enx[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 62 col[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 62 enx[b][color=RED])[/color][/b] enx[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmod [b][color=GREEN]([/color][/b]append enx [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 62 col[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]defun _SetClipBoardText [b][color=FUCHSIA]([/color][/b] text / htmlfile result [b][color=FUCHSIA])[/color][/b] [color=#8b4513];; Caller's sole responsibility is to pass a[/color] [color=#8b4513];; text string. Anything else? Pie in face.[/color] [color=#8b4513];; Attribution: Reformatted version of[/color] [color=#8b4513];; post by XShrimp at theswamp.org.[/color] [color=#8b4513];;[/color] [color=#8b4513];; See http://tinyurl.com/2ngf4r.[/color] [b][color=FUCHSIA]([/color][/b]setq result [b][color=NAVY]([/color][/b]vlax-invoke [b][color=MAROON]([/color][/b]vlax-get [b][color=GREEN]([/color][/b]vlax-get [b][color=BLUE]([/color][/b]setq htmlfile [b][color=RED]([/color][/b]vlax-create-object [color=#2f4f4f]"htmlfile"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] 'ParentWindow [b][color=GREEN])[/color][/b] 'ClipBoardData [b][color=MAROON])[/color][/b] 'SetData [color=#2f4f4f]"Text"[/color] text [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]vlax-release-object htmlfile[b][color=FUCHSIA])[/color][/b] text [b][color=BLACK])[/color][/b] Quote
eyeofnewt555 Posted December 15, 2016 Author Posted December 15, 2016 Oh man, that's exciting. A thing of beauty. Thank you so much for spending the time! Works wonderfully. Quote
Grrr Posted December 15, 2016 Posted December 15, 2016 Oh man, that's exciting. A thing of beauty. Thank you so much for spending the time! Works wonderfully. Thanks, I'm happy to help! 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.