Jump to content

Lisp needed: paste any object from clipboard into place of selected any other objects


Ryszard

Recommended Posts

Hello, I am not very experienced in lisp, can do some simple scripts but this one will be a hardship for me, and I am sure sth very easy for You guys.

I have got a blueprint of one floor of building which has many doors represented by one named block with additional dynamic attributes (non standard).

I need to replace half of these doors with other named block (leaving the other half intact) which doesn't have any additional attributes.

These doors have different sizes (setting by additional block attributes) and different orientations. I am at point where I am able to select (with custom QSELECT) every door I am interested to replace with new one. So i have got a selection set.

I need a script which just paste any object from clipboard (anything) in place of any door in the selection set. The rest - removing old ones, setting proper orientation - i will do manually. About point of paste - let's paste from clipboard in the basepoint of existent block in the selection set.

Or maybe there is such built-in function in ACAD2010?

Link to comment
Share on other sites

Can you better identify/narrow down the selection parameters of the existing various sized/orientation doors that need to be replaced? Or are you planning on manually selecting each and every door that needs to be replaced? Or are they all on a unique layer or with another unique indentifier?

Link to comment
Share on other sites

You can select a block and one attribute retrieving the name and attribute value form one pick this would then be used to make your selection set. You could then add a new block erasing the old one. One issue and you have touched on it is if the new block does not have a common insert point will create some problems. You need to use a combination of ssget and nentselp so you can get block name and Attribute value.

 

This took a couple of seconds to find, I have not looked at what was posted but may be a good starting point.

http://www.cadtutor.net/forum/showthread.php?48458-Replace-Selected-Block-Or-Blocks-With-Another-Block

 

block name and attribute value 1 pick

(defun BIGAL ( / oldsnap pt pt1 pt2 att attobj obj blkname ss1)
(setq oldsnap (getvar 'osmaode))
(setvar 'osmode 0)
(setq pt (Getpoint "Pick block attribute"))
(setq pt1 (polar pt (/ pi 4.0) 3))
(setq pt2 (polar pt (- 0 (/ pi 4.0)) 3))
(setq ss1 (ssget "C" pt1 pt2 (list (cons 0 "Insert"))))
(setq obj (vlax-ename->vla-object (ssname ss1 0)))
(setq att (nentselp pt)) 
(setq attobj (vlax-ename->vla-object (car att)))
(setq attstring (vla-get-textstring attobj))
(setq blkname (vla-get-name obj))
(alert (strcat "You picked block " blkname "\n\nand the attribute value was " attstring))
(setvar 'osmode oldsnap)
(princ)
)
(BIGAL)

Link to comment
Share on other sites

Can you better identify/narrow down the selection parameters of the existing various sized/orientation doors that need to be replaced? Or are you planning on manually selecting each and every door that needs to be replaced? Or are they all on a unique layer or with another unique indentifier?

 

Various selected objects may lay on different layers, visibles and accessibles.

I don't need a script to do anything besides pasting clipboard content in the localization of each selected object. The blueprint is complicated, it is big, there are many different details. All doors are represented by one block, where the size of door are determined with special attribute defined in block itself.

But in the end I need to replace these complicated blocks with simpler blocks where door size are not determined by any attribute but is fixed in block define. So I can't just replace one block with another because it will replace all blocks of kind.

I have created such simpler blocks but it is very tired work to manually place these new blocks in the place of old blocks.

That is why i need a script which make it more easy work.

Any other operations like exact position, orientation, layer of pasted blocks i will do manually.

Link to comment
Share on other sites

You can select a block and one attribute retrieving the name and attribute value form one pick this would then be used to make your selection set.

 

I am not interested in replacing selected block with another block and then removing old block.

I just need a script that will put anything from clipboard (it is block in my case, but it would be line, text, circle, anything) in place of selected blocks (or primitive objects or anything).

Nothing more. The problem is to determine paste point so I thought about a basepoint of block. It is first I heard that a block can not have a basepoint.

I don't know what exactly Your script does because it stops with error "bad string of ssget mode". It is probably due to ssget "C" which is not recognized in non english version of Autocad (this is why I hate translated commands and options, they may looks nice and more readable, but it is a pain in ... for any script). It probably should be ssget "_C" or "_C:" or whatever syntax really is.

In the URL You have provided, the guy wanted to replace selected blocks with other block. I don't need it. It can be probably good start point to create what I want, but with my knowledge about lisp, i don't know if I will be able to figure the rest by my own.

Link to comment
Share on other sites

Try this and use VLIDE or APPLOAD command to load lisp in order to keep what you have in clipboard memory...

 

(defun c:pasteblock-replace-ssofblocks ( / adoc ss el blk name n )

 (vl-load-com)

 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (if (= 8 (logand 8 (getvar 'undoctl)))
   (vla-endundomark adoc)
 )
 (vla-startundomark adoc)
 (prompt "\nSelect blocks to replace...")
 (setq ss (ssget "_:L-I" '((0 . "INSERT"))))
 (setq el (entlast))
 (vl-cmdf "_.PASTEBLOCK" "_non" '(0.0 0.0 0.0))
 (if (not (eq el (entlast)))
   (setq blk (entlast))
   (progn
     (prompt "\nClipboard empty... Quitting...")
     (exit)
   )
 )
 (if (/= "No" (progn (initget "Yes No") (getkword "\nChange name of newly created pasteclip block [Yes/No] <Yes> : ")))
   (progn
     (setq name (lisped (vla-get-name (vlax-ename->vla-object blk))))
     (while (or (not (snvalid name)) (tblsearch "BLOCK" name))
       (prompt "\nBlock name you specified already used...")
       (setq name (lisped (vla-get-name (vlax-ename->vla-object blk))))
     )
     (vla-put-name
       (vla-item (vla-get-blocks
                   (vla-get-activedocument (vlax-get-acad-object))
                 )
                 (vla-get-name (vlax-ename->vla-object blk))
       )
       name
     )
     (vla-auditinfo
       (vla-get-activedocument (vlax-get-acad-object))
       :vlax-true
     )
     (vla-put-name
       (vla-item (vla-get-blocks
                   (vla-get-activedocument (vlax-get-acad-object))
                 )
                 (vla-get-name (vlax-ename->vla-object blk))
       )
       name
     )
   )
 )
 (setq name (vla-get-name (vlax-ename->vla-object blk)))
 (entdel blk)
 (foreach b (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (vl-cmdf "_.INSERT" name "_non" (cdr (assoc 10 (entget b))) 1.0 1.0 (cvunit (vla-get-rotation (vlax-ename->vla-object b)) "radian" "degree"))
   (setq n (vla-get-name (vlax-ename->vla-object b)))
   (entdel b)
   (if (not (ssget "_X" (list '(0 . "INSERT") (cons 2 n))))
     (vl-cmdf "_.PURGE" "_B" n "_N")
   )
 )
 (vla-endundomark adoc)
 (princ)
)

Regards, M.R.

Edited by marko_ribar
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...