LISP ROUTINE ISSUE COMING OVER FROM AUTOCAD

So we're switching over to Brics from AutoCAD and I've hit a snag with one of our LISP routines:

**(defun c:prov (/ f DATAFILE ANG X Y Z PH SIZE UTL SERV_RL TD SIZEA SURV_RL COORD NOTE)
(setq ceho (getvar "CMDECHO"))
(setvar "CMDECHO" 1)
(setq blm (getvar "blipmode"))
(setvar "blipmode" 0)
(setq atd (getvar "attdia"))
(setvar "attdia" 0)
(setq OSM (getvar "osmode"))
(setq cl (getvar "clayer"))
(setvar "clayer" "ELS_POTHOLE")
(setq snco (getvar "OSNAPCOORD"))
(setvar "OSNAPCOORD" 1)

;(command "_.ucs" "w")

(setq datafile (getfiled "Select a CSV File" (getvar "dwgprefix") "csv" 8))
(setq datafile (strcat (getvar "dwgprefix") "/" datafile))
(setq f (open datafile "r"))
(setq dataline (read-line f))
(setq ang (angtos (getangle "\npick 2 points for text angle")))
(setvar "osmode" 0)

(while (/= dataline nil)
(setq dataline (str2lst dataline))
(setq x (nth 0 dataline))
(setq y (nth 1 dataline))
(setq z (nth 2 dataline))
(setq PH (nth 3 dataline))
(setq size (nth 4 dataline))
(setq utl (nth 5 dataline))
(setq serv_rl (nth 6 dataline))
(setq td (nth 7 dataline))
(setq coord (strcat x "," y "," z))
;(if (equal note "")
(setq note "-")
(command "-insert" "PH" coord "1" "1" ang PH size utl z serv_rl td note) ;the "1" "1" is the x and y scale for the block insertion this can be changed as per the dwg scale. 1 is for 1:250 ;
(setq dataline (read-line f))
)

(close f)
(setvar "attdia" atd)
(setvar "blipmode" blm)
(setvar "osmode" osm)
(setvar "CMDECHO" ceho)
(setvar "clayer" cl)
(setvar "OSNAPCOORD" snco)
(princ)
)

(defun str2lst (strg / tl pos)
(setq tl (list))
(while (setq pos (vl-string-search "," strg))
(setq tl (cons (substr strg 1 pos) tl)
strg (substr strg (+ 2 pos))
)
)
(reverse (cons strg tl))
)

(princ)**

when I run this in Brics I keep getting :

**## ; error : bad argument type ; expected FILE at [read-line] **

It still works fine in AutoCAD but BricsCAD won't go and get the csv to start reading in the data. Anyone got any ideas?

Comments

  • Jason Bourhill
    edited September 2019

    I think the issue is cause here

        (setq datafile (getfiled "Select a CSV File" (getvar "dwgprefix") "csv" 8))
        (setq datafile (strcat (getvar "dwgprefix") "/" datafile))
    

    In the first line getfiled is used to ask the user to select the file. Bit code 8 is supposed to return just the file name if the selected file is on the support file search path. It looks like BricsCAD is ignoring this and always returning the full path with the filename. This causes problems in the second line as it will create an invalid file path.

    Workaround would be to incorporate acet-filename-path-remove to force stripping of the path

    (acet-filename-path-remove (setq linfile (getfiled "Select a CSV File" (getvar "dwgprefix") "csv" 8)))

    This code change would still work in AutoCAD.

    I do think the logic is somewhat flawed as it prevents the user from selecting a file from any folder other than the current drawing, but doesn't check whether this file actually exists before attempting to open, hence your error. I would suggest you add a check e.g.

    (cond 
       ((findfile datafile); File exists!, can proceed to open ...
       .
       .
       )
      (T (Princ (strcat "Data file: " datafile " not found")))
    )
    

    When working with files I would also recommend using an error handler.

    Regards,
    Jason Bourhill
    BricsCAD V19 Ultimate
    Quickly create HELP links on your forum posts

    CAD Concepts

  • Works for me, I get the prompt to select the .cvs

    Does it fail after selecting the excel doc?

  • db - Yes, it runs right up to that point then stops.

    JB - I'll give that solution a crack this morning.

  • JB - T4T worked a treat, just had to change out "lin" for "csv", there was another issue I encountered at:

    **
    (command "-insert" "PH" coord "1" "1" ang PH size utl z serv_rl td note)
    **

    The block I'm using from our AutoCAD templates are dynamic blocks and the "1" "1" scales the block x and y, This lead to the insertion and auto-populate doing weird things, I simply changed it to "1" and everything was fine. Is there other issues I should be thinking about with this kind of thing? I'm working my way through the voluminous manuals but any heads ups would be appreciated.

  • Jason Bourhill
    edited September 2019

    @Colin_Digmore said:
    JB - T4T worked a treat, just had to change out "lin" for "csv", there was another issue I encountered at:

    Whoops, was testing using a filetype that I knew would be on the support file search path. I've corrected my previous post to csv.

    The block I'm using from our AutoCAD templates are dynamic blocks and the "1" "1" scales the block x and y, This lead to the insertion and auto-populate doing weird things, I simply changed it to "1" and everything was fine. Is there other issues I should be thinking about with this kind of thing? I'm working my way through the voluminous manuals but any heads ups would be appreciated.

    Hard to say without seeing the files. BricsCAD can use Dynamic Blocks, but you can't edit them. You could try using the Scale option with -INSERT, this assumes equal scaling for all axis.

    (command "._-insert" "PH" "_Scale" 1.0 coord ang PH size utl z serv_rl td note)

    BricsCAD LISP has additional tools that you can use. See the Lisp Developer Support Package (LDSP) for details. For example, BricsCAD LISP has a function "vle-file->list" which imports a given file and converts it to a list.

    Regards,
    Jason Bourhill
    BricsCAD V19 Ultimate
    Quickly create HELP links on your forum posts

    CAD Concepts