PasteUnderNewName Block

PasteUnderNewName Block

miroko
Enthusiast Enthusiast
567 Views
2 Replies
Message 1 of 3

PasteUnderNewName Block

miroko
Enthusiast
Enthusiast

Hi,

 

Users from my office like to have function which gives possibility to paste block under new name.

 

We have this PasteWithName function which is basically great enhancement for the 'Paste as block' function in AutoCAD (for the ctrl+shift+V) but if we have already something as block and we use it it will make block in block.

Users like to have possibility to paste block from drawing A to drawing B and immediatelly under pasting rename it.

 

For example we have block ''window'' in drawing A.

We want to paste it to drawing B but under different name (window 100x200).

 

Is there such a functionality possible or will it go too deep into some definitions ?

 

We have also this nice RenameBlock function but this will be a two-step: first copy/paste block and then rename. Users like to do both at same moment.

 

Would it work ?

 

regards

miroko

0 Likes
Accepted solutions (1)
568 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this, which is the same as the new definition of PASTEBLOCK from PasteBlockWithName.lsp, but with a different command name, without Undefining the PASTEBLOCK command, and using PasteCLIP instead of PasteBLOCK within it:

 

(defun C:PasteBlock2 (/ 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

 

It will work as expected only if what is in the Clipboard [from another drawing by way of COPYCLIP or COPYBASE] is a Block.  [It could work right sometimes if what's in the Clipboard is more than one object, but only if the right one of them -- the one that ends up being the last object in the drawing -- is a Block.  And if there are more than one Block, the drawing order of them will determine which one gets renamed.]

Kent Cooper, AIA
0 Likes
Message 3 of 3

miroko
Enthusiast
Enthusiast

Hi

 

It is working correctly.

 

thank you again for help.

 

regards

miroko

0 Likes