Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

station numbering lisp routine??

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
2584 Views, 11 Replies

station numbering lisp routine??

I have to station (number in increments of 100) polylines quite often. I would be EXTREMELY helpful if I could get it to do this automatically. Right now I have been creating a block and using measure command on a polyline to do this, then going back and editing text. Is it possible to do this? It doesnt have to be this way, but an example of the format is: 1+00, 2+00, 3+00, etc., in 100' increments. I do have a routine that will put the + in.

Thanks in advance
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

(setq lst '(1 2 3 4 5 6 ... 100))
(setq str (apply 'strcat (mapcar (function (lambda (x)
(strcat (itoa x)"+00,"))) lst)))
; Return string: "1+00,2+00,3+00,4+00,5+00,6+00,....100+00"
(setq new_list (read (strcat "(" str ")")))
; Return list:(1+00,2+00,3+00,4+00,5+00,6+00,....100+00)
Message 3 of 12
Anonymous
in reply to: Anonymous

Sorry, but I dont have enough experience with lisp to get this to work.
Message 4 of 12
Anonymous
in reply to: Anonymous

Thanks. Didnt know that 2004 had a text numbering command.....
Message 5 of 12
Anonymous
in reply to: Anonymous

Is there any way to edit this to account for 50' incements?  i.e. 1+00, 1+50, 2+00, 2+50,...

Also, can it be edited to begin at a number besides 1? 

 

Thank you so much for your lisp.  I have seen several posts by you for many of my AutoCAD questions, and you are always very helpful.

Message 6 of 12
smaher12
in reply to: Anonymous

Are you looking to do something like the following?

 

The following does have a quark (Unknown command) when you exit the program. Can't seem to figure it out right now. I'm curious if someone knows why...

 

 

(defun c:test (/ cnt p1 p2)
  (setvar 'cmdecho 0)
  (setq cnt (getint "\nSpecify start number: "))
  
  (while
    (setq p1 (getpoint "\nSpecify point: "))
    (command "_.text" "bl" "_none" p1 1 0  (strcat (itoa cnt) "+00"))
    (setq p2 (getpoint "\nSpecify point: "))
    (command "_.text" "bl" "_none" p2 1 0  (strcat (itoa cnt) "+50"))
    (setq cnt (1+ cnt))
  ); while
 (princ)
)

 

Message 7 of 12
hmsilva
in reply to: smaher12


smaher12 wrote:

The following does have a quark (Unknown command) when you exit the program. Can't seem to figure it out right now. I'm curious if someone knows why... 


Hi smaher12,

you should test the existence of correct argument before providing it to the the function.

i.e.

(setq cnt (getint "\nSpecify start number: "))

if the user press the spacebar or the enter,  your test function will continue the evaluation and will provide a "nil" cnt to the itoa function inside the text command, and the user should receive an  "error: bad argument type: fixnump: nil"

In the while function, the

(setq p1 (getpoint "\nSpecify point: "))

is the only  test function, if the user try to exits the test function at the

(setq p2 (getpoint "\nSpecify point: "))

pressing the spacebar or the enter, is going to provide a "nil" p2 to the

(command "_.text" "bl" "_none" p2 1 0  (strcat (itoa cnt) "+50"))

the text command will try to evaluate the arguments, cancels the command and send to the command line the

(strcat (itoa cnt) "+50")

as a command, the return should be a

"Unknown command "##+##".  Press F1 for help."

 

Perhaps something like this do the trick

 

(defun c:test (/ cnt old_echo p1 p2)
  (vl-load-com)
  (setq old_echo (getvar 'CMDECHO))
  (setvar 'cmdecho 0)
  (if (setq cnt (getint "\nSpecify start number <exit>: "))
    (while
      (and (setq p1 (getpoint "\nSpecify point <exit>: "))
	   (vl-cmdf "_.text" "bl" "_none" p1 1 0 (strcat (itoa cnt) "+00"))
	   (setq p2 (getpoint "\nSpecify point <exit>: "))
	   (vl-cmdf "_.text" "bl" "_none" p2 1 0 (strcat (itoa cnt) "+50"))
      );; and
       (setq cnt (1+ cnt))
    ); while
  );; if
  (setvar 'cmdecho old_echo)
  (princ)
)

 

HTH

Henrique

 

EESignature

Message 8 of 12
_gile
in reply to: hmsilva

Hi,

 

You can also try the 'Increment' plug-in available on Autodesk Exchange Apps.

I'ts not a LISP solution, but should do the trick (and many others).

 

In the dialog, set Value type to Digits, increment to 50 and separator to + to get

1+50 -> 2+00 -> 2+50 -> 3+00 ...

Choose the selection Tab to edit existing texts or attributes.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 12
lolivasQ7X83
in reply to: Anonymous

i have tried this lisp and it works for the most part but i am looking for something that can also self station to the length of the polyline without me having to manually select each point of the station. can you assist?

Message 10 of 12
john.uhden
in reply to: Anonymous

I could write what you want, but my wife doesn't like my giving away my time to strangers.  Why aren't you using Civil 3D?  Or can you borrow/steal an old copy of AutoCAD Land Desktop?  How do you do profiles and earthwork?

John F. Uhden

Message 11 of 12
Sea-Haven
in reply to: lolivasQ7X83

Just google for Chainage.lsp many different versions out there will do what you want, John no need to reinvent the wheel.

Message 12 of 12
bwattsAUCMD
in reply to: Anonymous

As ubiquitous as C3D is and as old as this query is; answering it may be a moot point.  But even lately I'll hear or read of someone stuck with generic AutoCAD  or still on the Civil learning curve.  Besides, I owe this forum for all the help aplenty. 

 

See attached.  Its more an inquiry and station tagging tool then a stationer.

 

But with a little code tweaking it could do actual stationing.  But there's probably a dozen of them out there already waiting to be uploaded.  Maybe when I get some down time.

 

b

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost