Jump to content

Recommended Posts

Posted

Dear CAD community,

 

I have several thousand drawings to process and would appreciate some help modifying Master Lees code to automate the input and output.  

I have drawings with several revision blocks all named REVB with attributes etc I would like the code to select the latest revision and rename just that block to VREVB?

 

To be clear in the drawings there are variable number of blocks called REVB I would like to rename the latest one to VREVB.

 

Apologies I have limited lisp skills and have been trying to modify CopyRenameBlockV1-5 LM:RenameBlockReference as follows to search for the last inserted revision.   I was trying to use the last inserted instance of this block for example A, B, C use C to rename.

"  ; select ?last occurrence of REVB
  (if (setq ss (ssget "x" '((0 . "INSERT") (2 . "REVB"))))
    (progn
      (repeat (setq i (sslength ss)) (setq b (ssname ss (setq i (1- i))) l (cons (cons (tai b "REV") b) l)))
      (setq REVB (cdr (assoc (last (acad_strlsort (mapcar 'car l))) l)))
    )
  )"

I am struggling with how to pass this block name to the RB code.

 

I already have tools to batch run the code but would rather not have to manually select the blocks.

 

Any assistance gratefully received

Many thanks for your time

John

 

 

 

 

 

Sample.dwg

Posted

So just checking, your routine is asking for lisp routine tai

 

 

However to put this into Lee Macs rename, get the block entity name and replace src with that

Replace this line with your selected block entity.

 

            (setq src (car (entsel (strcat "\nSelect block reference to " (if cpy "copy & " "") "rename: "))))

 

 

and replace this line

 

                (and (/= "" (setq new (getstring t (strcat "\nSpecify new block name <" def ">: "))))

 

 

with

 

                (and (/= "" (setq new "VREVB"))

 

 

I think that will work, if you can fnd tai lisp then probably be able to put this all together for you

  • Like 2
Posted

This is my take on the problem

I am struggling with how to pass this block name to the RB code. You pass the entity name not block name.

 

Try this works for A-Z etc 

; rename a block.
; uses lee-mac CopyRenameBlockV1-5.lsp which needs to be modified to pass entity and block name
; so give it a new name say CopyRenameBlockV1-5-1.lsp


(defun c:wow ( / obj x atts att chrnum num)

(if (not LM:RenameBlockReference)(load "CopyRenameBlockV1-5-1"))

(setq ss (ssget "x" '((0 . "INSERT") (2 . "REVB"))))
(setq num 0)
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq atts (vlax-invoke obj 'Getattributes))
(setq chrnum (ascii (vla-get-textstring (car atts))))
(if (> chrnum num)(setq num chrnum))
)

(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq atts (vlax-invoke obj 'Getattributes))
(if (= num (ascii (vla-get-textstring (car atts))))
(LM:RenameBlockReference nil (ssname ss x) "VREVB")
)
)

(princ)
)
(c:wow)

 

Lee's code is always excellent and I have made a few changes to get the extra options to work, it may be something that Lee will add the option of passing entity and new name, as say version 1-6

CopyRenameBlockV1-5-1.lsp

  • Like 2
Posted

Thank you very much for all your help. Very much appreciated

This will save me lots of work!

 

Initially I made a real school boy error and left the (c;wow) on the end of the code, which caused the vlide to go crazy when loading.  

 

The c:wow routine works well and perfectly selected the correct block and supplied the new block name but required a last carriage return to complete the input.   Not sure if I have done wrong but I then edited Lees code and added the line from SteveP (many thanks) which removed the getstring and supplies the new block name “VREVB”.

Again, I am not sure if I have violated good code practice but I then put the entire routine into one lsp file called CopyRenameBlockV1-5-1 (see attached) so all is loaded together.   We use the CB and RB functions regularly so I will need to be careful not to get these mixed/overwritten.

 

Thank you both again for all your help, please let me know if I have done anything terrible with the above modifications?

 

Regards John

CopyRenameBlockV1-5-1.lsp

  • Like 1

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...