Author Topic: 3d polyline export to *.txt  (Read 9931 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
3d polyline export to *.txt
« on: April 30, 2014, 12:54:29 PM »
Hi ,I am trying to export 3d polyline coordinates and elevetion to *.txt file

the export file must be  (x,y,z)  like this

Quote
270.309,359.292,125.32
299.161,467.638,45.32
376.760,475.590,65.23
517.036,475.590,45.65

here is my code .I have an export problem and i need some help

Code - Auto/Visual Lisp: [Select]
  1. (defun c:3dpe ()
  2.   (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
  3.                       (0 . "POLYLINE")(-4 . "OR>"))))
  4.   (if sset
  5.     (progn
  6.       (setq itm 0 num (sslength sset))
  7.       (setq fn (getfiled "Point Export File" "" "txt" 1))
  8.       (if (/= fn nil)
  9.         (progn
  10.           (setq fh (open fn "w"))
  11.           (while (< itm num)
  12.             (setq hnd (ssname sset itm))
  13.             (setq ent (entget hnd))
  14.             (setq obj (cdr (assoc 0 ent)))
  15.             (cond
  16.               ((= obj "POINT")
  17.                 (setq pnt (cdr (assoc 10 ent)))
  18.                 (setq pnt (trans pnt 0 1));;**CAB
  19.                 (princ (strcat (rtos (car pnt) 2 3) ","
  20.                                (rtos (cadr pnt) 2 3) ","
  21.                                (rtos (caddr pnt) 2 3)) fh)
  22.                 (princ "\n" fh)
  23.               )
  24.               ((= obj "POLYLINE")
  25.                 (if (= (cdr (assoc 38 ent)) nil)
  26.                   (setq elv 0.0)
  27.                   (setq elv (cdr (assoc 38 ent)))
  28.                 )
  29.                 (foreach rec ent
  30.                   (if (= (car rec) 10)
  31.                     (progn
  32.                       (setq pnt (cdr rec))
  33.                       (setq pnt (trans pnt 0 1));;**CAB
  34.                       (princ (strcat (rtos (car pnt) 2 3) ","
  35.                                      (rtos (cadr pnt) 2 3) ","
  36.                                      (rtos elv 2 3)) fh)
  37.                       (princ "\n" fh)
  38.                     )
  39.                   )
  40.                 )
  41.               )
  42.               (t nil)
  43.             )
  44.             (setq itm (1+ itm))
  45.           )
  46.           (close fh)
  47.         )
  48.       )
  49.     )
  50.   )
  51.   (princ)
  52. )
  53.  

Thanks
« Last Edit: April 30, 2014, 01:14:39 PM by Topographer »

ribarm

  • Gator
  • Posts: 3256
  • Marko Ribar, architect
Re: 3d polyline export to *.txt
« Reply #1 on: April 30, 2014, 01:18:34 PM »
Code - Auto/Visual Lisp: [Select]
  1. ((= obj "POLYLINE")
  2.  (setq v hnd)
  3.  (while (/= (cdr (assoc 0 (setq v (entnext v)))) "SEQEND")
  4.    (progn
  5.      (setq pnt (cdr (assoc 10 (entget v))))
  6.      (setq pnt (trans pnt hnd 1));;**CAB
  7.      (princ (strcat (rtos (car pnt) 2 3) ","
  8.                     (rtos (cadr pnt) 2 3) ","
  9.                     (rtos (cadr pnt) 2 3)) fh)
  10.      (princ "\n" fh)
  11.    )
  12.  )
  13. )
  14.  

Replace (cond) statement for POLYLINE entity with this piece...
« Last Edit: April 30, 2014, 02:45:56 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: 3d polyline export to *.txt
« Reply #2 on: April 30, 2014, 01:33:55 PM »
Hi ribam i try it but is not working

