Reset 'clipboard' after a copy/paste routine

Reset 'clipboard' after a copy/paste routine

Anonymous
Not applicable
6,564 Views
8 Replies
Message 1 of 9

Reset 'clipboard' after a copy/paste routine

Anonymous
Not applicable

In my code, I have a macro that copies something to the clipboard and pastes it again. However, this will overwrite whatever the user currently has in their clipboard at the time, and once the code is done all they will be able to paste in will be my block.

 

Is there any way to 'store' a user's clipboard value, and then set back to it at the end of the function? Or is there any other way to copy/paste a block without adding it to the clipboard in the first place?

0 Likes
Accepted solutions (1)
6,565 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I have a macro ....

Is there any way to 'store' a user's clipboard value, and then set back to it at the end of the function? Or is there any other way to copy/paste a block without adding it to the clipboard in the first place?


To the first question, I don't know of any way [though I don't guarantee there isn't one].  To the second, you can WBLOCK it to a temporary drawing file and then INSERT that.  If you do it by way of WBLOCK in an AutoLisp (command) function [e.g. if you package the whole procedure into one command definition], WBLOCK will remove the selected object(s) from the drawing, so you will need to include an OOPS command to bring them back.  The INSERT part can be done either Exploded or not, depending on whether you want the result as a Block or as whatever object(s) you started with.  If what you're doing it with is a single Block, you would still want to Insert the temporary drawing Exploded, or what you'll end up with is a new Block under the name of the temporary drawing file, that contains your Block as a nested object.  [To get it in Exploded, if you have it in some routine that doesn't use the Insert dialog box, put an asterisk before the name.]

 

HOWEVER:

If you're doing this in a macro, it must all be happening within the same drawing.  If that's correct, why would you not just use the regular COPY command?  That would certainly eliminate the problem.  Am I missing something?

Kent Cooper, AIA
0 Likes
Message 3 of 9

pendean
Community Legend
Community Legend
Post the macro code, I suspect it can be tweaked to do what you want differently.

As for storing clips, look at this free add-in https://apps.autodesk.com/ACD/en/Detail/Index?id=354291812252272809&appLang=en&os=Win32_64
0 Likes
Message 4 of 9

Anonymous
Not applicable

I do have it working with copy-paste right now! The only problem with this is that it will remove anything the user put on the clipboard and replace it with my block. If they were doing anything important, I could have cost them a lot of time and effort. The dream would be to save the contents of their clipboard to an error trap or a variable somewhere, do my code, and then bring it back at the end.

 

I do like the sound of nesting the block in a new block, inserting it, and then exploding it! I think I'll try that and see if it helps at all.

 

 

0 Likes
Message 5 of 9

Ranjit_Singh
Advisor
Advisor

Let's say something exists in Clipboard and you use autoCAD 'copy' command to move some other object from location one to two, then the clip board data is till retained. Unless you are using 'Copy with Base Point' which wipes the clipboard data.

Try using simple copy for your task, instead of copy with base point. This should not affect the clipboard data.

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I do have it working with copy-paste right now! The only problem ....


It sounds from the inclusion of the word "paste" like you misunderstood the end of my previous Reply.  I'm talking about AutoCAD's very basic and simple COPY command, not about Ctrl+C, which gives you the COPYCLIP  [i.e. Copy to the Clipboard] command, or Shift+Ctrl+C, which gives you the COPYBASE  command.  If you're copying things by way of COPYCLIP or COPYBASE and pasting them [whether via PASTECLIP or PASTEBLOCK or PASTEORIG] somewhere else within the same drawing [which you would have to be, if it's done in a command macro], you are unnecessarily involving the clipboard, when with just-plain COPY, there's no clipboard involvement at all, and therefore the problem you describe does not exist.  Additionally, the entire operation happens in one command, so there's no need for a macro [to combine copying with pasting] at all.

 

Read about the differences between those commands in Help.  CO is the default command alias for COPY, but I have revised mine so that C is for COPY instead of the default CIRCLE [whose alias I changed to CR], since I use COPY so much more often than CIRCLE.

 

Copying to the clipboard to paste into a different drawing is a different matter, but that can also be done via WBLOCK and INSERT, if you likewise want to not override the Clipboard's contents.

Kent Cooper, AIA
0 Likes
Message 7 of 9

Anonymous
Not applicable

I did misunderstand, copy looks like it would work perfectly! My only question now is whether or not the line between the old block (that I have tucked in a corner) and the new block (that the user is dropping in a location) can be hidden at all. If it's just always pointing off screen, for the first couple weeks the users will think that there is an error.

 

Thanks for your feedback!

0 Likes
Message 8 of 9

rapidcad
Collaborator
Collaborator

I do something similar and found that there are sometimes issues with using the clipboard in a lisp command. I offer my users a workaround via a function I added to my lisp to switch between using the clipboard insertion function (which I believe you are - like me - using in order to LOOK like a regular block insertion command) and using a move which also displays the rubberbanding you referred to as a "line". I don't think there is a way to turn off the rubberbanding in the use of the copy command within a lisp program, but if someone else knows, we'd both be interested in finding out!

 

If you really want to continue using the clipboard and your only concern is items already there you could also try the following plug-in which I tested years ago and loved... I just never kept up with it when changing versions and I lost interest with it in my current setup.

Check it out...https://apps.autodesk.com/ACD/en/Detail/Index?id=354291812252272809&appLang=en&os=Win32_64

 

Hope this helps,

ADN CAD Developer/Operator
0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... My only question now is whether or not the line between the old block (that I have tucked in a corner) and the new block (that the user is dropping in a location) can be hidden ....


If you're doing this with a Block specifically, and not potentially a multiple-object selection or certain different kinds of things [such as a Line], try ADDSELECTED.  It will start a new Insert command, with the selected Block, on the same Layer, dragging and ready to drop into place, and without the rubber-band line.

 

Or, if the idea is to automate it so that the User doesn't need to go to that corner where it's tucked to select it [as would EDIT: may * be required with ADDSELECTED], instead of either COPY or Copy/Paste, just write a macro that's a simple INSERT command with that Block, including setting the appropriate Layer [or changing the new one to the appropriate Layer after INSERTing it, so you don't need to set the Layer and then presumably set it back].

 

* It depends on how you get it.  I had put a Block with its insertion point at 0,0, moved away so that wasn't visible, and tried giving 0,0 to ADDSELECTED for an object selection, and that didn't work.  But in further experimentation, I find that if the Block is saved to a variable, I can give ADDSELECTED that variable for the selection, and even if it's not in the visible screen area, it works.  You haven't posted the original macro code, so I can't say whether that approach will work in a modification of it.

Kent Cooper, AIA