CADdet Posted January 5, 2011 Posted January 5, 2011 When retrieving information from a drawing into lisp I am given one of five didgets each represents a material. 1 for lead 2 = zinc 3 = ceramic 4 = concrete 5 = synthetic The values are stored in a variable, which is written to excel. Rather then have an excel file work things out how can I reference/ index the numbers with there corresponding material using lisp? So rather then have an excel with: 1 1 2 1 3 1 4 2 I have an excel file with: Lead Lead Zinc Lead Ceramic Lead Concrete Zinc Quote
David Bethel Posted January 5, 2011 Posted January 5, 2011 Associative lists are really good for this type of data (setq matdata '( ("LEAD" . 1) ("ZINC" . 2) ("CERAMIC" . 3) ("CONCRETE" . 4) ("SYNTHETIC" . 5) )) and then: (cdr (assoc value matdata)) They are case sensitive however. Or it could be reversed depending on your needs. -David Quote
BlackBox Posted January 5, 2011 Posted January 5, 2011 Use a cond statement prior to writing the value to the excel file. Example: ;; Get variable value (setq var 1) ;; Interpret value prior to write (cond ((= 1 var) (setq var "Lead")) ((= 2 var) (setq var "Zinc")) ((= 3 var) (setq var "Ceramic")) ((= 4 var) (setq var "Concrete")) ;; ...etc. ) ;; Write variable to excel Quote
BlackBox Posted January 5, 2011 Posted January 5, 2011 Associative lists are really good for this type of data (setq matdata '( ("LEAD" . 1) ("ZINC" . 2) ("CERAMIC" . 3) ("CONCRETE" . 4) ("SYNTHETIC" . 5) )) and then: (cdr (assoc value matdata)) They are case sensitive however. Or it could be reversed depending on your needs. -David Perhaps this format would be preferable? (setq matdata '((1 . "LEAD") (2 . "ZINC") (3 . "CERAMIC") (4 . "CONCRETE") (5 . "SYNTHETIC") )) Quote
David Bethel Posted January 5, 2011 Posted January 5, 2011 Perhaps this format would be preferable? I couldn't tell from the OP which way they needed the data..... Quote
Recommended Posts
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.