Error: malformed list on input

Error: malformed list on input

paulo.barreraF8J36
Explorer Explorer
3,592 Views
23 Replies
Message 1 of 24

Error: malformed list on input

paulo.barreraF8J36
Explorer
Explorer

Hello Everyone,

 

I am currently trying to create a .lisp program that automates the editing of attributes in a dynamic block. I have written the code and uploaded it to AutoCAD but am getting the error : malformed list on input. This shows up above the command line after I load it in the load/unload applications tab.

 

The code works by taking a csv file and separating the entries by columns. The csv file has 5 columns: Block, ID, ID_value, Attribute, Attribute_Value. 

 

This is my first time working on AutoLISP so really anything could be wrong.

 

Thank you so much for your time and help.

 

Here is my code, I will also upload the file below:

 

(defun c:replaceAttributes (filePath)
(if (setq fp (open filePath "r"))
(progn
(while (setq line (read-line fp))
(if (> (length line) 0)
(progn
(setq values (mapcar 'atoi (strsplit line ",")))
(setq blockName (nth 0 values))
(setq attribName (nth 1 values))
(setq newValue (nth 2 values))
(if (setq b (ssget (list (cons 0 "INSERT") (cons 2 blockName))))
(progn
(foreach b (entget b)
(if (and (equal (cdr (assoc 2 b)) blockName) (equal (cdr (assoc 70 b)) 1))
(progn
(if (setq a (ssget (list (cons 0 "ATTRIB") (cons 8 b) (list (cons 2 attribName)))))
(progn
(setq attribs (entget a))
(if (setq index (assoc 2 attribName attribs))
(progn
(setq newAttribs (subst (cons 2 newValue) index attribs))
(entmod newAttribs)
)
)
)
)
)
)
)
)
)
)
)
(close fp)
(alert "Attributes replaced.")
)
(alert (strcat "File " filePath " not found."))
)
)

0 Likes
Accepted solutions (1)
3,593 Views
23 Replies
Replies (23)
Message 21 of 24

pbejse
Mentor
Mentor
Accepted solution

 

(defun c:replaceAttributes ( / strsplit filePath fp line Alldata blockObjects index en bn attValues)
(defun strsplit ( str d_ / p)
  	(if (setq p (vl-string-position (Ascii d_) str))
	  	(cons (substr str 1 p) (strsplit (substr str (+ 2 p)) d_))
  		(list str)
  		)
  )
(if (and
      (setq filePath (getfiled "Select Attribute Data CSV file" (getvar 'dwgprefix) "csv" 16))
      (setq blockObjects (ssget  '((0 . "INSERT")(66 . 1)(410 . "Model"))))
      )
	(progn
      		(setq fp (open filePath "r"))
		  (while (setq line (read-line fp))
		     (and
			(> (strlen line) 0)
			(setq data (strsplit line ","))
			(setq Alldata (cons data Alldata)))
		)
    		(close fp)
	  	(and
		  Alldata
		(repeat (setq index (sslength blockObjects))
		  (setq en (ssname blockObjects (setq index (1- index))))		  
		  (setq bn (getpropertyvalue en "BlockTableRecord/Name"))
		    (and
		      (assoc (strcase bn) Alldata)
		    (setq attValues
			   ((lambda ( e / entData en lst)
				   (while (and (setq e (entnext e))
					       (= "ATTRIB" (cdr (assoc 0 (setq entData (entget e))))))
				        (setq lst
				            (cons (list (cdr (assoc 2 entData))
							(cdr (assoc 1 (reverse entData)))) lst
					            		)
					        	)
		    				) lst
		    			)  en
			        ) 
			  )
			(vl-some '(lambda (v / F)
				    (cond
				      ((and (eq (strcase (car v)) bn)
					    (setq f (assoc (cadr v) attValues))
						(eq (cadr f) (caddr v))
					    	(setq f (assoc (cadddr v) attValues)))
				       (setpropertyvalue en (cadddr v) (last v))
				       (setq Alldata (vl-remove v Alldata))
				       )))
				 Alldata
				 )		      
		    )
		  )
		  )
	  );progn
  	);if
  (princ)
  )

HTH

 

BTW, Will there be duplicate values of SENSOR_ID values on the blocks?

0 Likes
Message 22 of 24

paulo.barreraF8J36
Explorer
Explorer

No all the sensor ID values are different based on the plan! The value will be some abbreviated version of the company, floor number then 1-however many sensors there are. Ex. TIAA-NY-F06-001 where the 001 will range from 001 to however many sensors there are, ex, 001 - 036

0 Likes
Message 23 of 24

paulo.barreraF8J36
Explorer
Explorer

This worked perfectly! I selected all the blocks I needed then ran the command, found the file and it uploaded all of the serial numbers! Thank you so much for your help!

0 Likes
Message 24 of 24

pbejse
Mentor
Mentor

@paulo.barreraF8J36 wrote:

This worked perfectly! I selected all the blocks I needed then ran the command, found the file and it uploaded all of the serial numbers! Thank you so much for your help!


Glad to hear the code works for you and we hope you will from it.

You are very welcome @paulo.barreraF8J36 

 

Cheers

 

0 Likes