See the top rated post in this thread. Click here

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: export line coordinates

  1. #11
    Member
    Join Date
    2016-11
    Posts
    9
    Login to Give a bone
    0

    Default Re: export line coordinates

    [QUOTE=Lee Mac;1152430]After a quick look at your program, I notice that you are only incrementing the variable i if the entity encountered is a LINE entity.

    Since you haven't used a filter list with the ssget selection, there is a good chance that the user could inadvertently select an object which is not a line.

    In this case, the if statements within your repeat loop would not evaluate to T, and so the counter variable i would never be incremented.

    Hence, in the next iteration of the repeat loop, the same entity is processed (since i has not been incremented), and again i will not be incremented, and so on and so forth.

    Meanwhile, the program is still writing the values of variables c and cbert to the file, and, since the values of these variables have not been altered since the previous iteration, the same values are written over and over - that is, if a LINE has been encountered first, since otherwise these variables would be nil and you would receive an error from supplying a null value to the rtos function.

    Here is an alternative approach for you to study, I have included comments to help you see what the code is doing at each stage:




    Lee,

    I really appreciate you taking the time write out what each section of code is accomplishing. Between your post, and this COVID-19 quarantine I might finally try learning LISP. First, do you have any online courses or resources that would be a good starting point? Any specific AU classes that come to mind?

    Second, after looking at the code I started with from DOTSOFT (posted below), I can't figure out how to alter the output for when multiple polylines are selected. The output for multiple polylines needs to have each polylines x,y coordinates proceeded by an integer represent the selected object number or counter.

    For example

    1, 34567.98, 32467.97
    1, 21252.43, 98742.987
    1, 98876.12, 19813.78
    2, 65423.45, 68763.98
    2, 48786.45, 87546.78
    2, 42538.68, 74583.25

    Also, it would be nice to be able to check an ensure the polyline is closed. What i struggle with the most is the vocabulary of code. Which I imagine is a fairly common issue amongst those just starting to code.


    Code:
    (defun c:ocz ()
      (setq sset (ssget '((-4 . "<OR")(0 . "POINT")
                          (0 . "LWPOLYLINE")(-4 . "OR>"))))
      (if sset
        (progn
          (setq itm 0 num (sslength sset))
         ; (if (itm /= 1)
          (setq fn (getfiled "Save OCZ Boundary 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
                  ((= obj "POINT")
                    (setq pnt (cdr (assoc 10 ent)))
                    (setq pnt (trans pnt 0 1));;**CAB
                    (princ (strcat (rtos (car pnt) 2 8) ", "
                                   (rtos (cadr pnt) 2 8)) fh)
                                 ;  (rtos (caddr pnt) 2 8)) fh)
                    (princ "\n" fh)
                  )
                  ((= obj "LWPOLYLINE")
                   (if (= (cdr (assoc 38 ent)) nil)
                      (setq elv 0.0)
                     (setq elv (cdr (assoc 38 ent)))
                    )
                    (foreach rec ent
                      (if (= (car rec) 10)
                        (progn
                          (setq pnt (cdr rec))
                          (setq pnt (trans pnt 0 1));;**CAB
                          (princ (strcat (rtos (car pnt) 2 8) ", "
                                         (rtos (cadr pnt) 2 8)) fh)
                                        ; (rtos elv 2 8)) fh)
                          (princ "\n" fh)
                        )
                      )
                    )
                  )
                  (t nil)
                )
                (setq itm (1+ itm))
              )
              (close fh)
    	  (princ (strcat "\nThe Coordinates of" (itm num) "have been written to the file."))
            )
          )
        )
      )
      (princ)
    )
    
    (princ "\nPoint Export loaded, type PTEXPORT to run.")
    (prince)

  2. #12
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    1

    Default Re: export line coordinates

    Please clear you task to do . and upload your sample dwg where to apply this lisp

  3. #13
    Member
    Join Date
    2016-11
    Posts
    9
    Login to Give a bone
    0

    Default Re: export line coordinates

    Attached is a dwg drawing with two simple closed polylines.

    The ocz.lsp routine currently produces the correct results on a single polyline. See Single selection.txt

    However, when I select two polylines I need the output to look exactly like the results in 'multiple selection.txt' file (which I created manually).
    Attached Files Attached Files

  4. #14
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    1

    Default Re: export line coordinates

    Try it

    ; ----------------------------------------------------------------------
    ; (Export LWPOLYLINE Vertices & Points to File)
    ; Copyright (C) 2000 DotSoft, All Rights Reserved
    ; Website: http://www.dotsoft.com
    ; ----------------------------------------------------------------------
    ; DISCLAIMER: DotSoft Disclaims any and all liability for any damages
    ; arising out of the use or operation, or inability to use the software.
    ; FURTHERMORE, User agrees to hold DotSoft harmless from such claims.
    ; DotSoft makes no warranty, either expressed or implied, as to the
    ; fitness of this product for a particular purpose. All materials are
    ; to be considered ‘as-is’, and use of this software should be
    ; considered as AT YOUR OWN RISK.
    ; ----------------------------------------------------------------------
    ;;Revised 8/23/07 CAB to report coordinates in current UCS
    ;;Revised 04/15/20 JLM to remove z coordinate and change output format to comma space
    ;; revised 20-04-2020 by DEVITG@gmail.com to add enty order number

    (DEFUN C:OCZ+NBR (/
    ;;ELV ENT FH FN HND ITM NUM OBJ PNT SSET
    ;; keep above comment up to you get it good
    ;; strip both [;;]
    )
    (SETQ SSET (SSGET '((-4 . "<OR")
    (0 . "POINT")
    (0 . "LWPOLYLINE")
    (-4 . "OR>"))))
    (IF SSET
    (PROGN
    (SETQ ITM 0)
    (SETQ NUM (SSLENGTH SSET))

    ; (if (itm /= 1)
    (SETQ FN (GETFILED "Save OCZ Boundary 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
    ((= OBJ "POINT")
    (SETQ PNT (CDR (ASSOC 10 ENT)))
    (SETQ PNT (TRANS PNT 0 1))
    ;;**CAB
    (PRINC (STRCAT (ITOA (1+ ITM))
    ;; by DEVITG
    ", "
    (RTOS (CAR PNT) 2 8)
    ", "
    (RTOS (CADR PNT) 2 8))
    FH)
    ; (rtos (caddr pnt) 2 8)) fh)
    (PRINC "\n" FH)
    )
    ((= OBJ "LWPOLYLINE")
    (IF (= (CDR (ASSOC 38 ENT)) NIL)
    (SETQ ELV 0.0)
    (SETQ ELV (CDR (ASSOC 38 ENT)))
    )
    (FOREACH REC ENT
    (IF (= (CAR REC) 10)
    (PROGN
    (SETQ PNT (CDR REC))
    (SETQ PNT (TRANS PNT 0 1))
    ;;**CAB
    (PRINC (STRCAT (ITOA (1+ ITM))
    ;; by devitg
    ", "
    (RTOS (CAR PNT) 2 8)
    ", "
    (RTOS (CADR PNT) 2 8))
    FH)
    ; (rtos elv 2 8)) fh)
    (PRINC "\n" FH)
    )
    )
    )
    )
    (T NIL)
    )
    (SETQ ITM (1+ ITM))
    )
    (CLOSE FH)
    (PRINC
    (STRCAT "\nThe Coordinates of " (ITOA ITM) " " (ITOA NUM) " have been written to the file."))
    )
    )
    )
    )
    (PRINC)
    (STARTAPP "notepad" FN)
    ;; by devitg
    )



    (PRINC "\nPoint Export loaded, type OCZ+NBR to run.")

    (PRINC)
    ;|«Visual LISP© Format Options»
    (180 2 1 0 nil "end of " 100 20 2 2 nil nil T nil T)
    ;*** DO NOT add text below the comment! ***|;
    as ask.

    1, 10.61472348, 23.10803958
    1, 39.20571947, 57.61431106
    1, 66.52913434, 38.88233509
    1, 78.85283969, 20.43204301
    1, 84.27526984, 3.88311683
    1, 58.43069964, -2.52519069
    1, 46.10699429, 6.55911340
    2, 86.52187778, 55.79493122
    2, 114.11757501, 9.38924420
    2, 150.04829930, 21.10330101
    2, 120.08725659, 74.37973325
    2, 103.98038009, 70.09959702
    The lisp will open the TXT at NOTEPAD


    and please , next time check it.
    Attached Images Attached Images
    Attached Files Attached Files

  5. #15
    Member
    Join Date
    2016-11
    Posts
    9
    Login to Give a bone
    0

    Default Re: export line coordinates

    This is extremely close! I love that it opens notepad too! It was not fun having to navigate to the .txt file. Thank you!

    The only change that needs to be made is that when one polyline is selected the output needs to not include the item number.

    Code:
    10.61472348, 23.10803958
    39.20571947, 57.61431106
    66.52913434, 38.88233509
    78.85283969, 20.43204301
    84.27526984, 3.88311683
    58.43069964, -2.52519069
    46.10699429, 6.55911340
    I greatly appreciate your help with this! I appreciate you adding comments of where you changed or added code. That helps me understand what is going on better!

  6. #16
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    1

    Default Re: export line coordinates

    Find attached
    Attached Files Attached Files

  7. #17
    Member
    Join Date
    2016-11
    Posts
    9
    Login to Give a bone
    0

    Default Re: export line coordinates

    That is a thing of beauty!

    This works perfectly! Now I'm going to spend some time trying to fully understand what you are doing to accomplish this!

    Thanks so much!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Export coordinates to Excel
    By rputhenv in forum AutoCAD General
    Replies: 5
    Last Post: 2016-10-14, 02:09 PM
  2. 2013: How do I export to IFC with project coordinates and not real world coordinates?
    By m.knutsson in forum Revit Architecture - General
    Replies: 2
    Last Post: 2013-10-15, 06:54 AM
  3. 2013: Export coordinates from a corridor
    By xtcgr in forum AutoCAD Civil 3D - Corridors
    Replies: 2
    Last Post: 2013-02-27, 04:50 PM
  4. Export Coordinates
    By Maastricht in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2009-08-19, 04:45 PM
  5. Replies: 1
    Last Post: 2007-05-29, 10:37 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •