mjab8 Posted April 25, 2016 Posted April 25, 2016 Hi, I am new in lisp and this is my first dcl. In this lisp I hope to make attribute entry more convenient using a DCL popup_list to select my range of attributes. I wish to enter the Brand from the popup list and it will automatically fill in the Code as per the brand.dat file. Attached brand.lsp is my un-complete lisp which I am lost in it. My DCL is fine. My .dat is as follow: **CODE & BRANDS **CODE, BRANDS **---------------- *1006 - COUNTRY ROAD WOMENS 1006, COUNTRY ROAD WOMENS *1014 - SPORTCRAFT 1014,SPORTCRAFT *1022 - DAVID LAWRENCE 1022,DAVID LAWRENCE Area_Attrib_M.dwg is my attribute block. I hope someone can help. Thanks in advance. brand.dcl brand.lsp AREA_ATTRIB_M.dwg Quote
Tharwat Posted April 25, 2016 Posted April 25, 2016 Welcome to CADTutor. Upload a sample of your brand.dat file, try this primary program at the moment. New modified DCL codes: br : dialog { label = "Enhanced Attribute Input"; width = 42; : popup_list { label = "Code "; key = "sel-code"; value = 3; allow_accept = true; } : popup_list { label = "Brand"; key = "sel-brand"; value = 3; allow_accept = true; } spacer_1; ok_cancel; } AutoLISP codes: (defun C:BRAND (/ names dcl_id lst cd br it bk pt) (setq names '("1006 - COUNTRY ROAD WOMENS" "1014 - SPORTCRAFT" "1022 - DAVID LAWRENCE" "2109 - FRAGRANCE TRI" "2117 - FRAGRANCE L'OR" "2133 - BURBERRY BEAUTY" ) ) (if (and (< 0 (setq dcl_id (load_dialog "brand.dcl"))) (new_dialog "br" dcl_id) ) (progn (setq lst (mapcar '(lambda (x) (cons (substr x 1 4) (substr x )) names ) cd (mapcar 'car lst) br (mapcar 'cdr lst) ) (mapcar '(lambda (k v) (start_list k) (mapcar 'add_list v) (end_list) ) '("sel-code" "sel-brand") (list cd br) ) (action_tile "cancel" "(done_dialog)") (action_tile "accept" "(setq it (mapcar 'atoi (list (get_tile \"sel-code\") (get_tile \"sel-brand\")))) (done_dialog)" ) (start_dialog) (unload_dialog dcl_id) (if (and (apply 'and it) (if (not (or (tblsearch "BLOCK" (setq bk "AREA_ATTRIB_M")) (setq bk (findfile "C:/TEST/AREA_ATTRIB_M.dwg")) ) ) (progn (princ "\nBlock is not found in drawing nor in C:TEST path !" ) nil ) t ) (setq pt (getpoint "\nPick Attribute insertion point: ")) ) (command "_.-insert" bk "_non" pt "1" "1" "0." (nth (car it) cd) (nth (cadr it) br) "" "" ) ) ) ) (princ) ) Quote
mjab8 Posted April 26, 2016 Author Posted April 26, 2016 Hi Tharwat, Thanks for the quick reply. I fixed the dcl (attched) and it's now good. The lisp is not ready yet. It's getting the error not finding the block eventhough the path ot it is correct. The second line, ie. (setq names....). Do I need ot define this as there are about 150 of them. I hoping to getting the brand and code from .dat instead. At the moment it's not reading the .dat and inserting the attribute block. Attached is the .dat (short list) which I have to rename to .txt in order to attached in here. Thanks again. brand.txt brand.dcl Quote
Tharwat Posted April 26, 2016 Posted April 26, 2016 Few points for you to consider: The changes you have made on my modification of your first dcl file is incorrect in your case, because you need to have a space between attribute tiles vertically and not horizontally. The program DOES find the block via the path so check again the location of your block. The contents of XXX.dat file must be ordered correctly because in your file some lines have asterisks and some don't and some have commas after the code column and some have dashes instead, so there must be a logic form to allow the function to choose how to isolate the each line of the file into two popup lists. Quote
mjab8 Posted April 26, 2016 Author Posted April 26, 2016 The block location is fixed! When defining the path, we need to include the .dwg, ie. (findfile "H:/Temp/AREA.DWG"). * I hope we can do with the second line, (setq names...) as we have 150 in the full list. Attached is my update .dat(txt) and I decided not to have spaces in between. * If I select a brand, I hope it will auto-fill the code, vice versa since it's retrieving from the .dat. Thanks again for the help. * We probably don't need the default Enter Attribute dialog which we still getting. Hope that the custom dialog is sufficient to fill these two attributes. brand.txt Quote
mjab8 Posted April 27, 2016 Author Posted April 27, 2016 Can someone help out please? This lisp is to make attribute input simpler with the help of a dcl popup_list and reading from the .dat. Currently is not reading the .dat. Please see previous post issues not resolved. Thanks (defun C:BRAND (/ names dcl_id lst cd br it bk pt) (setq names '("1006 - COUNTRY ROAD WOMENS" "1014 - SPORTCRAFT" "1022 - DAVID LAWRENCE" "2109 - FRAGRANCE TRI" "2117 - FRAGRANCE L'OR" "2133 - BURBERRY BEAUTY" ) ) (if (and (< 0 (setq dcl_id (load_dialog "brand.dcl"))) (new_dialog "br" dcl_id) ) (progn (setq lst (mapcar '(lambda (x) (cons (substr x 1 4) (substr x )) names ) cd (mapcar 'car lst) br (mapcar 'cdr lst) ) (mapcar '(lambda (k v) (start_list k) (mapcar 'add_list v) (end_list) ) '("sel-code" "sel-brand") (list cd br) ) (action_tile "cancel" "(done_dialog)") (action_tile "accept" "(setq it (mapcar 'atoi (list (get_tile \"sel-code\") (get_tile \"sel-brand\")))) (done_dialog)" ) (start_dialog) (unload_dialog dcl_id) (if (and (apply 'and it) (setq pt (getpoint "\nPick Attribute insertion point: ")) (if (not (or (tblsearch "BLOCK" (setq bk "AREA_ATTRIB_M")) (setq bk (findfile "H:/DCL test/AREA_ATTRIB_M")) ) ) (progn (princ "\nBlock not found drawing or at H:DCL test folder !" ) nil ) t ) ) (command "_.-insert" bk "_non" pt "1" "1" "0." (nth (car it) cd) (nth (cadr it) br) "" "" ) ) ) ) (princ) ) The DCL: br : dialog { label = "Enhanced Attribute Input"; width = 42; : popup_list { label = "Code "; key = "sel-code"; value = 3; allow_accept = true; } : popup_list { label = "Brand"; key = "sel-brand"; value = 3; allow_accept = true; } : spacer { width = 1; } ok_cancel; } The .DAT **CODE & BRANDS **CODE, BRANDS **---------------- *1006-COUNTRY ROAD WOMENS 1006,COUNTRY ROAD WOMENS *1014-SPORTCRAFT 1014,SPORTCRAFT *1022-DAVID LAWRENCE 1022,DAVID LAWRENCE *2379-OPI 2379,OPI *2565-MAC 2565,MAC *3498-BLAZER 3498,BLAZER *4753-QUICKSILVER 4753,QUICKSILVER Quote
mjab8 Posted April 29, 2016 Author Posted April 29, 2016 Anyone can help on improving the method of entering the attributes value? 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.