MessatsuX Posted September 8 Posted September 8 <--Looks like this (seems like every other one is missing a digit) <--- Should look like this I made this to station a profile grid without having to manually enter stations for long jobs. They go in increments of 50 and if below 1000 they have a 4-digit convention with a leading zero. like 00+50. If above 10,000, they are formatted like 100+50; Where did I go wrong here? Also leading zero isn't working. Here is the lisp. Thanks guys. (defun c:STA50 (/ start-station start-dist line-ent line-obj line-length point-incr cur-dist cur-station text-pt text-str) ;; Function to format station in XX+XX format (defun format-station (station) (strcat (itoa (/ station 100)) "+" (rtos (rem station 100) 2 0)) ) ;; Ask the user to enter the beginning station (e.g., 14700 for 147+00 or 0 for 00+00) (setq start-station (getstring "\nEnter beginning station (format 14700 or 0 for 00+00): ")) ;; Convert the user input to a numeric value (remove any "+" if entered by mistake) ;; The station is expected to be entered as a number, but we ensure it's converted correctly to an integer. (setq start-dist (atoi (vl-string-subst "" "+" start-station))) ;; Ask the user to select a line or polyline (setq line-ent (entsel "\nSelect a line or polyline: ")) ;; Check if a valid entity was selected (if (and line-ent (eq (type (car line-ent)) 'ENAME)) (progn ;; Get the entity object and its length (setq line-obj (vlax-ename->vla-object (car line-ent))) ;; Ensure length is calculated as a floating-point number (setq line-length (vlax-curve-getDistAtParam line-obj (vlax-curve-getEndParam line-obj))) ;; Set station increment and initial distance (setq point-incr 50.0) ; Increment stations by 50 feet (setq cur-dist 0.0) ; Initialize current distance ;; Loop to place text at 50' increments until the line length is exceeded (while (<= cur-dist line-length) ;; Calculate the current station by adding the station distance to the current offset (setq cur-station (+ start-dist (fix cur-dist))) ;; Format the station as XX+XX (e.g., 147+00 or 00+00) (setq text-str (format-station cur-station)) ;; Get the point on the line at the current distance (setq text-pt (vlax-curve-getPointAtDist line-obj cur-dist)) ;; Adjust the text point to be 10.82 feet below the line (setq text-pt (list (car text-pt) (- (cadr text-pt) 10.82) (caddr text-pt))) ;; Create the text entity with Arial font, height of 4.0, at the calculated point (entmakex (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 1 text-str) ; The text content (e.g., "147+00" or "00+00") (cons 7 "Arial") ; Text style (cons 40 4.0) ; Text height (cons 10 text-pt))) ; Insertion point ;; Increment the current distance by 50 feet for the next station (setq cur-dist (+ cur-dist point-incr)) ) ) (princ "\nInvalid selection. Please select a line or polyline.") ) ;; End of the command (princ) ) Quote
BIGAL Posted September 9 Posted September 9 No answer to your question but why not use a CIVIL design package like CIV3D or Civil Site Design, which have all this done for you plus so much more, time is money and these programs will pay for them selves. Quote
Steven P Posted September 9 Posted September 9 Try this: (defun format-station (station / Hundreds Tens) (setq Hundreds (itoa (/ station 100)) ) ;;Split out the 'hundreds' (setq Tens (rtos (rem station 100) 2 0) ) ;;Split out the 'tens' (while (< (strlen Tens) 2) ;;Change '2' here to the string length including leading zeros. (setq Tens (strcat "0" Tens)) ;;Add a leading zero ) ; end while ;;repeat if string length is still too short (strcat Hundreds "+" Tens) ;;Create text ) Quote
Recommended Posts
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.