PasteBlockWithName

PasteBlockWithName

miroko
Enthusiast Enthusiast
961 Views
12 Replies
Message 1 of 13

PasteBlockWithName

miroko
Enthusiast
Enthusiast

Hei

 

I found in internet on some page attached lisp from Kent Cooper.

It is very nice lisp and users like it in our office.

 

But i have little issue with it.

When i start command the cursor does not change from this 'rectangle box' to just 'crossing lines' and it makes confusion if function is running or not (unless one have the DYNMODE turned on so that small field appear for inserting name).

 

Is there something in the lisp that makes it working in that way ?

 

regards

miroko

0 Likes
Accepted solutions (1)
962 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

It's no different from anything else that prompts for the User to enter some text.  It doesn't go into the PasteBlock command until that's done, so I'm not sure there's a way to change the look of the cursor.  It could conceivably be done by completing the native PasteBlock command first, and afterwards asking for the name, but that leaves open the possibility that the User might cancel it without giving it a name, and then the wacky Block name would remain.

 

But here's a suggested alternative that should make it obvious that it's underway, without the User needing to notice a prompt at the Command: line, and entirely apart from the question of what the cursor looks like.  Replace the first (while) function [between the (defun) line and the (command) line] with this:

...

  (while
    (not
      (and
        (setq newname (lisped "Name for Block to be Inserted")); calls up Text Editor with content pre-selected for replacement
        (setq newname (vl-string-trim " " newname)); remove any leading/trailing space(s)
        (/= newname ""); didn't either clear out or enter only space(s)
        (/= newname "Name for Block to be Inserted"); didn't just hit Enter
        (not (tblsearch "block" newname)); name not already in use
      ); and
    ); not
    (alert
      (cond
        ((= newname "") "Empty string or only space(s) not allowed;\nyou must supply a Block name.")
        ((= newname "Name for Block to be Inserted") "You must supply a new Block name.")
        (T "\nThat Block name is already in use.")
      ); cond
    ); alert
  ); while

...

Kent Cooper, AIA
0 Likes
Message 3 of 13

ВeekeeCZ
Consultant
Consultant

Hello Kent,

besides the topic, in your lisp you have written note about Scale and Rotation. Where this can be controlled? (In AutoCAD not LISP) It sometimes happens to me and I never know where... Always thought this is some kind of bug...

 

  (command "_.pasteblock")
  (while (> (getvar 'cmdactive) 0) (command pause))
    ;; finish _.PASTEBLOCK including possible Scale/Rotate options, etc.
0 Likes
Message 4 of 13

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

.... in your lisp you have written note about Scale and Rotation. Where this can be controlled? (In AutoCAD not LISP) ....


When PASTEBLOCK [or PASTECLIP] is asking for an insertion point, you can type an S for the Scale option [XYZ all together], R for Rotation, X or Y or Z for just the X or Y or Z scale factor, give it values, and it will go back to the insertion-point prompt, and the dragged image will reflect the options you've used.  You can use as many of them as you want before getting around to giving it an insertion point.  Since it doesn't display a prompt with options, I'm not sure whether it honors all the same ones as the command-line version of the Insert command.

Kent Cooper, AIA
Message 5 of 13

miroko
Enthusiast
Enthusiast

Hi

 

That is a nice help. Now user will know whats happening.

 

I noticed however that there is 'Full editor' button. But it does not work actually, when i click then i get error. Actually this is not needed this FullEditor since we are not formatting anyhow the name so would be nice to just remove the button, how to do that?

 

Another issue is that I noticed that 'Ctrl+Shift+V' will be not active when this lisp is loaded. Is there a way that 'Ctrl+Shift+V' will invoke this new command? Should be added something to code?

This would make that users will be forced to give a 'nice' name when they paste something.

 

 

regards

miroko

0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@miroko wrote:

.... 

I noticed however that there is 'Full editor' button. But it does not work actually, when i click then i get error. Actually this is not needed this FullEditor since we are not formatting anyhow the name so would be nice to just remove the button, how to do that?

 

Another issue is that I noticed that 'Ctrl+Shift+V' will be not active when this lisp is loaded. Is there a way that 'Ctrl+Shift+V' will invoke this new command? Should be added something to code?

....


I don't know of a way to remove the Full Editor button from the Text Editor window that (lisped) calls up.  Double-clicking on plain Text brings up one that doesn't have that [though I think that varies with version and certain System Variables], but I haven't found a way to get that simpler Editor except by having a piece of Text drawn.  I suppose it might be possible to have the routine actually draw a temporary one, call up the Editor on that, extract the content after editing for its checks, and after all is satisfied, delete the Text.  But that could involve changing System Variables, and requires a middleman Text entity, meaning *error* handling should be added, and so on.  I think a small amount of education of Users, to not pick the Full Editor button, would be both simpler and safer.

 

Ctrl+Shift+V is inactive if there is no drawing-entity content in the Clipboard to Paste in.  When there is, for me it does invoke this command.  Make sure you have used COPYCLIP or COPYBASE to put some drawing entities into the Clipboard first, and check again whether it works.

Kent Cooper, AIA
0 Likes
Message 7 of 13

miroko
Enthusiast
Enthusiast

Hi Kent1Cooper

 

It is working.

 

Thank you for help.

 

miroko

0 Likes
Message 8 of 13

miroko
Enthusiast
Enthusiast

Hello,

Some time ago I got help on this post and the tool is working. However users experience that this function is in some circumstances doing something that is not always fully logic for them.

 

When we copy block from one drawing to other with this function then it works nice. But the problem is that when we i.e. have a block in ‘drawing A’ and copy the block and use this command to paste still into the same ‘drawing A’ then function is of course doing it, but it is actually renaming the existing block.

 

Users would wish to be able to use this function to paste block into same drawing but so that a new block definition is created and not that it is renaming that particular block.

Would that be that possible?

Currently used function is:

 

 

 

(defun C:PB (/ newname oldname doc blks); change name as desired

(while

   (not

     (and

       (setq newname (lisped "Name for Block to be Inserted"))

         ; calls up Text Editor with content pre-selected for replacement

       (setq newname (vl-string-trim " " newname)); remove any leading/trailing space(s)

       (/= newname ""); didn't either clear out or enter only space(s)

       (/= newname "Name for Block to be Inserted"); didn't just hit Enter

       (not (tblsearch "block" newname)); name not already in use

     ); and

   ); not

   (alert

     (cond

       ((= newname "") "Empty string or only space(s) not allowed;\nyou must supply a Block name.")

       ((= newname "Name for Block to be Inserted") "You must supply a new Block name.")

       (T "\nThat Block name is already in use.")

     ); cond

   ); alert

); while

(command "_.pasteclip")

(while (> (getvar 'cmdactive) 0) (command pause))

   ;; finish _.PASTECLIP including possible Scale/Rotate options, etc.

(setq

   oldname (cdr (assoc 2 (entget (entlast)))); AutoCAD's meaningless name

   doc (vla-get-activedocument (vlax-get-acad-object))

   blks (vla-get-blocks doc)

); setq

(vla-put-name (vla-item blks oldname) newname); = Rename

(princ)

); defun

 

 

 

 

Best regards

miroko

 

0 Likes
Message 9 of 13

Kent1Cooper
Consultant
Consultant

@miroko wrote:

.... 

When we copy block from one drawing to other with this function then it works nice. But the problem is that when we i.e. have a block in ‘drawing A’ and copy the block and use this command to paste still into the same ‘drawing A’ then function is of course doing it, but it is actually renaming the existing block.

 

Users would wish to be able to use this function to paste block into same drawing but so that a new block definition is created and not that it is renaming that particular block.

Would that be that possible?

.... 


Just use ordinary PASTECLIP [Ctrl+V] for that.  A routine like this one has no way of knowing whether what is in the Clipboard ready for Pasting in is already a Block, or a Line, or a whole set of different kinds of objects, so it can't decide whether to ask you for a Block name or not -- it just always does.

 

But I think you'll find that it is not actually renaming the Block that you copied.  It is making a new Block definition that contains an insertion of that Block, but if you Explode the new Block, you will be left with an insertion of the other Block still under its original name.  And you can Insert more of that Block under its original name, in addition to being able to Insert it as a nested object within the new Block.

Kent Cooper, AIA
0 Likes
Message 10 of 13

miroko
Enthusiast
Enthusiast

hi

 

using Ctrl+V just pastes the same object without asking any questions.

and it is ok because not all we paste we want to become immediatelly a block.

 

it is making block in block when using Ctfl+Shift+V.

but when using just function from above lisp (PB) then it pastes the same block under new name but it is actually renaming existing while user would want that it makes a new definition and keeping old one completelly untouched and independent.

 

dont know if thats possible, just asking

 

a work around is just to traditionally copy/paste block in other file, rename block and traditionally paste back (then we have two separate)

 

 

miroko

0 Likes
Message 11 of 13

ВeekeeCZ
Consultant
Consultant
This doesn't work for you?
http://www.lee-mac.com/copyblock.html
0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

@miroko wrote:

.... user would want that it makes a new definition and keeping old one completelly untouched and independent.

 

dont know if thats possible, just asking

 

....

In addition to the link from BeekeeCZ, there are other routines out there, as well as suggestions of approaches without routines, to create a new Block definition duplicating another one but under a different name, without affecting the "source" Block definition.

Kent Cooper, AIA
0 Likes
Message 13 of 13

miroko
Enthusiast
Enthusiast

hi

 

thank you to you (BeekeeCZ and Kent Cooper).

I did not know about those routines.

will check them out.

 

regards

miroko

0 Likes