Hi Folks,
I have tried to understand LISPS, but its way over my head. I can program in VBA within excel but for some reason, I just cant get LISPS !!!
What I need help in is a LISP to do the folowing
-A LISP to update only the Selected Block
-A LISP to Read a csv file from a predetermined location (i.e. C:\Users\....)
-The LISP should Lookup the 'Detail' Field in the Block and populate the other fields / Attribute values from looking up the cvs file
-If the 'Detail' Field does not match any of the detail values in the csv file, the block is updated.
-If a field is blank in the cvs file, that field will not be updated in the block.
Please see the attachd. Any help will be appreciated.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@BasTek_Inc wrote:
Hi Folks,
What I need help in is a LISP to do the folowing
-A LISP to update only the Selected Block
One question: You want this for single selection only?
(defun c:upd (/ _delFinder ss e a data b attrvalues) ;;; pBe 21July2014 ;;; (defun _delFinder (str md / d l str) (while (setq d (vl-string-position md str nil T)) (setq l (cons (substr str (+ 2 d)) l) str (substr str 1 d) ) ) (cons str l) ) (if (and (setq a nil data nil ss (ssget "_:L:S" '((0 . "INSERT") (2 . "WWW Callout Bubble,`*U*")) ) ) (eq (vla-get-effectivename (setq e (vlax-ename->vla-object (ssname ss 0))) ) "WWW Callout Bubble" ) (setq fn (findfile "Details.csv")) ) (progn (setq of (open fn "r")) (while (setq a (read-line of)) (setq data (cons (_delFinder a 44) data)) ) (close of) (setq attrvalues (vl-remove-if '(lambda (v) (member (Car v) '("LOCATION_ID" "PIPE_SIZE" "LENGTH_(IN.)" "FINISH" ) ) ) (mapcar '(lambda (at) (list (strcase (vla-get-tagstring at)) (vla-get-textstring at) at ) ) (vlax-invoke e 'Getattributes) ) ) ) (if (setq b (assoc (cadr (assoc "DETAIL_NO." attrvalues)) data)) (mapcar '(lambda (j h) (vla-put-textstring (last j) h) ) (cdr attrvalues) (cdr b) ) ) ) ) (princ) ) (vl-load-com)
Single or multiple selection would be great. Can I ask you for one additional feature? Can you have the LISP grab the file path from a field in the block. Please see attached.
P.S. The Lisp works great so far for a single selection. Thank you so much for your help !!!!
@BasTek_Inc wrote:
Single or multiple selection would be great. Can I ask you for one additional feature? Can you have the LISP grab the file path from a field in the block. Please see attached.
P.S. The Lisp works great so far for a single selection. Thank you so much for your help !!!!
Glad it works for you BasTek_Inc , Its easy to modify the code for multiple selections.
As for the file path, Yes, it can be deon, noticed i used (fndfile ....) function to determine where the details.csv file is located but i could've sworn you said:
<< -A LISP to Read a csv file from a predetermined location (i.e. C:\Users\....) >>>>
does that mean there is only one details.csv file? or one csv file per project folder?
I did say a csv file from a predetermined location, but rethinking it over, it would make more sence to have it as a field to fill in incase we need to make a project spacific csv file. This would make it more user friendly for our basic cad operators.
I took a stab at it. I think I was able to get the LSIP to get the File location from the Block. It seems to be working fine, but I am no expert. Please let me know if there are any errors and also how to make the code select one or multiple blocks.
@BasTek_Inc wrote:
I took a stab at it. I think I was able to get the LSIP to get the File location from the Block. It seems to be working fine, but I am no expert. Please let me know if there are any errors and also how to make the code select one or multiple blocks.
Here's what i think..
You're basically reading each block to check what csv file it reference to correct?
For multiple selection, say 5 objects, for every block it would open/read/close the data file? or should all the blocks on that drawing have the same path so it would check the data file once? And if the file is not found, should the program be asking where the current data file is located and update the last attribute field?
@BasTek_Inc wrote:
You ask very good questions. All blocks within the file will have the same path. Call it a project path if you will. It should check the data file once. If the file is not located, it may be a good idea for the program to ask for the file location and update all the blocks with the same path.
Ok, take a deep breath and think hard what else needs to be done before i make any changes on the original code , send me a PM if you want as ot not clutter this thread with Q&A.
🙂
@BasTek_Inc wrote:
That would be it. Thanks for your help.
P.S. I am new to the autodesk community and am not sure how to do a PM.
Okay then. HYG. Try it and tell me how it goes.
You Rock pbejse !!! Thanks for all your help. This will defenately make an impact in how we do things. Much appreciated !!!!
@BasTek_Inc wrote:
You Rock pbejse !!! Thanks for all your help. This will defenately make an impact in how we do things. Much appreciated !!!!
You are welcome BasTek_Inc. Glad it helps.
Cheers
pbejse, We discovered that after running the lisp once, it will not reload the csv file again. is there a way we can have the lisp reload the csv file everythime you run it. That way we can make changes to the csv file and save it, and reload the updated info to the block while the dwg file is open.
@BasTek_Inc wrote:
pbejse, We discovered that after running the lisp once, it will not reload the csv file again. is there a way we can have the lisp reload the csv file everythime you run it. That way we can make changes to the csv file and save it, and reload the updated info to the block while the dwg file is open.
I guess i can re-arrange the sequence to accomodate your request BasTek. Hang in there, i will read thru this thread again to get familiar with what the program is all about.
EDIT:
Lets say, the first thing that the routine will ask is the location of the CSV file.
Among the selected block there's a few with a path already defined on the path field and it does not match with the CSV the user were prompted at the start. what to do then?
EDIT2: Perhaps a toggle switch can be added as to when to read the CSV file again or not .
command: RCSV <--- Re-read CSV
As i remember, the point of using an attribute as a placeholder for the CSV location is to avoid remembering what CSV were used on the original DATA generation
@BasTek_Inc wrote:
The point of using the attribute as a placeholder for the location of the CSV is to have a project specific location. Back to your original question, if the path of the CSV file does not match, prompt the user for the location. All blocks in the same dwg file should lead to the same location. But the point of my question above is if we can have the lisp reread or reload the CSV file every time you run it.
I see, well all you ahve to do now is add the blue text on the routine
(defun c:upd (/ _delFinder read&_ ss e a b attrvalues Ndata fn npath)
and might as well add this too
(setq a nil npath nil
ss (ssget "_:L"
'((0 . "INSERT") (2 . "WWW Callout Bubble,`*U*"))
)
)
I believe the mod above will take care of your progblem [reloading the CSV]
HTH