Hey folks,
I'm using a Lisp which searches a certain folder and then updates all blocks, which are nested in that folder.
My issue is, that I'd like to use more than one folder on different path, where the LISP can search for this files. Is there a way to use multiple search path?
The code I'm using now to search for the blocks is: (setq dir "I:\\AutoCAD Blöcke\\Template\\Support")
Hope you guys can help me with this little issue!
cheers Klingi
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Look into the loop functions (while ...), (foreach ...), and (repeat ...). You can create a list of strings, with each string as the path. You pass each string in the list to the function for processing.
@Klingi162 wrote:
Hey folks,
I'm using a Lisp which searches a certain folder and then updates all blocks, which are nested in that folder.
My issue is, that I'd like to use more than one folder on different path, where the LISP can search for this files. Is there a way to use multiple search path?
The code I'm using now to search for the blocks is: (setq dir "I:\\AutoCAD Blöcke\\Template\\Support")
Hope you guys can help me with this little issue!
cheers Klingi
Try this
(defun wHere (bn) (vl-some (function (lambda (d) (findfile (strcat d bn ".dwg")))) (list "C:\\Folder1\\" "C:\\Folder2\\" "C:\\Folder3\\")) ) (if (setq dir (wHere "blockname")) "do this" "else do this" )
HTH
Hey guys,
first of all thanks for your replies.
The thing is I'm pretty new to the Lisp stuff and don't even know where to put the missing lines to make it work.
I post my code so you could maybe tell me where to insert it to make it work.
thanks again guys.
(defun c:UB ( / bln dir doc dwg lst obj org spc )
(setq dir "I:\\AutoCAD Blöcke\\Template\\Support") ;; Directory of Block Library; nil to use Support Path
(if dir
(setq dir (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)) "\\"))
(setq dir "")
)
(cond
( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
(princ "\nCurrent layer locked.")
)
( (setq doc (vla-get-activedocument (vlax-get-acad-object))
spc (vla-get-modelspace doc)
org (vlax-3D-point 0 0)
)
(terpri)
(vlax-for blk (vla-get-blocks doc)
(if
(and
(= :vlax-false (vla-get-isxref blk))
(= :vlax-false (vla-get-islayout blk))
(not (wcmatch (setq bln (vla-get-name blk)) "`**,*|*"))
)
(if (setq dwg (findfile (strcat dir bln ".dwg")))
(progn
(princ (strcat "Block aktualisiert: " dwg "\n"))
(setq obj (vla-insertblock spc org dwg 1.0 1.0 1.0 0.0))
(if (= :vlax-true (vla-get-hasattributes obj))
(setq lst (vl-list* "," bln lst))
)
(vla-delete obj)
)
(princ (strcat "Block kann nicht gefunden werden: " dir bln ".dwg\n"))
)
)
)
(if lst
(progn
(princ "Synchronising attributes for redefined blocks...\n")
(vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst)))
)
)
(vla-regen doc acallviewports)
)
)
(princ)
)
(vl-load-com)
(princ "\n:: UpdateBlock.lsp erfolgreich geladen ::")
(princ)
@Klingi162 wrote:
Hey guys,...
....I post my code so you could maybe tell me where to insert it to make it work.....
HYG
(defun c:UB (/ wHere bln dir doc dwg lst obj org spc) ;; (setq dir "I:\\AutoCAD Blöcke\\Template\\Support") ;; Directory of Block Library; nil to use Support Path (defun wHere (bn / fl) ;;; pBe Dec2013 ;;; (or (setq fl (findfile (strcat bn ".dwg"))) (setq fl (vl-some (function (lambda (d) (findfile (strcat d bn ".dwg")) ) ) (list "I:\\AutoCAD Blöcke\\Template\\Support\\" "C:\\Folder1\\" ;; "My issue is, that I'd like to use more "C:\\Folder2\\" ;; than one folder on different path" "C:\\Folder3\\" ;; This is where you put the other target folders ) ) ) ) fl ) (cond ((= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer)))) ) ) (princ "\nCurrent layer locked.") ) ((setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-modelspace doc) org (vlax-3D-point 0 0) ) (terpri) (vlax-for blk (vla-get-blocks doc) (if (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk)) (not (wcmatch (setq bln (vla-get-name blk)) "`**,*|*")) ) (if (setq dwg (wHere bln)) (progn (princ (strcat "Block aktualisiert: " dwg "\n")) (setq obj (vla-insertblock spc org dwg 1.0 1.0 1.0 0.0)) (if (= :vlax-true (vla-get-hasattributes obj)) (setq lst (vl-list* "," bln lst)) ) (vla-delete obj) ) (princ (strcat "Block kann nicht gefunden werden: " bln ".dwg\n" ) ) ) ) ) (if lst (progn (princ "Synchronising attributes for redefined blocks...\n") (vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst))) ) ) (vla-regen doc acallviewports) ) ) (princ) ) (vl-load-com) (princ "\n:: UpdateBlock.lsp erfolgreich geladen ::") (princ)
HTH
BTW: next time use code tags when posting codes
thanks pbejse,
works exactly how it should. you made my day
Is there also a way that it updates all theblocks in the subfolders?
Thanks for the advice with the code tags, but I don't know how to use them.
Is it this "message tag" down there?
@Klingi162 wrote:
thanks pbejse,
works exactly how it should. you made my day
Is there also a way that it updates all theblocks in the subfolders?
Thanks for the advice with the code tags, but I don't know how to use them.
Is it this "message tag" down there?
You are welcome Klingi162. Glad I could help
You mean the other way around? I guess it can be done. Do you need it now?
.... This code tags ↑↑↑ .....
thanks man,
I mean that it now just updates the blocks in the folder that I add to the list, but all it's subfolders don't get searched for updates.
I'd like to give the main adress of the library, but sort the many blocks I got via different subfolders.
For example:
right now I'm using this one and it just updates every block in this specific folder. "I:\\AutoCAD Blöcke\\Template\\Support\\"
But what I want is, that I just write "I:\\AutoCAD Blöcke\\" and it knows that there are subfolders in this directory and searches them as well to update the blocks.
Thanks for the advice about the "insert code"
@Klingi162 wrote:
right now I'm using this one and it just updates every block in this specific folder. "I:\\AutoCAD Blöcke\\Template\\Support\\"
But what I want is, that I just write "I:\\AutoCAD Blöcke\\" and it knows that there are subfolders in this directory and searches them as well to update the blocks.
Before i modify the code . Answer me this will there be more subfolders on the subfolders?
@Klingi162 wrote:
I post my code so you could maybe tell me where to insert it to make it work.
(defun c:UB ( / bln dir doc dwg lst obj org spc ) (setq dir "I:\\AutoCAD Blöcke\\Template\\Support") ;; Directory of Block Library; nil to use Support Path
(if dir
(setq dir (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)) "\\"))
(setq dir "")
)
(cond
( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
(princ "\nCurrent layer locked.")
)
( (setq doc (vla-get-activedocument (vlax-get-acad-object))
spc (vla-get-modelspace doc)
org (vlax-3D-point 0 0)
)
(terpri)
(vlax-for blk (vla-get-blocks doc)
(if
(and
(= :vlax-false (vla-get-isxref blk))
(= :vlax-false (vla-get-islayout blk))
(not (wcmatch (setq bln (vla-get-name blk)) "`**,*|*"))
)
(if (setq dwg (findfile (strcat dir bln ".dwg")))
(progn
(princ (strcat "Block aktualisiert: " dwg "\n"))
(setq obj (vla-insertblock spc org dwg 1.0 1.0 1.0 0.0))
(if (= :vlax-true (vla-get-hasattributes obj))
(setq lst (vl-list* "," bln lst))
)
(vla-delete obj)
)
(princ (strcat "Block kann nicht gefunden werden: " dir bln ".dwg\n"))
)
)
)
(if lst
(progn
(princ "Synchronising attributes for redefined blocks...\n")
(vl-cmdf "_.attsync" "_N" (apply 'strcat (cdr lst)))
)
)
(vla-regen doc acallviewports)
)
)
(princ)
)
(vl-load-com)
(princ "\n:: UpdateBlock.lsp erfolgreich geladen ::")
(princ)
That code looks very familiar...
After devoting my spare time to helping you in that thread, I really can't understand why you would decide to repay me by removing my name from the code and claiming it as your own... Nevertheless, I now know not to offer you any help in the future.
@Lee_Mac wrote:
@Klingi162 wrote:I post my code so you could maybe tell me where to insert it to make it work....
That code looks very familiar...
After devoting my spare time to helping you in that thread, I really can't understand why you would decide to repay me by removing my name from the code and claiming it as your own... Nevertheless, I now know not to offer you any help in the future.
To think i almost suggest the OP to use your recursive findfile function you wrote some time ago. Apologies into stepping onto your toes LM.
But if you dont mind i'll go ahead and post the code with the proper credits
@pbejse wrote:
@Lee_Mac wrote:
@Klingi162 wrote:I post my code so you could maybe tell me where to insert it to make it work....
That code looks very familiar...
After devoting my spare time to helping you in that thread, I really can't understand why you would decide to repay me by removing my name from the code and claiming it as your own... Nevertheless, I now know not to offer you any help in the future.
To think i almost suggest the OP to use your recursive findfile function you wrote some time ago. Apologies into stepping onto your toes LM.
But if you dont mind i'll go ahead and post the code with the proper credits
There is no need for you to apologise Patrick, you were also only trying to help the OP.
For those other members who happen to be reading this thread and perhaps interpret my comments as petty gripes over inconsequential code, please understand that my issue is not with the code itself - the code in question is trivial and could no doubt be written by many who frequent this board. No, my issue is with the fact that the OP has intentionally and deliberately removed the one line of code acknowledging the time & effort that I have generously donated to assisting them. This tells me that they obviously do not value the time I have spent helping them and are simply using the members here for their own gains.
Hey Lee Mac,
I'm really sorry about that, but didn't mean to harm you in any way.
I just didn't know how to put an existing code in this forum without getting any problems with "rights". Thats why I removed the line where your originally put your name, although I was thinking about it carefully. Next time I know better, I definitely know how much work it takes and whould never know how to create it own my own.
sorry about this ignoble posts Lee Mac, I was always a great fan of what your doing and in what way you help noobs like me...
I appreciate your apology, and hope that my earlier posts weren't too 'harsh' when posted in the heat of the moment. Please understand that my point was not about claiming the code as my own invention or you violating my 'rights' to the code - as I say, the code in question could likely be written by many on this board - my point was more about the principle applicable to 5 lines of code or 5,000 lines of code.
In short, when posting code written by another author to the public domain, it is good coding etiquette to acknowledge the original source of the code (even if the code didn't originally include an author's note, it is dutiful to include one if you know the source), otherwise, code is assumed to be your own.
Lee
Thanks Lee Mac,
I'm going to act more respectful with any codes of someone else and add it's original author.
Your post wasn't to harsh at all and your good right to show how important it is to pay attention to one's work, as most of us need to deal with design copying in daily life and how ennoying it can be.
till soon...hopefully
Klingi
Thank you for your understanding Klingi