Author Topic: insert coordinates of a point in text  (Read 3501 times)

0 Members and 2 Guests are viewing this topic.

danny

  • Guest
insert coordinates of a point in text
« on: September 20, 2004, 04:10:21 PM »
got a lisp that gives me coordinates of a picked point.  I tried to add a text function so the lisp inserts the coordinates in text.  I can only get it to work have way?? any help will be appreciated.

;get coordinates of a certain point
(defun c:tcoord (/ a n e z)
 (graphscr)
 (setq a (getpoint "Point:  "))
 (setq n (cadr a))
 (setq e (car a))
 (setq z (caddr a))
 (princ) (terpri)
 (princ "  Northing = " ) (prompt (rtos n 2 4)) (princ "  Elevation = " ) (prompt (rtos z 2 4)) (terpri)
 (princ "  Easting  = " ) (prompt (rtos e 2 4))
 (setq PT (getpoint "\nSelect Center point for text"))
 (setq TXTHT 0.0625)                         ;;set plotted text height
 (setq TXTHT (* TXTHT (getvar "dimscale"))) ;;adjust height per dimscale
 (command "text" "c" PT TXTHT "" (rtos e 2 4),(rtos n 2 4))
 (princ)
);end program

SMadsen

  • Guest
insert coordinates of a point in text
« Reply #1 on: September 20, 2004, 05:39:47 PM »
Danny, read up on the STRCAT function and you're there.

(command "text" "c" PT TXTHT "" (strcat (rtos e 2 4) "," (rtos n 2 4)))

42

  • Bull Frog
  • Posts: 483
insert coordinates of a point in text
« Reply #2 on: September 20, 2004, 05:39:57 PM »
I have a lsp in the office that places a marker with number, then assembles a table of the co-ordinates in a location of your choice.

Don’t get me wrong I know very little lsp but I can either give you snippets or the entire file and let you pull  the bones out of it.
Alastair Mallett Autodesk Certified Professional
Technical Director
Hunters South Architects

danny

  • Guest
insert coordinates of a point in text
« Reply #3 on: September 20, 2004, 06:08:53 PM »
thanks.. it works now.
42,
i'm interested in your lsp.  I'm running out of room, my text is overlapping, and its hard to read.  It would be great to oganize these points in a table. thanks..

42

  • Bull Frog
  • Posts: 483
insert coordinates of a point in text
« Reply #4 on: September 21, 2004, 07:40:38 AM »
Danny

This is the lisp that we use for inserting coordinates. Follow the instructions on the screen. It will insert numbered points and the create a crd file in your current directory. You can insert this into your drawing in youy favoured marror.

