Author Topic: Routine wanted to modifile-added missing line  (Read 2226 times)

0 Members and 1 Guest are viewing this topic.

kottok

  • Guest
Routine wanted to modifile-added missing line
« on: October 11, 2008, 01:21:40 AM »
i have this lisp which allows me to place result in drawing,but i want to write out to a text file with select y/n,how to do it?
 thanks!

Code: [Select]
; (c) Marker Engineering Surveying Co.
;Place CH,O/S,Easting and Northing on drawing with leader to point
(prompt "\nMarker Engineering Surveying Co.")
(defun c:chosen (/ endpt ent off offpt onpt ss sta startpt)
(defun Xmarksthespot (x y / leglen start)
(setq start (list x y)
leglen (* 0.03 (getvar "viewsize"))
)
(grdraw (polar start (angtof "135" 1) leglen)
(polar start (angtof "315" 1) leglen)
7)
(grdraw (polar start (angtof "45" 1) leglen)
(polar start (angtof "225" 1) leglen)
7)
)
(while (setq ss (ssget ":S" '((0 . "LINE,*POLYLINE,SPLINE,ARC"))))
(setq ent (ssname ss 0))
(setq startpt (vlax-curve-getstartpoint ent)
endpt (vlax-curve-getendpoint ent)
)
(xmarksthespot (car startpt)(cadr startpt))
(setq startptch(getreal "\nStart Point Ch="))
(setq t1 "Text Height: <default = ")
(setq t2 " >: ")
(setq t3 (getvar "textsize"))
(terpri)
(setq HT (getreal (strcat t1 (rtos t3 2 2) t2)))
(if (= HT nil)
(setq HT t3)
)
(command "dim" "dimtxt" ht "exit")
(command "dim" "dimasz" ht "exit")
(setq a " N ")
(setq b " E ")
(setq c "CH=")
(setq d "O/S=")
(while (setq offpt (getpoint "\nOffset point: "))
(setq onPt (vlax-curve-getclosestpointto ent offpt)
sta (vlax-curve-getdistatpoint ent onpt)
off (distance onpt offpt)
)
(setq ch (rtos (+ sta startptch) 2 3))
(setq off1 (rtos off 2 3))
;(setq p1 (getpoint "\nCoordinates of which point?"))
(setq e (rtos (car offpt) 2 3))
(setq n (rtos (cadr offpt) 2 3))
(setq coorde (strcat e b))
(setq coordn (strcat n a))
(setq chainage (strcat c ch))
(setq offset (strcat d off1))
(setq p2 (getpoint offpt"\nText Location:"))
(command "_leader" offpt p2 "a" chainage offset coorde coordn "")
;(princ (strcat "Station: " (rtos sta 2 2) " - Offset: " (rtos off 2 2)))
)
(redraw)
)
(princ)
)
(prompt "\nType CHOSEN to start routine ")



original lisp
Code: [Select]
Re: Baseline Station and Offset
Thanks for the reply, I got a wonderful routine from the customization NG.
BTW, just using vanilla AutoCAD. Here is the routine I got from there, I'll
share here for the curious. This seems to work well for my needs. Thanks
all.

;;station/offset listing
(defun c:sta-off (/ endpt ent off offpt onpt ss sta startpt)
;; Marker for point location on the screen
;; Oct. 2004 by Jeff Mishler
(defun Xmarksthespot (x y / leglen start)
(setq start (list x y)
leglen (* 0.03 (getvar "viewsize"))
)
(grdraw (polar start (angtof "135" 1) leglen)
(polar start (angtof "315" 1) leglen)
7)
(grdraw (polar start (angtof "45" 1) leglen)
(polar start (angtof "225" 1) leglen)
7)
)
(while (setq ss (ssget ":S" '((0 . "LINE,*POLYLINE,SPLINE,ARC"))))
(setq ent (ssname ss 0))
(setq startpt (vlax-curve-getstartpoint ent)
endpt (vlax-curve-getendpoint ent)
)
(xmarksthespot (car startpt)(cadr startpt))
(while (setq offpt (getpoint "\nOffset point: "))
(setq onPt (vlax-curve-getclosestpointto ent offpt)
sta (vlax-curve-getdistatpoint ent onpt)
off (distance onpt offpt)
)
(princ (strcat "Station: " (rtos sta 2 2) " - Offset: " (rtos off 2
2)))
)
(redraw)
)
(princ)
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Routine wanted to modifile-added missing line
« Reply #1 on: October 11, 2008, 01:45:24 AM »
Give this a try:

Code: [Select]
; (c) Marker Engineering Surveying Co.
;Place CH,O/S,Easting and Northing on drawing with leader to point
(prompt "\nMarker Engineering Surveying Co.")
(defun c:chosen (/ a      b      c      ch     chainage
coorde coordn d      e      file   fn    ht
keyw message       n      off1   offset p2
startptch     t1     t2     t3     endpt  ent
off offpt  onpt   ss     sta    startpt
)
  (defun Xmarksthespot (x y / leglen start)
    (setq start (list x y)
  leglen (* 0.03 (getvar "viewsize"))
    )
    (grdraw (polar start (angtof "135" 1) leglen)
    (polar start (angtof "315" 1) leglen)
    7
    )
    (grdraw (polar start (angtof "45" 1) leglen)
    (polar start (angtof "225" 1) leglen)
    7
    )
  )
  (initget 0 "Yes No")
  (setq keyw (getkword "\nExport results [Yes/No]: "
     )
file (strcat (getvar 'dwgprefix)
     (vl-filename-base (getvar 'dwgname))
     "_station.csv"
     )
  )
  (while (setq ss (ssget ":S" '((0 . "LINE,*POLYLINE,SPLINE,ARC"))))
    (setq ent (ssname ss 0))
    (setq startpt (vlax-curve-getstartpoint ent)
  endpt   (vlax-curve-getendpoint ent)
    )
    (xmarksthespot (car startpt) (cadr startpt))
    (setq startptch (getreal "\nStart Point Ch="))
    (setq t1 "Text Height: <default = ")
    (setq t2 " >: ")
    (setq t3 (getvar "textsize"))
    (terpri)
    (setq HT (getreal (strcat t1 (rtos t3 2 2) t2)))
    (if (= HT nil)
      (setq HT t3)
    )
    (command "dim" "dimtxt" ht "exit")
    (command "dim" "dimasz" ht "exit")
    (setq a " N ")
    (setq b " E ")
    (setq c "CH=")
    (setq d "O/S=")
    (while (setq offpt (getpoint "\nOffset point: "))
      (setq onPt (vlax-curve-getclosestpointto ent offpt)
    sta (vlax-curve-getdistatpoint ent onpt)
    off (distance onpt offpt)
      )
      (setq ch (rtos (+ sta startptch) 2 3))
      (setq off1 (rtos off 2 3))
;(setq p1 (getpoint "\nCoordinates of which point?"))
      (setq e (rtos (car offpt) 2 3))
      (setq n (rtos (cadr offpt) 2 3))
      (setq coorde (strcat e b))
      (setq coordn (strcat n a))
      (setq chainage (strcat c ch))
      (setq offset (strcat d off1))
      (setq p2 (getpoint offpt "\nText Location:"))
      (command "_leader" offpt p2 "a" chainage offset coorde coordn "")

      (if (= Keyw "Yes")
(progn
  (setq fn (open file "a"))
  (write-line
    (strcat chainage "," offset "," coorde "," coordn)
    fn
  )
  (close fn)
)
      )

;(princ (strcat "Station: " (rtos sta 2 2) " - Offset: " (rtos off 2 2)))
    )
    (redraw)
  )
  (princ)
)
(prompt "\nType CHOSEN to start routine ")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

kottok

  • Guest
Re: Routine wanted to modifile-added missing line
« Reply #2 on: October 11, 2008, 04:22:16 AM »
thanks ronjonp !

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Routine wanted to modifile-added missing line
« Reply #3 on: October 11, 2008, 07:13:16 AM »
Welcome to TheSwamp kottok.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Routine wanted to modifile-added missing line
« Reply #4 on: October 11, 2008, 09:03:07 AM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC