1

So I asked a similar question here about a month ago (Lisp - Extracting info from a list of comma separated values) and managed to put something together that almost meets my needs, but I am hitting a roadblock with a few things. I'll start with the code:

(defun c:poleid ( / fn fp lst l)
;; String to list convertor. This will separate coordinates and values by comma and store them in a variable as a list
    (defun LM:str->lst ( str del / len lst pos )
        (setq len (1+ (strlen del)))
        (while (setq pos (vl-string-search del str))
            (setq lst (cons (substr str 1 pos) lst)
                str (substr str (+ pos len))
            )
        )
        (reverse (cons str lst))
    )
    ;; Prompt the user to select a .TXT file.
    (setq fn (getfiled "Select UTM GPS file" "" "txt" 4))

    ;; Open the file and create an empty list
    (setq fp (open fn "r") lst '())

    ;; Iterate the file, writing each line to the list (as a string)
    (while (setq l (read-line fp))
        (setq lst (cons l lst))
    )
    ;; Close the file.
    (close fp)

    ;; Reverse the list
    (setq lst (reverse lst))

    ;; At this point, the data is stored in a variable (lst) and the file is closed.

    ;; Save current OSNAP MODE and turn off
    (setq os (getvar 'osmode))
    (setvar "osmode" 0)
    
    ;;Set pcount to 0
    (setq pcount 0)
    ;; Iterate the list and draw a point
    ;; entity at each coordinate
    (foreach item lst ;; For each line in lst
        (setq items (LM:str->lst item ",")) ;;set variable items as a list of item, separated by commas. Set the las
        (setq ptx (nth 2 items) pty (nth 1 items) ptz (nth 3 items) idn (nth 4 items)) ;; Set the pole (pt) x, y and z values from the 2nd, 3rd and 4th values of each line. Set notes to idn (as a string). UTM values are provided to this program as y,x,z
        (setq idr (LM:str->lst idn " ") idn (nth 0 idr) idr (nth 1 idr)) ;;Set idr (Pole ID) as a list of idn, then set idn as the first half of the note (HP#) and idr as the second half
        (cond ((wcmatch idn "HP") ;; Only process lines that have HP in the 5th value
            (
                (printc idn)
                (setq ptxyz (strcat ptx "," pty "," ptz)) ;;Make the pole x, y, and z value into a single string, separated by commas
                (setq idx (atof ptx) idx (- idx 5.0) idx (rtos idx)) ;;set the idx as real number version of ptx, subtract 5 from it, then convert back to a string
                (setq idxyz (strcat idx "," pty "," ptz)) ;;Make the ID x, y, and z value into a single string, separated by commas
        
                ;;Insert pole and ID block at xyz coords, with idn as the HP number and idr as the pole ID
                (command "insert" "G:\\Shared drives\\Project Tools\\Customized Tools\\CAD\\prog\\CWood_Pole_D.dwg" ptxyz "508" "508" "0") ;; Pole symbol set to an x/y scale of 20
                (command "insert" "G:\\Shared drives\\Project Tools\\Customized Tools\\CAD\\prog\\POLENA.dwg" idxyz "25.4" "25.4" "0" idn idr) ;; Pole ID block set to an x/y scale of 1, with the top half showing the HP# and the bottom half showing the pole ID
                (setq pcount (+ pcount 1)) ;;Add 1 to counter
            ))
        )
    )
    ;; Restore OSNAP MODE and close with count of poles inserted
    (setvar 'osmode os)
    (setq pcount (write-to-string pcount))
    (princ pcount)
    (princ " pole(s) have been successively added")
    (princ)
)

This is fed a .txt file that contains GPS points. The test example I have been feeding the script is:

1000,1,2,3,HP
1001,10.000,2.000,3.000,HP21 blah
1002,15.000,2.000,3.000,HP22 2gt3
1003,20.000,2.000,3.000,CU

#,Easting,Northing,Elevation,Notes

What I want the code to do is insert a block (CWood_Pole_D.dwg) in at the Easting/Northing/Elevation, and then insert a second block (POLENA.dwg) 5 units to the left of that point. The second block contains two attributes, which I would like to pull from the notes (with the two attributes separated by a space). All of this should only happen when the notes begin with "HP" (which may be followed bynumbers and a letter, ex. HP22A). The last little bit just counts up each time a pair of blocks is successfully added, but even that is spitting out a .

The problem I am having is dealing with the notes part, and conversely the loop activating when the notes are anything but JUST "HP". I'm also sure there is a bunch of redundancy or useless code, but boy oh boy is it difficult to find good information that breaks down all the individual actions (like, what is happening with the Lee Mac string to list convertor?)

Fizscy
  • 41
  • 3

1 Answers1

1

I think the match does not work:

(wcmatch idn "HP")

You can try this instead, you may need a wildcard to match e.g. "HP22":

(wcmatch idn "HP*")

The rest is fine, I'd encourage to split your setq into distinct lines for readability.

coredump
  • 37,664
  • 5
  • 43
  • 77