TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PDJ on February 14, 2005, 03:55:50 PM
-
What I'm trying to do is this:
We have 60 villages that we provide telephone support to in the bush here in Alaska. Each village has it's own directory and under each directory is a map with the villages exchange number as a name (i.e. 231oa.dwg).
What I'm trying to do is write a simple lisp that when loaded will have all my village directories and map names in there so that when I'm in AutoCad, I can just type x231 on the command line and it will open that villages map.
I know that filedia has to be switched to 0 at the start and returned to 1 at the end.
Here's what I have that isn't working so far.. :D
(defun C:X231()
(command "filedia" "0")
(command "OPEN" "T:\\PRM\\Birch Creek\\231OA.DWG" )
(command "filedia" "1")
)
I'm getting the following as an error:
Unknown command "T:\PRM\BIRCH CREEK\231OA.DWG"
I've tried with without the quotes but then it just gives me a nil..
I'm pretty sure this is a simple fix but, I can think very hard today.. Any help is greatly appreciated. My brain is fried from a lovely flu virus I've had for the last 4 days..
Thanks!
-
Is this a toughie?? 24 views so far and no comments or anything?? Hmmm..
-
http://tinyurl.com/526c4
-
Here is another one to try.
(command "vbastmt" (strcat
"AcadApplication.Documents.Open " (chr 34) filnam (chr 34)))
-
I use a variation of this :
(defun c:xtest ()
(if (setq tmp (findfile "F:\\Develop\\test\\Standards-012.DWG"))
(vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) tmp))
(alert "Can't find file : \n F:\\Develop\\test\\Standards-012.DWG")
)
)
-
Dag nabbit CAB, I tole yas my brain was fried.. hehe.. I think Kerry's is close enough.. Now I just gotta copy it 60 times in my lisp file and change all the name..
Thanks for the help you two!!
-
<snip> .. Now I just gotta copy it 60 times in my lisp file and change all the name.. </snip>
Your kidding right?!
-
Set the value of SDI to 1 and you "should" be able to use the (command "open" ...) without incident.
When the SDI interface was implemented, "open" was modified and the problems started.
-
se7en, that's how many different paths I have to be able to access. This is the main reason I wanted a routine like this. If I'm missing something, please let me know..
-
PDJ,
Your a beginner at lisp right?
-
"You are a" or "You're a", but not "your a".
<spank.mpg>
-
hummm?! Hey while i have your attention officer; Could you tell me if i spelled this right?
BAN!!!
-
se7en, that's how many different paths I have to be able to access. This is the main reason I wanted a routine like this. If I'm missing something, please let me know..
PDJ, rather than rewriting a routine for each path, create a routine that will define the lisps for you. By creating a master list that you can add to, delete from, modify at will it will make your job now, and in the future, much easier.
For instance:
(defun c:make_the_lisps (/ master_list)
(setq master_list '(("231" . "Path-to-231.dwg")
("491" . "Path-to-491.dwg")
;add all your villages like so
)
)
(foreach village master_list
(eval (read (strcat "(defun " "c:x" (car village)
" () (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object))\""
(cdr village) "\")))")
)
)
)
)
This will create a new lisp function that can be called from the command line, as you said you wanted, for each village listed in the master_list. Then you just need to call this one lisp in your acaddoc.lsp file
Is that what you had in mind Se7en?
-
*blink*
*sigh*
No.
I was gonna show him 'arguments'.
show-off!
:P :D
-
How about this, Paul?
You enter XLD 232 [enter] at the command line.
The space between D & 2 starts the routine.
You will have to maintain the list within the lisp.
You could use a text file read routine to read the list from a text file.
;; X Load
(defun c:xld (/ ac_list ac filen tmp)
(setq ac_list
(list
(list "231" "T:\\PRM\\Birch Creek\\231OA.DWG")
(list "232" "T:\\PRM\\Birch Creek\\232OA.DWG")
(list "233" "T:\\PRM\\Birch Creek\\233OA.DWG")
)
)
(if (setq ac (getstring "\nEnter the area code for the project to load. "))
(if (setq filen (assoc ac ac_list))
(progn
(setq filen (cdr filen))
;; from Kerry Brown
(if (setq tmp (findfile filen))
(vla-activate
(vla-open (vla-get-documents (vlax-get-acad-object)) tmp)
)
(alert (strcat "Can't find file : " filen))
)
)
(alert (strcat filen " is not in the list."))
)
)
(princ)
)
(prompt "\n*** XLD loaded, enter XLD followed by the area code to run [XLD 321].")
(princ)
-
"You are a" or "You're a", but not "your a".
<spank.mpg>
ROTFLMAO ................. :lol:
man that was good........ I haven't laughed like that in months.
-
"You are a" or "You're a", but not "your a".
<spank.mpg>
ROTFLMAO ................. :lol:
man that was good........ I haven't laughed like that in months.
I thought it was funny too but didn't laugh too hard
because they will be after me next. :horror:
-
hummm?! Hey while i have your attention officer; Could you tell me if i spelled this right?
BAN!!!
omg..is there really a spell check police?
-
Alright CAB, I tried your way, coulda sworn I checked it with just a few and now that I have all the villages loaded, it doesn't work.. Take a look if you will and see if you see any glaring errors. Main thing I did is change the name from xld to xx and added all those dang villages. FYI, the T: is a network drive but, I don't think that's a problem.
(defun c:xx (/ ac_list ac filen tmp)
(setq ac_list
(list
(list "231" "T:\\PRM\\Birch Creek\\221OA.DWG")
(list "237" "T:\\PRM\\newtokk\\237oa.DWG")
(list "238" "T:\\PRM\\alakanuk\\238oa.DWG")
(list "256" "T:\\PRM\\tuntutuliak\\256oa.DWG")
(list "293" "T:\\PRM\\nikolai\\293oa.DWG")
(list "295" "T:\\PRM\\livengood\\295oa.DWG")
(list "298" "T:\\PRM\\takotna\\298oa.DWG")
(list "358" "T:\\PRM\\rampart\\358oa.DWG")
(list "427" "T:\\PRM\\toksook bay\\427oa.DWG")
(list "438" "T:\\PRM\\st marys\\438oa.DWG")
(list "467" "T:\\PRM\\chuathbaluk\\467oa.DWG")
(list "477" "T:\\PRM\\kasigluk\\477oa.DWG")
(list "478" "T:\\PRM\\stevens village\\478oa.DWG")
(list "493" "T:\\PRM\\togiak\\493oa.DWG")
(list "496" "T:\\PRM\\nunam iqua\\496oa.DWG")
(list "520" "T:\\PRM\\central\\520oa.DWG")
(list "524" "T:\\PRM\\mcgrath\\524oa.DWG")
(list "525" "T:\\PRM\\twin hills\\525oa.DWG")
(list "526" "T:\\PRM\\lime village\\526oa.DWG")
(list "527" "T:\\PRM\\nunapitchuk\\527oa.DWG")
(list "536" "T:\\PRM\\eek\\536oa.DWG")
(list "543" "T:\\PRM\\bethel\\543oa.DWG")
(list "549" "T:\\PRM\\pilot station\\549oa.DWG")
(list "553" "T:\\PRM\\atmautluak\\553oa.DWG")
(list "556" "T:\\PRM\\quinhagak\\556oa.DWG")
(list "557" "T:\\PRM\\kongiganak\\557oa.DWG")
(list "558" "T:\\PRM\\scammon bay\\558oa.DWG")
(list "573" "T:\\PRM\\chenega bay\\573oa.DWG")
(list "584" "T:\\PRM\\russian mission\\584oa.DWG")
(list "587" "T:\\PRM\\arctic village\\587oa.DWG")
(list "588" "T:\\PRM\\kwigillingok\\588oa.DWG")
(list "589" "T:\\PRM\\napakiak\\589oa.DWG")
(list "591" "T:\\PRM\\mt village\\591oa.DWG")
(list "624" "T:\\PRM\\unalakleet\\624oa.DWG")
(list "628" "T:\\PRM\\beaver\\628oa.DWG")
(list "647" "T:\\PRM\\nightmute\\647oa.DWG")
(list "652" "T:\\PRM\\tununak\\652oa.DWG")
(list "672" "T:\\PRM\\manley hs\\672oa.DWG")
(list "674" "T:\\PRM\\l minchumina\\674oa.DWG")
(list "679" "T:\\PRM\\marshall\\679oa.DWG")
(list "695" "T:\\PRM\\tuluksak\\695oa.DWG")
(list "737" "T:\\PRM\\napaskiak\\737oa.DWG")
(list "757" "T:\\PRM\\kwethluk\\757oa.DWG")
(list "758" "T:\\PRM\\hooper bay\\758oa.DWG")
(list "765" "T:\\PRM\\akiak\\765oa.DWG")
(list "798" "T:\\PRM\\minto\\798oa.DWG")
(list "825" "T:\\PRM\\akiachak\\825oa.DWG")
(list "827" "T:\\PRM\\mekoryuk\\827oa.DWG")
(list "848" "T:\\PRM\\chalkyitsik\\848oa.DWG")
(list "849" "T:\\PRM\\venetie\\849oa.DWG")
(list "858" "T:\\PRM\\chevak\\858oa.DWG")
(list "867" "T:\\PRM\\chefornak\\867oa.DWG")
(list "896" "T:\\PRM\\kipnuk\\896oa.DWG")
(list "899" "T:\\PRM\\kotlik\\899oa.DWG")
(list "949" "T:\\PRM\\emmonak\\949oa.DWG")
(list "967" "T:\\PRM\\goodnews bay\\967oa.DWG")
(list "979" "T:\\PRM\\platinum\\979oa.DWG")
(list "984" "T:\\PRM\\savoonga\\984oa.DWG")
(list "985" "T:\\PRM\\gambell\\985oa.DWG")
)
)
(if (setq ac (getstring "\nEnter the area code for the project to load. "))
(if (setq filen (assoc ac ac_list))
(progn
(setq filen (cdr filen))
;; from Kerry Brown
(if (setq tmp (findfile filen))
(vla-activate
(vla-open (vla-get-documents (vlax-get-acad-object)) tmp)
)
(alert (strcat "Can't find file : " filen))
)
)
(alert (strcat filen " is not in the list."))
)
)
(princ)
)
(prompt "\n*** XX loaded, enter XX followed by the area code to run [XX 321].")
(princ)
Thanks for the help guys and dolls!!
-
Sorry Paul
Change this:
(setq filen (cdr filen))
to this:
(setq filen (cadr filen))
-
http://groups-beta.google <snip>
Make a bookmark in your browser and put the following for the path:
javascript:void(location.href='http://tinyurl.com/create.php?url='+location.href)
:)
-
Thanks Tim
I updated the post. :)
-
Works like a charm now CAB.. Many thanks!
-
You're welcome.
Here is another version.
(defun c:xx (/ ac_list ac filen tmp)
(setq ac_list
(list
(list "231" "Birch Creek")
(list "237" "newtokk")
(list "238" "alakanuk")
(list "256" "tuntutuliak")
(list "293" "nikolai")
(list "295" "livengood")
(list "298" "takotna")
(list "358" "rampart")
(list "427" "toksook bay")
(list "438" "st marys")
(list "467" "chuathbaluk")
(list "477" "kasigluk")
(list "478" "stevens village")
(list "493" "togiak")
(list "496" "nunam iqua")
(list "520" "central")
(list "524" "mcgrath")
(list "525" "twin hills")
(list "526" "lime village")
(list "527" "nunapitchuk")
(list "536" "eek")
(list "543" "bethel")
(list "549" "pilot station")
(list "553" "atmautluak")
(list "556" "quinhagak")
(list "557" "kongiganak")
(list "558" "scammon bay")
(list "573" "chenega bay")
(list "584" "russian mission")
(list "587" "arctic village")
(list "588" "kwigillingok")
(list "589" "napakiak")
(list "591" "mt village")
(list "624" "unalakleet")
(list "628" "beaver")
(list "647" "nightmute")
(list "652" "tununak")
(list "672" "manley hs")
(list "674" "l minchumina")
(list "679" "marshall")
(list "695" "tuluksak")
(list "737" "napaskiak")
(list "757" "kwethluk")
(list "758" "hooper bay")
(list "765" "akiak")
(list "798" "minto")
(list "825" "akiachak")
(list "827" "mekoryuk")
(list "848" "chalkyitsik")
(list "849" "venetie")
(list "858" "chevak")
(list "867" "chefornak")
(list "896" "kipnuk")
(list "899" "kotlik")
(list "949" "emmonak")
(list "967" "goodnews bay")
(list "979" "platinum")
(list "984" "savoonga")
(list "985" "gambell")
)
prefix "T:\\PRM\\"
suffix "oa.DWG"
)
(if (setq ac (getstring "\nEnter the area code for the project to load. "))
(if (setq filen (assoc ac ac_list))
(progn
(setq filen (strcat prefix (cadr filen) "\\" ac suffix ))
;; from Kerry Brown
(if (setq tmp (findfile filen))
(vla-activate
(vla-open (vla-get-documents (vlax-get-acad-object)) tmp)
)
(alert (strcat "Can't find file : " filen))
)
)
(alert (strcat filen " is not in the list."))
)
)
(princ)
)
(prompt "\n*** XX loaded, enter XX followed by the area code to run [XX 321].")
(princ)
-
Here's my quick 2˘ food for thought effort (untested) --
(defun c:xx
( /
areaCodes
areaCode
cityName
fileName
filePrefix
fileSuffix
filePath
openedOK
)
(setq areaCodes
'(
("231" . "Birch Creek")
("237" . "newtokk")
("238" . "alakanuk")
("256" . "tuntutuliak")
("293" . "nikolai")
("295" . "livengood")
("298" . "takotna")
("358" . "rampart")
("427" . "toksook bay")
("438" . "st marys")
("467" . "chuathbaluk")
("477" . "kasigluk")
("478" . "stevens village")
("493" . "togiak")
("496" . "nunam iqua")
("520" . "central")
("524" . "mcgrath")
("525" . "twin hills")
("526" . "lime village")
("527" . "nunapitchuk")
("536" . "eek")
("543" . "bethel")
("549" . "pilot station")
("553" . "atmautluak")
("556" . "quinhagak")
("557" . "kongiganak")
("558" . "scammon bay")
("573" . "chenega bay")
("584" . "russian mission")
("587" . "arctic village")
("588" . "kwigillingok")
("589" . "napakiak")
("591" . "mt village")
("624" . "unalakleet")
("628" . "beaver")
("647" . "nightmute")
("652" . "tununak")
("672" . "manley hs")
("674" . "l minchumina")
("679" . "marshall")
("695" . "tuluksak")
("737" . "napaskiak")
("757" . "kwethluk")
("758" . "hooper bay")
("765" . "akiak")
("798" . "minto")
("825" . "akiachak")
("827" . "mekoryuk")
("848" . "chalkyitsik")
("849" . "venetie")
("858" . "chevak")
("867" . "chefornak")
("896" . "kipnuk")
("899" . "kotlik")
("949" . "emmonak")
("967" . "goodnews bay")
("979" . "platinum")
("984" . "savoonga")
("985" . "gambell")
)
)
(setq
filePrefix "T:\\PRM\\"
fileSuffix "oa.DWG"
)
(setq areaCode
(getstring
(strcat
"\nEnter the area code "
"for the project to load. "
)
)
)
(cond
(
(and
(setq cityName
(cdr
(assoc
areaCode
areaCodes
)
)
)
(setq fileName
(strcat
filePrefix
cityName
"\\"
areaCode
fileSuffix
)
)
(setq filePath
(findfile fileName)
)
;; compliments Kerry Brown; slight massage
( (lambda (result)
(setq openedOK
(null
(vl-catch-all-error-p result)
)
)
)
(vl-catch-all-apply
'(lambda()
(vla-activate
(vla-open
(vla-get-documents
(vlax-get-acad-object)
)
filePath
)
)
)
)
)
)
)
( (null cityName)
(alert
(strcat
"<" areaCode ">"
" is not a valid area code."
)
)
)
( (null filePath)
(alert
(strcat
"Can't find file: "
fileName
)
)
)
( (null openedOK)
(alert
(strcat
"Problem opening "
filePath
"."
)
)
)
( t
(princ "We're not sure what happened.")
)
)
(princ)
)