Code: [Select]
(defun c:os-ref ()
 (setq
    c_blp (getvar "BLIPMODE")
    c_col (getvar "CECOLOR")
    c_lay (getvar "CLAYER")
    c_cmd (getvar "CMDECHO")
    c_til (getvar "TILEMODE")
    c_osm (getvar "OSMODE")
    c_dimzin (getvar "DIMZIN")
    c_qaf (getvar "QAFLAGS")
 )
 (setvar "osmode" 37)
 (initget 4 "1 2 5 10 20 50 100 200 500 1250 2500")
 (setq dimsc (atoi (getkword "Enter drawing scale - (1 2 5 10 20 50 100 200 500 1250 2500)")))
 (if (= (tblsearch "block" "ref_pt") nil)
        (progn (entmake '((0 . "BLOCK")
                    (2 . "REF_PT")
                    (70 . 0)
                    (10 0.0 0.0 0.0)
               ))
               (entmake '((0 . "CIRCLE")
                   (67 . 0)
                   (8 . "0")
                   (10 0.0 0.0 0.0)
                   (40 . 0.75)
                   (210 0.0 0.0 1.0)
               ))
               (entmake '((0 . "LINE")
                   (67 . 0)
                   (8 . "0")
                   (10 0.0 0.0 0.0)
                   (11 0.53033 0.53033 0.0)
                   (210 0.0 0.0 1.0)
               ))
               (entmake '((0 . "LINE")
                   (67 . 0)
                   (8 . "0")
                   (10 0.0 0.0 0.0)
                   (11 -0.53033 0.53033 0.0)
                   (210 0.0 0.0 1.0)
               ))
               (entmake '((0 . "LINE")
                   (67 . 0)
                   (8 . "0")
                   (10 0.0 0.0 0.0)
                   (11 -0.53033 -0.53033 0.0)
                   (210 0.0 0.0 1.0)
               ))
               (entmake '((0 . "LINE")
                   (67 . 0)
                   (8 . "0")
                   (10 0.0 0.0 0.0)
                   (11 0.53033 -0.53033 0.0)
                   (210 0.0 0.0 1.0)
               ))
               (entmake '((0 . "ENDBLK"))
               )
         )        
 )
 (setq prefix (if (= (setq test2 (getstring 1 (strcat "Enter reference prefix (. for none)<" (if (/= prefix nil) prefix ".") "> :"))) ".") prefix test2))
 (if (/= (and (tblsearch "layer" "A0COORDS") (ssget "X" '((0 . "TEXT") (8 . "A0COORDS")))) nil)
    (progn
      (setq
        no_ent (ssget "X" '((0 . "TEXT") (8 . "A0COORDS")))
        no_ent2 (sslength no_ent)
        cnt (+ no_ent2 1)
        cnt (if (= (setq test (getint (strcat "Start numbering from? <" (rtos cnt 2 0) "> :"))) nil) cnt test)
        coord_fil (open (strcat (getvar "DWGPREFIX") (SUBSTR (GETVAR "DWGNAME") 1 (- (STRLEN (GETVAR "DWGNAME")) 3)) "crd") "a")
        pt1 (getpoint "\nPick point: ")
        x (nth 0 pt1)
        y (nth 1 pt1)
      )
    )
    (progn
      (command "layer" "m" "A0COORDS" "c" "7" "" "")
      (setq
        cnt 1
        cnt (if (= (setq test (getint (strcat "Start numbering from? <" (rtos cnt 2 0) "> :"))) nil) cnt test)
        coord_fil (open (strcat (getvar "DWGPREFIX") (SUBSTR (GETVAR "DWGNAME") 1 (- (STRLEN (GETVAR "DWGNAME")) 3)) "crd") "w")
        pt1 (getpoint "\nPick point: ")
        x (nth 0 pt1)
        y (nth 1 pt1)
      )
    )
  )
  (write-line (strcat (strcat prefix (rtos cnt 2 0)) ","(strcat (rtos (/ y 1000) 2 3) "N")","(strcat (rtos (/ x 1000) 2 3) "E")) coord_fil)
  (close coord_fil)
  (command "insert" "ref_pt" pt1 dimsc dimsc "0")
  (command "text" "m" "none" (subst (+ (* 2.1 dimsc) (cadr pt1)) (nth 1 pt1) pt1) (* dimsc 2.0) "0" (strcat prefix (rtos cnt 2 0)))
  (setq cnt (+ cnt 1))
  (setq pt1 (getpoint "\nPick point: "))
  (while (/= pt1 nil)
    (setq
      coord_fil (open (strcat (getvar "DWGPREFIX") (SUBSTR (GETVAR "DWGNAME") 1 (- (STRLEN (GETVAR "DWGNAME")) 3)) "crd") "a")
      x (nth 0 pt1)
      y (nth 1 pt1)
    )
    (write-line (strcat (strcat prefix (rtos cnt 2 0))","(strcat (rtos (/ y 1000) 2 3) "N")","(strcat (rtos (/ x 1000) 2 3) "E")) coord_fil)
    (close coord_fil)
    (command "insert" "ref_pt" pt1 dimsc dimsc "0")
    (command "text" "m" "none" (subst (+ (* 2.1 dimsc) (cadr pt1)) (nth 1 pt1) pt1) (* dimsc 2.0) "0" (strcat prefix (rtos cnt 2 0)))
    (setq cnt (+ cnt 1))
    (setq pt1 (getpoint "\nPick point: "))
  )
 (command "-layer" "thaw" c_lay "on" c_lay "")
 (setvar "CLAYER" c_lay)
 (setvar "BLIPMODE" c_blp)
 (setvar "CECOLOR" c_col)
 (setvar "CMDECHO" c_cmd)
 (setvar "TILEMODE" c_til)
 (setvar "OSMODE" c_osm)
 (setvar "DIMZIN" c_dimzin)
 (setvar "QAFLAGS" c_qaf)
)
Alastair Mallett Autodesk Certified Professional
Technical Director
Hunters South Architects

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
insert coordinates of a point in text
« Reply #5 on: September 21, 2004, 10:35:11 AM »
another way .............
Code: [Select]

;;; sub-routine
;;; create a text entity that uses the current layer,
;;; current textstyle and textsize. horiz. justification
;;; is "center" and vert. justification is "bottom"
;;;
;;; str = string
;;; pt = 3D point list, the insertion point
(defun make-txt (str pt / txt_ent)
  (if
    (setq txt_ent
          (entmake
            (list
              '(0 . "TEXT")
              (cons 10 pt)
              (cons 8 (getvar "clayer"))
              (cons 40 (getvar "textsize"))
              (cons 1 str)
              (cons 7 (getvar "textstyle"))
              '(72 . 1); = horz. centered
              (cons 11 pt)
              '(73 . 1); = vert. bottom
              )
            )
          )
    txt_ent
    )
  )

;;; main function
;;;
;;; prints the xyz values of the selected point to the command
;;; line and places the "x,y" values in the dwg as a text entity
;;; at the user defined position
;;;
;;; if you want specific rounding of x & y values then change
;;; the lines '(rtos (..r pt) 2 <number of places>)' i.e.
;;; for 4 decimal places you would use (rtos (car pt) 2 4)
(defun c:tcoord (/ pt str1 str2 str_pt screen_txt)

(cond ((setq pt (getpoint "\nSelect Point: "))
       (setq str1
             (strcat
               "\nNorthing = "
               (rtos (cadr pt))
               " Elevation = "
               (rtos (caddr pt))
               "\n"
               )
             str2
             (strcat
               "Easting = "
               (rtos (car pt))
               )
             )
       ;; output to the command line
       (princ str1); Northing = 1000.00 Elevation = 1000.00
       (princ str2); Easting = 1000.00

       (cond ((setq str_pt (getpoint pt "\nSelect Text Center Point: "))
              (setq screen_txt
                    ;; output = (x)1000.00,(y)1000.00
                    (strcat (rtos (car pt))","(rtos (cadr pt)))
                    )
              (make-txt screen_txt str_pt))
             ))
      (T (princ))
      )
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

danny

  • Guest
insert coordinates of a point in text
« Reply #6 on: September 22, 2004, 02:19:07 PM »
thanks guys.