legg1979 Posted August 13, 2013 Share Posted August 13, 2013 Hi guys, 1st of all I am a very very basic lisp user. I can write very simple lisp (probably not very well written but they work!) for every day tedious tasks. I am trying to write, put together a lisp to insert a block based on part of the file name. I will have a block named in following way. Partnumber1-Partnumber2.dwg The user when wanting to insert the block may have either of the part numbers. So only 1 part number will ever be entered. I need to the lisp to wildcard the block name. I have had a mess around with "wcmatch" but couldnt really get my head round it, hey I did say I was a basic user!! Any way. after days & hours of trial & error & web searching I found a code that does all but what I need. The only problem is after inserting the block the user needs to set scale & rotation. I have spent ages trying to work out where the "" "" "" would go to eliminate the user from having to do so but for the life of me I can not get it to work. Also I clue to where I would add "*" if i wanted the block to be exploded. Thanks in advance for help you guys can give. Heres the code. (defun c:test (/ file dir files itm n fil qt) (setq file (getstring "\nEnter partial block name to insert: ")) (if (and (setq dir "C:\\test\\test\\Blocks\\");; changes to your search path (setq files (vl-directory-files dir (strcat "*" file "*.dwg") 1)) ) (progn (cond ((= (length files) 1) (command "_.insert" (strcat (car files))) (while (> (getvar 'cmdactive) 0) (command pause)) ) ((> (length files) 1) (setq itm 0) (textscr) (foreach n files (print (strcat " " (rtos itm 2 0) " <-- " n)) (setq itm (1+ itm)) ) (setq qt (- (length files) 1)) (while (or (not fil) (not (<= 0 fil qt)) ) (setq fil (getint (strcat "\nEnter block number from 0 to " (rtos qt 2 0) " :") ) ) ) (graphscr) (command "_.insert" (strcat (nth fil files))) (while (> (getvar 'cmdactive) 0) (command pause)) ) ) ) (princ (strcat "\nThere are no blocks with -> " file " <- in the name!!!") ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted August 13, 2013 Share Posted August 13, 2013 (edited) This code is familiar to me. Perhaps something like this: (defun c:test (/ file dir files itm n fil qt) (setq file (getstring "\nEnter partial block name to insert: ")) (if (and (setq dir "C:\\test\\test\\Blocks\\");; changes to your search path (setq files (vl-directory-files dir (strcat "*" file "*.dwg") 1)) ) (progn (cond ((= (length files) 1) (command "_.insert" (strcat "*" dir (car files)) pause "" "" "") ) ((> (length files) 1) (setq itm 0) (textscr) (foreach n files (print (strcat " " (rtos itm 2 0) " <-- " n)) (setq itm (1+ itm)) ) (setq qt (- (length files) 1)) (while (or (not fil) (not (<= 0 fil qt)) ) (setq fil (getint (strcat "\nEnter block number from 0 to " (rtos qt 2 0) " :") ) ) ) (graphscr) (command "_.insert" (strcat "*" dir (nth fil files)) pause "" "" "") ) ) ) (princ (strcat "\nThere are no blocks with -> " file " <- in the name!!!") ) ) (princ) ) hope that helps Henrique Edited August 14, 2013 by hmsilva Quote Link to comment Share on other sites More sharing options...
legg1979 Posted August 25, 2013 Author Share Posted August 25, 2013 Absolutely perfect thanks. I think it may have been your code in the 1st place seeing your username rings a bell! Thanks again & sorry for the late reply have given it a rest for a while & only just read, applied & tested the code. Got another problem now but on a different code I have been writing so look out for a new tread!! Quote Link to comment Share on other sites More sharing options...
hmsilva Posted August 25, 2013 Share Posted August 25, 2013 You're welcome. Glad i could help. Henrique Quote Link to comment Share on other sites More sharing options...
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.