Code - Auto/Visual Lisp: [Select]
  1. (defun c:3dpe ()
  2.   (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
  3.                       (0 . "POLYLINE")(-4 . "OR>"))))
  4.   (if sset
  5.     (progn
  6.       (setq itm 0 num (sslength sset))
  7.       (setq fn (getfiled "Point Export File" "" "txt" 1))
  8.       (if (/= fn nil)
  9.         (progn
  10.           (setq fh (open fn "w"))
  11.           (while (< itm num)
  12.             (setq hnd (ssname sset itm))
  13.             (setq ent (entget hnd))
  14.             (setq obj (cdr (assoc 0 ent)))
  15.             (cond
  16.               ((= obj "POINT")
  17.                 (setq pnt (cdr (assoc 10 ent)))
  18.                 (setq pnt (trans pnt 0 1));;**CAB
  19.                 (princ (strcat (rtos (car pnt) 2 3) ","
  20.                                (rtos (cadr pnt) 2 3) ","
  21.                                (rtos (caddr pnt) 2 3)) fh)
  22.                 (princ "\n" fh)
  23.               )
  24.               ((= obj "POLYLINE")
  25.  (setq v obj)
  26.  (while (/= (cdr (assoc 0 (setq v (entnext v)))) "SEQEND")
  27.    (progn
  28.      (setq pnt (cdr (assoc 10 (entget v))))
  29.      (setq pnt (trans pnt obj 1));;**CAB
  30.      (princ (strcat (rtos (car pnt) 2 3) ","
  31.                     (rtos (cadr pnt) 2 3) ","
  32.                     (rtos elv 2 3)) fh)
  33.      (princ "\n" fh)
  34.    )
  35.  )
  36. )
  37.        
  38.               (t nil)
  39.             )
  40.             (setq itm (1+ itm))
  41.           )
  42.           (close fh)
  43.         )
  44.       )
  45.     )
  46.   )
  47.   (princ)
  48. )
  49.  

ribarm

  • Gator
  • Posts: 3256
  • Marko Ribar, architect
Re: 3d polyline export to *.txt
« Reply #3 on: April 30, 2014, 02:45:11 PM »
Sorry, I was in a hurry... Check my edited post...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: 3d polyline export to *.txt
« Reply #4 on: April 30, 2014, 03:24:40 PM »
nothing .The export file is empty ..

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.   (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
  3.                       (0 . "POLYLINE")(-4 . "OR>"))))
  4.   (if sset
  5.     (progn
  6.       (setq itm 0 num (sslength sset))
  7.       (setq fn (getfiled "Point Export File" "" "txt" 1))
  8.       (if (/= fn nil)
  9.         (progn
  10.           (setq fh (open fn "w"))
  11.           (while (< itm num)
  12.             (setq hnd (ssname sset itm))
  13.             (setq ent (entget hnd))
  14.             (setq obj (cdr (assoc 0 ent)))
  15.             (cond
  16.               ((= obj "POINT")
  17.                 (setq pnt (cdr (assoc 10 ent)))
  18.                 (setq pnt (trans pnt 0 1));;**CAB
  19.                 (princ (strcat (rtos (car pnt) 2 3) ","
  20.                                (rtos (cadr pnt) 2 3) ","
  21.                                (rtos (caddr pnt) 2 3)) fh)
  22.                 (princ "\n" fh)
  23.               )
  24.               ((= obj "POLYLINE")
  25.  (setq v hnd)
  26.  (while (/= (cdr (assoc 0 (setq v (entnext v)))) "SEQEND")
  27.    (progn
  28.      (setq pnt (cdr (assoc 10 (entget v))))
  29.      (setq pnt (trans pnt hnd 1));;**CAB
  30.      (princ (strcat (rtos (car pnt) 2 3) ","
  31.                     (rtos (cadr pnt) 2 3) ","
  32.                     (rtos (cadr pnt) 2 3)) fh)
  33.      (princ "\n" fh)
  34.    )
  35.  )
  36. )
  37.  
  38.  
  39.               (t nil)
  40.             )
  41.             (setq itm (1+ itm))
  42.           )
  43.           (close fh)
  44.         )
  45.       )
  46.     )
  47.   )
  48.   (princ)
  49. )
  50.  

ronjonp

  • Needs a day job
  • Posts: 7527
Re: 3d polyline export to *.txt
« Reply #5 on: April 30, 2014, 03:32:10 PM »
Just a quick glance but I do not see WRITE-LINE anywhere in the code. That would explain an empty text file.
http://docs.autodesk.com/ACD/2014/ENU/index.html?url=files/GUID-CB4F3ABC-F0F6-41DA-A911-75B90D9F974A.htm,topicNumber=d30e641793
« Last Edit: April 30, 2014, 03:38:00 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: 3d polyline export to *.txt
« Reply #6 on: April 30, 2014, 03:40:35 PM »
here is my test dwg

