TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: KOWBOI on May 27, 2010, 10:33:20 AM
-
My apologies if this is not in the proper area. Feel free to move it if necessary.
I make use of fields in my title block that populate automatically. I want to add a field using the filename - path only but I would like to show only the last two back slashes in the path.
Instead of showing this:
S:\STONE_APPS\CUSTOMERS\JIM VAUGHN HOMES\24115
I would like to show this:
\JIM VAUGHN HOMES\24115
Is that possible?
Thanks for any and all comments/help.
-
Use a Diesel expression Field.
eg.$(substr,$(getvar,dwgprefix),[color=red]NUMBER[/color])
NUMBER being what you want to cut off.
-
lost my lisp powers some moons ago... but here i go - just to pretend...
(defun string-break (str pat / i j lst)
(setq i 0)
(while (setq j (vl-string-search pat str i))
(setq lst (cons (substr str (1+ i) (- j i)) lst))
(setq i (+ j (strlen pat))))
(mapcar (function (lambda (x) (vl-string-trim " " x)))
(cons (substr str (1+ i)) lst)))
usage:
(setq filename "S:\\STONE_APPS\\CUSTOMERS\\JIM VAUGHN HOMES\\24115")
(setq items (reverse (string-break filename "\\")))
;;;(setq backslashes (- (length items) 1))
;;;\JIM VAUGHN HOMES\24115
(setq lsp (strcat "\\" (nth (- (length items) 2) items) "\\" (last items)))
then from field command you can use LispVariable - by selecting your lisp variable there
-
Thanks for the input. The number of characters before the last two backslashes changes. Is there a way to count only the backslashes?
I replied before I saw the second response. How exactly would I use the lisp code to set the field to the last two backslashes?
-
I replied before I saw the second response. How exactly would I use the lisp code to set the field to the last two backslashes?
Lisp variable Field
-
I must be missing something. I don't see a field option for lisp variable.
-
I must be missing something. I don't see a field option for lisp variable.
from A2010...
-
Ok, I'm on 2006 so I don't have the lisp variable option. Guess I should have been specific about which version I was using. Given that I'm on 2006 what are my options now?
-
How about setting the string you need to one of USERS1, and using a DIESEL field to retrieve it? Can't think of much else.... :|
-
How about setting the string you need to one of USERS1, and using a DIESEL field to retrieve it? Can't think of much else.... :|
Here's an example I did...http://www.cadtutor.net/forum/showthread.php?t=40653
-
Th IT Nazis here at work have that site blocked as an interest/hobby so I can't view the example. I'd love to see it though, can you post it here?
-
Th IT Nazis here at work have that site blocked as an interest/hobby so I can't view the example. I'd love to see it though, can you post it here?
Sure thing. :)
I save the entire page so you could read my post. Both LSP files are also zipped.
-
also, don't remember if RTEXT it is available on A2006, you might see if could be of some help too, maybe
-
also, don't remember if RTEXT it is available on A2006, you might see if could be of some help too, maybe
Heck yeah, I still use RText, but it will only accept Diesel.
-
Without a reactor, I think your first post Alan is the closest we are going to get somehow...
-
Without a reactor, I think your first post Alan is the closest we are going to get somehow...
Me too. :|
-
you guys are correct...
i did very little diesel in my lisper life, if i get a chance will try to play into the few functions available in there, as soon i finish some stuff here...
-
This is what I use for DIESEL:
http://www.crlf.de/Dokumente/Diesel/DieselReference.html (http://www.crlf.de/Dokumente/Diesel/DieselReference.html)
-
This is what I use for DIESEL:
http://www.crlf.de/Dokumente/Diesel/DieselReference.html (http://www.crlf.de/Dokumente/Diesel/DieselReference.html)
x2
-
I hardly know lisp and I zip about diesel but I will take a look, thanks. Alan, your first example would work if all the path names were consistent in length but they vary a great deal.
-
I hardly know lisp and I zip about diesel but I will take a look, thanks. Alan, your first example would work if all the path names were consistent in length but they vary a great deal.
Then you'll need a reactor. You could easily modify one of the two versions I posted to work with your needs.
-
Geez, I feel like a moron compared to you guys. I know zip about reactors as well as diesel.
-
I've posted both of these before, but I don't feel like digging them up.
This could (and definitely should) easily be consolidated (more concise and faster), but it should give you something to play with...
;;; Convert string to list, based on separator
;;; #Str - String to convert
;;; #Sep - Separator to break string into items
;;; Ex. - (AT:Str2Lst "1,2,3" ",") -> '("1" "2" "3")
;;; Alan J. Thompson, 11.11.09 / 04.01.10
(defun AT:Str2Lst (#Str #Sep / #Inc #List #Str)
(while (setq #Inc (vl-string-search #Sep #Str))
(setq #List (cons (substr #Str 1 #Inc) #List))
(setq #Str (substr #Str (+ 2 #Inc)))
) ;_ while
(vl-remove "" (reverse (cons #Str #List)))
) ;_ defun
;;; Convert List to String
;;; L - List to process
;;; S - Separator
;;; Ex. (AT:Lst2Str '("A" "B" "C") ",") -> "A,B,C"
;;; Alan J. Thompson, 04.01.10
(defun AT:Lst2Str (L S)
(if (cdr L)
(strcat (vl-princ-to-string (car L)) S (AT:Lst2Str (cdr L) S))
(vl-princ-to-string (car L))
) ;_ if
) ;_ defun
(at:lst2str (cdddr (at:str2lst (getvar 'dwgprefix) "\\")) "\\")
If you need to add an additional backslash to the end:
(strcat (at:lst2str (cdddr (at:str2lst (getvar 'dwgprefix) "\\")) "\\") "\\")
:|
This is extremely ugly, but it's time to go home and I just wanted to give you some options.
-
Perhaps more concise:
(setq DWG (getvar 'DWGPREFIX))
(and (eq "\\" (substr DWG (strlen DWG)))
(setq DWG (substr DWG 1 (1- (strlen DWG)))))
(substr DWG (1+ (vl-string-position 92 (substr DWG 1 (vl-string-position 92 DWG 0 t)) 0 t)))
-
Geez, I feel like a moron compared to you guys. I know zip about reactors as well as diesel.
Don't feel bad about that - reactors are a more advanced topic of Visual LISP ;-)
-
Perhaps more concise:
(setq DWG (getvar 'DWGPREFIX))
(substr DWG (1+ (vl-string-position 92 (substr DWG 1 (vl-string-position 92 DWG 0 t)) 0 t)))
Instead of showing this:
S:\STONE_APPS\CUSTOMERS\JIM VAUGHN HOMES\24115
I would like to show this:
\JIM VAUGHN HOMES\24115
With the code above I get this:
\\24115\\
Ok something else I know nothing about is visual lisp.
-
Don't worry, "\\" is correct - it is an escape character sequence for "\"
-
Right but I also need the string just ahead of the first \.
-
Ok, give this a try...
** Create a FIELD, DieselExpression > in the box for the DIESEL expression type:
$(getvar,users1)
** Place the FIELD - it will probably show "----" :-)
Now load this LISP:
(defun c:FilenameReactor nil
(vl-load-com)
;; © Lee Mac ~ 27.05.10
( (lambda ( data foo / react )
(if
(setq react
(vl-some
(function
(lambda ( reactor )
(if (eq data (vlr-data reactor)) reactor)
)
)
(cdar (vlr-reactors :vlr-command-reactor))
)
)
(if (vlr-added-p react)
(vlr-remove react)
(vlr-add react)
)
(setq react
(vlr-command-reactor data
(list
(cons :vlr-CommandWillStart foo)
)
)
)
)
(princ
(if (vlr-added-p react)
"\n** Reactor Activated **"
"\n** Reactor Deactivated **"
)
)
react
)
"Filename-Reactor"
'Filename-CallBack
)
(princ)
)
(defun Filename-CallBack ( reactor args / pos str )
(if (wcmatch (strcase (car args)) "*REGEN*")
(progn
(setq dwg (getvar 'DWGPREFIX))
(and (eq "\\" (substr dwg (strlen dwg)))
(setq dwg (substr dwg 1 (1- (strlen dwg)))))
(and (setq pos (vl-string-position 92 dwg 0 t))
(setq str (substr dwg 1 pos))
(setq pos (vl-string-position 92 str 0 t))
(setq dwg (substr dwg (1+ pos)))
(setvar "USERS1" dwg)
)
)
)
(princ)
)
** Type "FilenameReactor" at the command line (only type this once... it is a toggle).
** Regen the drawing and hopefully smile 8-)
Or you can load and call the LISP first, then make the FIELD, whichever takes your fancy :P
-
Right but I also need the string just ahead of the first \.
Gotcha - try the code I posted to see if it works, and I'll update that for you. :-)
-
OK, try the updated code :-)
-
That worked, thank you Lee! Can I make this run automatically each time I start a new drawing?
-
Excellent :lol:
Put the code in the ACADDOC.lsp with (c:FilenameReactor) after it :-)
-
FYI there is an ARX sample in the SDK that has this functionality. it also has the hook for the field dialog.
-
Perhaps more concise:
(setq DWG (getvar 'DWGPREFIX))
(substr DWG (1+ (vl-string-position 92 (substr DWG 1 (vl-string-position 92 DWG 0 t)) 0 t)))
Thanks Lee; very nice.
I knew there was a better way to write it, but it was time to leave and I wanted to post 'something'. :) I figured someone would post a better solution.
-
Oh yeah, know that the reactor will only work if the person opening the file is running it.
-
Thanks Alan - and good point indeed 8-)
-
ok... no idea if this miserable code is of some use and how about the vars names, but well here it goes (it can be use for at least extract the strings for the output path, and what it is available in a2006? for the field command): :-P
;;;S:\STONE_APPS\CUSTOMERS\JIM VAUGHN HOMES\24115
;;;
;;;\JIM VAUGHN HOMES\24115
;;;
(setq filename "S:\\STONE_APPS\\CUSTOMERS\\JIM VAUGHN HOMES\\24115")
(setq list_1 (fnsplitl filename)) ;;("S:\\STONE_APPS\\CUSTOMERS\\JIM VAUGHN HOMES\\" "24115" "")
(setq _filename (car list_1) _l (cadr list_1)) ;; "S:\\STONE_APPS\\CUSTOMERS\\JIM VAUGHN HOMES\\" "24115"
(setq __sub (substr _filename 1 (- (strlen _filename) 1) )) ;;"S:\\STONE_APPS\\CUSTOMERS\\JIM VAUGHN HOMES"
(setq list_2 (fnsplitl __sub)) ;;("S:\\STONE_APPS\\CUSTOMERS\\" "JIM VAUGHN HOMES" "")
(setq item1 (car list_2) item2 (cadr list_2)) ;;"S:\\STONE_APPS\\CUSTOMERS\\" "JIM VAUGHN HOMES"
(setq backs (substr item1 (strlen item1)))
(setq path (strcat backs item2 backs _l)) ;;"\\JIM VAUGHN HOMES\\24115"
-
hmm... the old undocumented function fnsplitl does not play nice with long file names nor if the first front folder have empty spaces...
-
Oh yeah, know that the reactor will only work if the person opening the file is running it.
What do you mean the person running the file? It has to be loaded on every machine right?
-
Oh yeah, know that the reactor will only work if the person opening the file is running it.
What do you mean the person running the file? It has to be loaded on every machine right?
Correct.
-
Cool, thank you all so much for the help it's greatly appreciated.
I setup the acaddoc.lsp with the code, works great! Thanks again, you guys are a huge help and a great resource of info.
-
You're welcome :-)
So bear in mind that if you send the file to clients - the lack of reactor means that the FIELD will not display correctly.
-
You're welcome :-)
So bear in mind that if you send the file to clients - the lack of reactor means that the FIELD will not display correctly.
<out of scope>
every time I read that it is always translated to beer in mind.... in all my 38 years I have speaking English.... :ugly:
<out of scope>
-
You're welcome :-)
So bear in mind that if you send the file to clients - the lack of reactor means that the FIELD will not display correctly.
<out of scope>
every time I read that it is always translated to beer in mind.... in all my 38 years I have speaking English.... :ugly:
<out of scope>
Makes sense to me, Luis! :-D I do the same thing and I've never spoke another language...well, except for German during 3 years in high school....
-
Some words make me think of bourbon ... but thats my personal problem :wink:
-
Some words make me think of bourbon ... but thats my personal problem :wink:
That appears to be whiskey, don't think I ever had tried....
-
You're welcome :-)
So bear in mind that if you send the file to clients - the lack of reactor means that the FIELD will not display correctly.
<out of scope>
every time I read that it is always translated to beer in mind.... in all my 38 years I have speaking English.... :ugly:
<out of scope>
Makes sense to me, Luis! :-D I do the same thing and I've never spoke another language...well, except for German during 3 years in high school....
:lol:
-
You're welcome :-)
So bear in mind that if you send the file to clients - the lack of reactor means that the FIELD will not display correctly.
Not a problem, we don't send electronic files to anyone. Thanks again for all the help :-)
-
You're very welcome :-)
-
Lee, I've been using this setup with great success until recently. For some reason lately the field does not display properly much of the time unless I force a Regen. Any ideas or suggestions? Thanks for the help.
-
The code reacts upon the Regen command, yes.
-
Lee, I've been using this setup with great success until recently. For some reason lately the field does not display properly much of the time unless I force a Regen. Any ideas or suggestions? Thanks for the help.
you will want to investigate the FIELDEVAL system variable
Controls how fields are updated.
The setting is stored as a bitcode using the sum of the following values:
0
Not updated
1
Updated on open
2
Updated on save
4
Updated on plot
8
Updated on use of ETRANSMIT
16
Updated on regeneration
NoteThe Date field is updated by UPDATEFIELD, but it is not updated automatically based on the setting of the FIELDEVAL system variable.
-
Ok so I already had all the field update settings turned on. The code that Lee setup for me (thanks again Lee) had a Regen command in it, I also tried putting a Regen command in my Acaddoc.lsp but I still have to force an update for that particular field by manually typing Regen at the command line. Any thoughts/suggestions?
-
My code creates a field dependent upon one of the custom system variables 'USERS#' - this is updated when the command reactor callback is triggered upon a Regen being called.
Lee
-
Thanks Lee. Shouldn't the field update automatically with your code since there is a Regen command in there? Also, I put a Regen command in Acaddoc.lsp and I'm not getting a Regen. Any ideas?
-
Thanks Lee. Shouldn't the field update automatically with your code since there is a Regen command in there? Also, I put a Regen command in Acaddoc.lsp and I'm not getting a Regen. Any ideas?
The field will only update when you perform a regen, as this is when the command reactor is triggered.
-
Just a thought: couldn't you use s::startup to handle the regen?
-
I tried using this in the Acaddoc.lsp but still no Regen at startup.
(defun-q S::STARTUP ( )
(command "REGEN")
)
Am I understanding the concept correctly?
-
Could it be that you already have s::startup in some file?:
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%202010%20User%20Documentation/files/WS73099cc142f4875513fb5cd10c4aa30d6b-7f62.htm
I don't know if s::startup can solve your problem, but your code should result in a regen.
-
The startup still didn't force a regen when opening a drawing using this code. I'm stumped.
-
The startup still didn't force a regen when opening a drawing using this code. I'm stumped.
what happens if you place the same field manually?