Jump to content

Increment numbers....but with special thing.


bono05

Recommended Posts

Hi everyone,

 

I'm looking for a lisp for special numbering:

 

BGDT/001

BGDT/002-003

BGDT/004

BGDT/005

BGDT/006-007...

 

So the lisp need to "identify" when the text ending with 1 number (BGDT/001)

an when the texte ending with 2 numbers (BGDT/002-003).

 

I will make a block with attribute for numbers with 1 number (BGDT/xxx)

And a block with attribute for numbers with 2 numbers (BGDT/xxx-xxx)

 

And now with a lisp (like increment) if i select one of the text, he can recognise if it's with 1 or 2 numbers...for sample:

 

BGDT/xxx ---- when a click ---- BGDT/001

BGDT/xxx-xxx -- when a click ---- BGDT/002-003...and so far.

 

Possible? :?

 

Thanks for answer...

 

Bono.

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • bono05

    11

  • pBe

    7

  • Tharwat

    3

This lisp to check for numbers .

 

(defun c:Test (/ ss n e p)
 (if (progn
       (princ "\n Pick only one Attibuted Block :")
       (setq ss (ssget "_+.:S" '((0 . "INSERT") (66 . 1))))
     )
   (progn
     (setq n (entnext (ssname ss 0)))
     (while (not (eq (cdr (assoc 0 (setq e (entget n)))) "SEQEND"))
       (if (and (eq (cdr (assoc 0 e)) "ATTRIB")
                (setq p (vl-string-position 47 (cdr (assoc 1 e))))
           )
         (if (vl-string-position 45 (cdr (assoc 1 e)) (1+ p))
           (alert "The selected Block has two Numbers !")
           (alert "The selected Block has only one Number !")
         )
         (alert
           "The selected Block has no < / > to check for Numbers !"
         )
       )
       (setq n (entnext n))
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Woaw.....very fast answer!! thanks Tharwat.

 

So i made a few block with attribute BGDT/xxx and BGDT/xxx-xxx.... i'll put manually the first one to BGDT/001 and then i try de lisp...and at the end i receive this alert "The selected Block has no to check for Numbers !".

 

And how to make increment?

 

I don't know the problem...:(

Link to comment
Share on other sites

Just upload a sample drawing with these blocks and mention what you want from the lisp to do , so I might be able to help or anyone else may also have the willing to help you as well .

Link to comment
Share on other sites

Ok!

 

As you can see i have a plan with blocks/attribute:

Block Data1 with attribute and one ending number (BGDT/xxx)...xxx is the ending number.

Block Data2 with attribute and two ending numbers (BGDT/xxx-xxx) xxx-xxx are the ending numbers

 

So i need to increase those numbers from 001 to 200 or more...

Actually i'm using incr.lsp to increase my numbers but he's only working with one ending numbers...evrytime i select a atrribute he made +1.

 

But in this case i need a lisp who can made from two ending numbers a logical suite.

 

For sample when i select de first one with xxx...he made 001...and if the second one has xxx-xxx...he made 002-003....

TEST.dwg

Link to comment
Share on other sites

Try this routine and let me know how did the code work for you .

 

(defun c:Test (/ _inc ss n i e p s en j k)
 ;;--== Tharwat 06. 06. 2013 ==--;;
 (defun _Inc (n / o)
   (cond ((< n 10) (setq o (strcat "00" (itoa n))))
         ((<= n 99) (setq o (strcat "0" (itoa n))))
         (t (setq o (itoa n)))
   )
   o
 )
 (if (progn
       (princ "\n Select Attibuted Blocks :")
       (setq n  0
             ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))
       )
     )
   (progn
     (repeat (setq i (sslength ss))
       (setq en (entnext (ssname ss (setq i (1- i)))))
       (while (not (eq (cdr (assoc 0 (setq e (entget en)))) "SEQEND"))
         (if (and (eq (cdr (assoc 0 e)) "ATTRIB")
                  (setq p (vl-string-position 47 (cdr (assoc 1 e))))
             )
           (if
             (setq s (vl-string-position 45 (cdr (assoc 1 e)) (1+ p)))
              (progn
                (setq n (1+ n)
                      j (_inc n)
                      n (1+ n)
                      k (_inc n)
                )
                (entmod
                  (subst
                    (cons 1
                          (strcat (substr (cdr (assoc 1 e)) 1 (+ 1 p))
                                  j
                                  "-"
                                  k
                          )
                    )
                    (assoc 1 e)
                    e
                  )
                )
              )
              (progn
                (setq n (1+ n))
                (entmod
                  (subst
                    (cons 1
                          (strcat (substr (cdr (assoc 1 e)) 1 (+ 1 p))
                                  (_inc n)
                          )
                    )
                    (assoc 1 e)
                    e
                  )
                )
              )
           )
         )
         (setq en (entnext en))
       )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

We go forward!!!!

 

Can you do somethings to see number(s) each time i select a attribute? So i can really follow my result.

Actually i need to select all attribute and then i can see the results.

 

Also actually the last attribute give me the first number? Better the first attribute ----> first number.

 

THANKS!!!!!

Link to comment
Share on other sites

(Defun c:IT  (/ ZeroPref  ss two att names)
(vl-load-com)
(defun ZeroPref  (str)
           (strcat (nth (strlen str) '(x "00" "0" "")) str)
           )
[color="blue"];;;	Add your blocknames here			;;;
(setq Names (list
;;;	IF the block only have one number add here	;;;
                 '("PRISE-M120" "PRISE-M150" "PRISE-SR" )

;;;	if the block has two numbers add it here	;;;
                   '("PRISE DOUBLE WIFI 1"
                     "PRISE-D" "PRISE-DR"
                     "PRISE-P"))
                        )      [/color]
(setq qstr  (getstring
         (strcat "\nEnter Prefix <"
                 (cond (prefx)
                       ("BGDT"))
                 ">: "))
prefx (cond ((/= qstr "") (strcase qstr))
         (prefx)
         ("BGDT"))
)
(setq num  (cond
              ((getint
                     (strcat "\nEnter Start number"
                             (if num
                                   (strcat " <"
                                           (ZeroPref
                                                 (itoa num))
                                           ">: ")
                                   ": ")
                             )))
              (num))
   )
     (While (and (princ (strcat "\nCurrent number "
                                (ZeroPref (itoa num))))
                 (setq two nil
                       ss  (ssget
                                 "_:S:L"
                                 ([color="blue"]list '(0 . "INSERT")'(66 . 1)
                                 (cons 2 (apply 'strcat
                                               (mapcar '(lambda (d)
                                                (strcat  d ","))
                                                     (apply 'append
                                                            names)))))))[/color])
           (if (Setq att (vl-some
                         '(lambda (j)
                                (if (eq (vla-get-tagstring j) "NR") j))
                         (vlax-invoke
                               (setq e (vlax-ename->vla-object
                                     (ssname ss 0)))
                               'GetAttributes))
                 )
               (progn
		[color="blue"](setq two (member
                                        (vla-get-effectivename e)
                                       (cadr Names)))[/color]
            (vla-put-textstring att
                  (strcat prefx "."
                          (if two
                                (strcat (ZeroPref (itoa num))
                                        "-"
                                       (ZeroPref (itoa (1+ num))))
                                     (ZeroPref (itoa num)))))
            (setq num (+ (if two 2
                               1)
                         num))))
           )
     (princ)
     )

Edited by pBe
UPDATE CODE
Link to comment
Share on other sites

pBe,

 

That's the way i'm looking for!!!!!!

 

Is that right if it's not BGDT/ but ABCD/ (for sample), i just need to change this here: (strcat "BGDT/"

 

Can you insert a line to have a popup who ask me "text before number" and "insert first number"?

Because BGDT/ was a sample... but there are different zone and so different text before the number. So i don't need to change the lisp and reload the lisp each time.

 

If not your lisp is already GREAT for me!!!

 

Thanks!

Link to comment
Share on other sites

pBe,

 

Can you insert a line to have a popup who ask me "text before number" and "insert first number"?

Because BGDT/ was a sample... but there are different zone and so different text before the number. So i don't need to change the lisp and reload the lisp each time.

 

Thanks!

 

[/b]

 

You are welcome bono05 :)

 

Remember this code will work specifically for blocks "Data1" & "Data2" with tags "G" & "A" found on your test drawing attachment.

 

Happy to help.

Link to comment
Share on other sites

IT.lsp work perfect for me....

But there is no other way than this: this code will work specifically for blocks "Data1" & "Data2" with tags "G" & "A"

 

Because that was a sample...and it will be more than two differents blocks on the plan. Problem i'm still waiting for the plans. :oops:

 

Can you make that this lisp working for each block and each tag?

 

 

THANKS YOU!!!!!!

Link to comment
Share on other sites

Because that was a sample...and it will be more than two differents blocks on the plan. Problem i'm still waiting for the plans. :oops:

Can you make that this lisp working for each block and each tag?

 

Thanks!!!

 

Yes we can its really easy.

These are the lines you need to change:

(2 . "Data1,Data2");

("A" "G");

 

Tell you what bono05 we'll cross the bridge when we get there okay? : [i'll be here]

 

Note: i wrote it that way [block and TAG specific] to make do without reading the current value for determining if the "numbers" is one or two.

Link to comment
Share on other sites

OK i understand....is there a possibilities to have 6 differents blocks "data1, data2,....data6" with tags "A,B,C,D,E,F" that i can change easily into the lisp? :unsure:

Link to comment
Share on other sites

OK i understand....is there a possibilities to have 6 differents blocks "data1, data2,....data6" with tags "A,B,C,D,E,F" that i can change easily into the lisp? :unsure:

 

Again, Yes...[but its more than just that really] i just need to see what you have... unless you know how to modify it yourself then by all means do so. :)

 

Catch you later bono05

Link to comment
Share on other sites

  • 2 years later...

Hi PBe (and all others),

 

Concerning It.lsp....

It's possible to "add" an option for block with 3 numbers and block with 4 numbers?

It would be fantastic for me because i need it for a large project.

Thanks a lot!

Bono

Link to comment
Share on other sites

Hi PBe (and all others),

 

Concerning It.lsp....

It's possible to "add" an option for block with 3 numbers and block with 4 numbers?

It would be fantastic for me because i need it for a large project.

Thanks a lot!

Bono

 

(Defun c:IT  (/ _numbers ZeroPref  op ss two att names)
;;;		pBe Jun 2013		;;;
;;;		pBe Apr 2016		;;;
 	
(vl-load-com)
(defun _numbers (int m / l)
 	(repeat m
  (setq n (ZeroPref (itoa int)))
  
  (setq l (cons (Strcat "-" n ) l)
	int (1+ int)))
 (list (substr (apply 'strcat (reverse l)) 2) int)
 )  
(defun ZeroPref  (str)
           (strcat (nth (strlen str) '(x "00" "0" "")) str)
           )

;;;		Block Names Here	;;;
 
[color="blue"]	(setq Names '(
	      
;;;	IF the block only have one number add here	;;;
	    (("PRISE-M120" "PRISE-M150"
     		"PRISE-SR" "PRISE-SP"
    		 "PRISE-S" 		)	1	)

;;;	if the block has two numbers add it here	;;;
           (("PRISE DOUBLE WIFI 1" "PRISE-D"
      		"PRISE-DR" "PRISE-P"
    					)	2	)
	    
;;;	if the block has three numbers add it here	;;;
	    (("BLOCKNAMEFOR3" 
	       
	    				)	3	)

;;;	if the block has four numbers add it here	;;;
	    (("BLOCKNAMEFOR4" 	 
	       
	    				)	4	)
	      )
      )[/color]
 
(setq qstr  (getstring (strcat "\nEnter Prefix <"
                 (cond (prefx)
                       ("BGDT"))
                 ">: "))
	prefx (cond ((/= qstr "") (strcase qstr))
	          (prefx)  ("BGDT"))
)

(setq num  (cond
              ((getint (strcat "\nEnter Start number"
                             (if num (strcat " <"
                                           (ZeroPref
                                                 (itoa num))
                                           ">: ") ": ")
                             ))) (num)))
 
(While (and (princ (strcat "\nCurrent number "
                                (ZeroPref (itoa num))))
                 (setq ss (ssget  "_:S:L" '((0 . "INSERT")(66 . 1)))))

           (if (And
		[color="blue"](setq ef (strcase (vla-get-EffectiveName (setq e (vlax-ename->vla-object
                                      		(ssname ss 0))))))
		(setq op (vl-some '(lambda (k) (if (member ef (car k)) (Cadr k))) Names))[/color]
		(Setq att (vl-some
                          '(lambda (j)
                                 (if (eq (vla-get-tagstring j) "NR") j))
                          (vlax-invoke e 'GetAttributes))
                  )
		)
	                (progn
			  (setq r (_numbers num op) s (car r) num (cadr r))
			  (vla-put-textstring att (strcat prefx "." s))    
	            		)
      		(princ "\n <<<Not a valid block >>>"))
)
     (princ)
     )

 

clydE 2.dwg

 

EDIT: Clear on what the OP meant by "...block with 3 numbers and block with 4 numbers?.."

Edited by pBe
Link to comment
Share on other sites

That's great !!!

Now it's my fault...but i have a block (3 numbers) but with 4 attributes! And of course It.lsp change only the first one...See sample dwg.

Is there a solution? Once again i'm sorry to forget this...

Drawing_test.dwg

Link to comment
Share on other sites

That's great !!!

Now it's my fault.......

 

You are right about that dude :lol:

 

.....but i have a block (3 numbers) but with 4 attributes! And of course It.lsp change only the first one...

 

Because that's from all the other samples you sent & posted.

 

Is there a solution? Once again i'm sorry to forget this...

 

Of course there is, but i wish you think about ALL the conditions before you request for modifications bono05.

 

(Defun c:IT  (/ _numbers ZeroPref  op ss  att names)
;;;		pBe Jun 2013		;;;
;;;		pBe Apr 2016		;;;
 	
(vl-load-com)
(defun _numbers (int m / l)
 	(repeat m
  (setq n (ZeroPref (itoa int)))
  
  (setq l (cons (Strcat "-" n ) l)
	int (1+ int)))
 (list (substr (apply 'strcat (reverse l)) 2) int)
 )  
(defun ZeroPref  (str)
           (strcat (nth (strlen str) '(x "00" "0" "")) str)
           )

;;;		Blcok Names Here	;;;
 
(setq Names '(
	      
;;;	IF the block only have one number add here	;;;
	    (("PRISE-M120" "PRISE-M150"
     		"PRISE-SR" "PRISE-SP"
    		 "PRISE-S" 		)	1	)

;;;	if the block has two numbers add it here	;;;
           (("PRISE DOUBLE WIFI 1" "PRISE-D"
      		"PRISE-DR" "PRISE-P"
    					)	2	)
	    
;;;	if the block has three numbers add it here	;;;
	    (( "ST-VLOERDOOS_2"
	       
	    				)	3	)

;;;	if the block has four numbers add it here	;;;
	    (("BLOCKNAMEFOR4" 	 
	       
	    				)	4	)
	      )
      )
 
(setq qstr  (getstring (strcat "\nEnter Prefix <"
                 (cond (prefx)
                       ("BGDT"))
                 ">: "))
	prefx (cond ((/= qstr "") (strcase qstr))
	          (prefx)  ("BGDT"))
)

(setq num  (cond
              ((getint (strcat "\nEnter Start number"
                             (if num (strcat " <"
                                           (ZeroPref
                                                 (itoa num))
                                           ">: ") ": ")
                             ))) (num)))
 
(While (and (princ (strcat "\nCurrent number "
                                (ZeroPref (itoa num))))
                 (setq ss (ssget  "_:S:L" '((0 . "INSERT")(66 . 1)))))

           (if (And
		(setq ef (strcase (vla-get-EffectiveName (setq e (vlax-ename->vla-object
                                      		(ssname ss 0))))))
		(setq op (vl-some '(lambda (k) (if (member ef (car k)) (Cadr k))) Names))
		[color="blue"](setq att (vl-remove-if-not '(lambda (j)
                                 (if (eq (vla-get-tagstring j) "NR") j)) (vlax-invoke e 'GetAttributes)))[/color]
		)
    [color="blue"]  (foreach itm att
		(setq r (_numbers num op) s (car r) num (cadr r))
			  (vla-put-textstring itm (strcat prefx "." s))[/color]
	)
	            		
      		(princ "\n <<<Not a valid block >>>"))
)
     (princ)
     )

Link to comment
Share on other sites

I can believe what i see :roll: It's AMAZING !!!!

And with the block with 4 attributes ...Don't need to click on each attributes separately, one click and it's done!!!!!!

1000000x Thank you Pbe!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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