ronjonp

  • Needs a day job
  • Posts: 7527
Re: 3d polyline export to *.txt
« Reply #7 on: April 30, 2014, 03:50:11 PM »
I'll give you a hint .. the error is on this line: (while (/= (cdr (assoc 0 (setq v (entnext v)))) "SEQEND")


Take a look at what ASSOC requires and look at what is being passed.
And you still need to include WRITE-LINE.
« Last Edit: April 30, 2014, 03:55:30 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7527
Re: 3d polyline export to *.txt
« Reply #8 on: April 30, 2014, 11:13:22 PM »
You figure it out ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

fixo

  • Guest
Re: 3d polyline export to *.txt
« Reply #9 on: May 01, 2014, 01:25:25 AM »
Hi Topographer
Try this out
Code: [Select]
(defun c:tw (/ ent fh fn hnd itm num obj pnt sset v vexx)
  ;; helper to get 3dpoly coordinates
  (defun 3dpoly-verts  (en / elist  lst vex)
 
  (if (member "AcDb3dPolyline"
      (mapcar 'cdr (entget en)))
    (progn
      (setq vex (entnext en))
      (setq elist (entget vex))
      (while (= (cdr (assoc 0 elist)) "VERTEX")
(setq lst (cons (trans (cdr (assoc 10 elist)) 1 0) lst))
(setq vex (entnext vex))
(setq elist (entget vex))
)
      )
    )
  (reverse lst)
  )
 
  ;;________________________________________________;;
 
  (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
                      (0 . "POLYLINE")(-4 . "OR>"))))
  (if sset
    (progn
      (setq itm 0 num (sslength sset))
      (setq fn (getfiled "Point Export File" "" "txt" 1))
      (if (/= fn nil)
        (progn
          (setq fh (open fn "w"))
          (while (< itm num)
            (setq hnd (ssname sset itm))
            (setq ent (entget hnd))
            (setq obj (cdr (assoc 0 ent)))
            (cond
              ((eq obj "POINT")
                (setq pnt (cdr (assoc 10 ent)))
                (setq pnt (trans pnt 0 1));;**CAB
                (write-line (strcat (rtos (car pnt) 2 3) ","
                               (rtos (cadr pnt) 2 3) ","
                               (rtos (caddr pnt) 2 3)) fh)

              )
              ((= obj "POLYLINE")
       (setq v hnd)
       (setq vexx (3dpoly-verts v ))
       (foreach pnt vexx
(write-line (strcat (rtos (car pnt) 2 3) ","
                    (rtos (cadr pnt) 2 3) ","
                    (rtos (cadr pnt) 2 3)) fh)

)        
)
 
 
              (t nil)
            )
            (setq itm (1+ itm))
          )
          (close fh)
        )
      )
    )
  )
  (princ)
)

(princ "\n\t---\tType TW to write coordinates\t---")
(princ)

pedroantonio

  • Guest
Re: 3d polyline export to *.txt
« Reply #10 on: May 01, 2014, 02:18:30 AM »
Hi fixo, Thank you for the code .I make this change to your code and work fine

Code - Auto/Visual Lisp: [Select]
  1.               ((= obj "POLYLINE")
  2.                (setq v hnd)
  3.                (setq vexx (3dpoly-verts v ))
  4.                (foreach pnt vexx
  5.                 (write-line (strcat (rtos (car pnt) 2 3) ","
  6.                                (rtos (cadr pnt) 2 3) ","
  7.                                (rtos (caddr pnt) 2 3)) fh)
  8.  
  9.  
  10.         )              
  11. )
  12.  

fixo

  • Guest
Re: 3d polyline export to *.txt
« Reply #11 on: May 01, 2014, 03:05:53 AM »
Glad, you've sorted this out
Cheers  :-)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: 3d polyline export to *.txt
« Reply #12 on: May 01, 2014, 11:58:57 AM »
I'm talking to myself again  ::)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: 3d polyline export to *.txt
« Reply #13 on: May 01, 2014, 12:33:46 PM »
I forget to thank you ronjonp.Thank you for your help  :lmao:

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: 3d polyline export to *.txt
« Reply #14 on: May 02, 2014, 06:43:28 AM »
You figure it out ?

Not possible, for all the post he is not learning much, just trying to cob together some surveying functions so he does not have to buy a canned program....