TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on March 12, 2021, 12:34:55 PM

Title: Increment a block name +1 upon insert
Post by: jlogan02 on March 12, 2021, 12:34:55 PM
I have Lee Mac's CopyRenameBlock.lsp and it works great within the drawing. It's dang near what I want but in block library form.

Open library
choose block
test for the block name in the drawing with/without numeric suffix.
if it exists insert with/without suffix increment it's name by 1.

block.dwg is in the drawing
newly inserted block is incremented +1 and renamed block_1.dwg

To be clear, I'm not talking about a field or an attribute. I am talking about the block name.
Like using "block edit" to SaveAs a new block of an existing block.

This is way over my head. As are most things.

J.
Title: Re: Increment a block name +1 upon insert
Post by: d2010 on March 12, 2021, 12:38:32 PM
Please you upload a sample Drawing.dwg (as old-version acad2010), because progecad failed in
Lisp-function/s.If you upload a sample Drawing.dwg then you repair many bug/s inside Lisp.

I have Lee Mac's CopyRenameBlock.lsp and it works great within the drawing. It's dang near what I want but in block library form.
Title: Re: Increment a block name +1 upon insert
Post by: jlogan02 on March 12, 2021, 01:08:46 PM
My apologies for not being clear enough in my post.

I'm simply asking the question "can this be done?" or "has this been done?".

I don't have any code created, I don't have any sample blocks created.

J.

Title: Re: Increment a block name +1 upon insert
Post by: ronjonp on March 12, 2021, 01:33:21 PM
Maybe something like this?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ bn n r)
  2.   (setq bn "BlockName"
  3.         n  -1
  4.   )
  5.   ;; While a block definition exists keep going
  6.   (while (tblobjname "block" (setq r (strcat bn "-" (itoa (setq n (1+ n)))))))
  7.   (alert r)
  8.   (princ)
  9. )
Title: Re: Increment a block name +1 upon insert
Post by: Lee Mac on March 13, 2021, 06:38:45 PM
My Copy/Rename Block Reference already includes logic to increment the block name and will offer the incremented result as a default - this is implemented at line 87 of the program source code (http://lee-mac.com/lisp/html/CopyRenameBlockV1-5.html). As such, replacing lines 88-95 with (setq new "") should cause the default to be automatically used, yielding the behaviour you have described.
Title: Re: Increment a block name +1 upon insert
Post by: jlogan02 on March 19, 2021, 10:54:42 AM
My Copy/Rename Block Reference already includes logic to increment the block name and will offer the incremented result as a default - this is implemented at line 87 of the program source code (http://lee-mac.com/lisp/html/CopyRenameBlockV1-5.html). As such, replacing lines 88-95 with (setq new "") should cause the default to be automatically used, yielding the behaviour you have described.


Told you it was over my head. I was looking at lines 57-78, thinking I have to somehow get the selection of the block picked from the slide library, check to see if it exists in the drawing and then do the magic. I see that I didn't mention "slide" library in the OP.

I'll give that a shot and see what I get.

Thanks Lee
Title: Re: Increment a block name +1 upon insert
Post by: BIGAL on March 19, 2021, 11:05:17 PM
The other thing you need to do is to check what is last number for a block then add 1. Else will start to get block exists.

Again Lee has a good parse number lisp that will pull out numbers from a string, that is provided that all blockname is A-Z, if not then make a str say last 2 characters of blockname and check for number, a Blockname-X note the - would be the best way to delimit where does number start.

If your using a Menu slide library then its simple ^c^C(If (not LM:RenameBlockReference-2 ) (load "My_Copyrenameblock")) (LM:RenameBlockReference-2   t "Block_area") so the block name is passed and make changes as Lee has suggested.
Title: Re: Increment a block name +1 upon insert
Post by: jlogan02 on March 22, 2021, 02:34:33 PM
The other thing you need to do is to check what is last number for a block then add 1. Else will start to get block exists.

Thanks for the confirmation.
Let's say my characters before the -#(increment) are known character sets (library name abbreviation).

...-SL-#(increment).dwg
...-AC-#(increment).dwg
...-CTL-#(increment).dwg
and so on.

Does that help me in any way?

Again Lee has a good parse number lisp that will pull out numbers from a string, that is provided that all blockname is A-Z, if not then make a str say last 2 characters of blockname and check for number, a Blockname-X note the - would be the best way to delimit where does number start

So, if I have numbers in the blockname I need to make str say, last 2 or 3 characters of the name? Got it. I also need to use a hyphen not an underscore. Thanks for letting me know, as I was thinking underscore.

If your using a Menu slide library then its simple ^c^C(If (not LM:RenameBlockReference-2 ) (load "My_Copyrenameblock")) (LM:RenameBlockReference-2   t "Block_area") so the block name is passed and make changes as Lee has suggested.

Thanks for this. I would have never gotten the macro correct.

Now let's see if I can do any of this.

Hold please....

J.
Title: Re: Increment a block name +1 upon insert
Post by: BIGAL on March 22, 2021, 08:03:11 PM
Underscore is fine just use that as a search for character.

If you get stuck just ask.