Jump to content

Recommended Posts

Posted

I have probleme with use of set function

error: Argument type incorrect: symbolp (NTH COUNT LIST_VARIABLES)

Any help please?

 

(defun c:sectionPOTEAU ()
  
  ;; Import variables form file
  (setq name_file (getfiled "Select txt file..." "D:\\" "txt" 4)
        read_file (open name_file "r")
        
        pot_larg pot_haut pot_enrob pot_HA14 pot_longCoude pot_raduisCoude pot_enrob_HA07 pot_LWPOLY_WIDTH ;;declare variables

        list_variables '(pot_larg pot_haut pot_enrob pot_HA14 pot_longCoude pot_raduisCoude pot_enrob_HA07 pot_LWPOLY_WIDTH)
  )
    
  (if read_file 
    (progn 
      (setq count 0)
      (while (setq text_line (atof (read-line read_file))) ;;read line & convert text to float
        (set '(nth count list_variables) text_line) ;; set variable value
        (setq count (1+ count))
      ) ;;while
    ) ;;progn
  ) ;;if
  
  (close read_file)
)

 

Posted (edited)

The issue here is that the nth expression is quoted and is therefore unevaluated before being passed to the set function; set requires a symbol argument as the first argument and therefore cannot assign the value value to a list. You will also run into problems when reaching the end of the file, as read-line will return nil and (atof nil) will return an error.

 

The line at which you 'declare variables' is also incorrect and only syntactically correct because you have an even number of variables; this line is essentially assigning the value of every other variable to every other symbol.

Edited by Lee Mac
Posted

I might suggest something like the following (untested);

(defun c:sectionPOTEAU ( / des fnm lst str )
    (cond
        (   (not (setq fnm (getfiled "Select Text File" "D:\\" "txt" 16))))
        (   (not (setq des (open fnm "r")))
            (princ "\nUnable to open file.")
        )
        (   t
            (setq lst '(pot_larg pot_haut pot_enrob pot_HA14 pot_longCoude pot_raduisCoude pot_enrob_HA07 pot_LWPOLY_WIDTH))
            (while
                (and
                    (setq sym (car lst))
                    (setq str (read-line des))
                )
                (set sym (atof str))
                (setq lst (cdr lst))
            )
            (close des)
        )
    )
    (princ)
)

 

Though, you'll want to ensure that the symbols in the list are declared local elsewhere in your application else they will reside in the document namespace and hence could clash/be overwritten by other applications.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...