Start Numbering From 0

Start Numbering From 0

ImagenZeta
Participant Participant
1,055 Views
10 Replies
Message 1 of 11

Start Numbering From 0

ImagenZeta
Participant
Participant

This work perfect for numbering vertexes in a polyline, nIt starts numbers from "1", but is there a way to make it start numbering from "0"??????

 

(defun c:vername (/ e i j m n p s x)
  (if (and (setq s (ssget '((0 . "LWPOLYLINE"))))
	   (setq x (getstring "\nSpecify prefix <enter for none>: "))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    n (cdr (assoc 210 (entget e)))
	    m (vlax-curve-getendparam e)
	    j -1
      )
      (while (<= (setq j (1+ j)) m)
	(setq p (trans (vlax-curve-getpointatparam e j) 0 e))
	(entmakex
	  (list
	    (cons 0 "TEXT")
	    (cons 7 (getvar 'TEXTSTYLE))
	    (cons 40 (getvar 'TEXTSIZE))
	    (cons 10 p)
	    (cons 11 p)
	    (cons 72 1)
	    (cons 73 2)
	    (cons 1 (strcat x (itoa (1+ j))))
	    (cons 210 n)
	  )
	)
      )
    )
  )
  (princ)
)

 

0 Likes
Accepted solutions (2)
1,056 Views
10 Replies
Replies (10)
Message 2 of 11

WarrenGeissler
Advisor
Advisor

While you may get lucky and get an answer here, you are going to get a faster response and much better bandwidth posting this over in the AutoCAD Customization / LISP forum >>HERE<<




Warren Geissler
Drafting Manager Denver Water
_____________________________________________

Please ACCEPT AS SOLUTON if this works
(...and doesn't melt your computer or cause Armageddon)

0 Likes
Message 3 of 11

ImagenZeta
Participant
Participant
Thanks a lot, I'll follow your advice.
0 Likes
Message 4 of 11

Anonymous
Not applicable

 


(defun c:vername (/ e i j m n p s x) (if (and (setq s (ssget '((0 . "LWPOLYLINE")))) (setq x (getstring "\nSpecify prefix <enter for none>: ")) ) (repeat (setq i (sslength s)) (setq e (ssname s (setq i (1- i))) n (cdr (assoc 210 (entget e))) m (vlax-curve-getendparam e) j -1 ) (while (<= (setq j (1+ j) ) m) (setq p (trans (vlax-curve-getpointatparam e j) 0 e)) (entmakex (list (cons 0 "TEXT") (cons 7 (getvar 'TEXTSTYLE)) (cons 40 (getvar 'TEXTSIZE)) (cons 10 p) (cons 11 p) (cons 72 1) (cons 73 2) (cons 1 (strcat x (itoa (- (1+ j) 1)))) (cons 210 n) ) ) ) ) ) (princ) )

 

0 Likes
Message 5 of 11

Anonymous
Not applicable

I did not test, but I think it works. @ImagenZeta

 

(cons 1 (strcat x (itoa (- (1+ j) 1))))
0 Likes
Message 6 of 11

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

I did not test, but I think it works. @ImagenZeta

 

(cons 1 (strcat x (itoa (- (1+ j) 1))))

Man, better double check your math. 

0 Likes
Message 7 of 11

Anonymous
Not applicable
Accepted solution

lol

This may not be a more elegant way to do it, but it will work !!

 

 

 

 

0 Likes
Message 8 of 11

Anonymous
Not applicable

That's better ?

 

(cons 1 (strcat x (itoa j)))

 

Message 9 of 11

pbejse
Mentor
Mentor

 

What would be the the value of variable j with this line Frjuniornogueira?

 

...
(cons 1 (strcat x (itoa (- (1+ j) 1))))
...

 

 

There is no need to add 1 to variable at (1+ j ) , which makes j 1 from  0 and then reduce the the value by 1 to make 0 when the value of j is already 0 to start with at (<= (setq j (1+ j)) m).

 

 

Message 10 of 11

Anonymous
Not applicable

It really was a slip, I only realized when the @ВeekeeCZ corrected me!

 

but correct me here.

 

(cons 1 (strcat x (itoa j)))
0 Likes
Message 11 of 11

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

It really was a slip, I only realized when the @ВeekeeCZ corrected me!

 

but correct me here.

 

(cons 1 (strcat x (itoa j)))

That is the quickest fix. so its all good.

 

I also suggested the same here

 

One can also set j to 0 here

 

 

...
	    m (vlax-curve-getendparam e)
	    j 0
      )
...

 

 

Then increase the value of variable j  after entmake and not before.

 

 

	    (cons 73 2)
	    (cons 1 (strcat x (itoa j)))
	    (cons 210 n)
	  )
	)
        (setq j (1+ j))
      )

 

 

or even use repeat in place of while 

 

(repeat (1+ (fix m)) ...

 

There's more than one way to skin a cat. 🙂

 

HTH