Author Topic: Using a field with filename - path only  (Read 14027 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Using a field with filename - path only
« Reply #15 on: May 27, 2010, 03:25:57 PM »
Without a reactor, I think your first post Alan is the closest we are going to get somehow...
Me too. :|
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

LE3

  • Guest
Re: Using a field with filename - path only
« Reply #16 on: May 27, 2010, 03:28:34 PM »
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...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using a field with filename - path only
« Reply #17 on: May 27, 2010, 03:30:00 PM »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

KOWBOI

  • Guest
Re: Using a field with filename - path only
« Reply #19 on: May 27, 2010, 04:28:52 PM »
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Using a field with filename - path only
« Reply #20 on: May 27, 2010, 04:44:43 PM »
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.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

KOWBOI

  • Guest
Re: Using a field with filename - path only
« Reply #21 on: May 27, 2010, 04:54:57 PM »
Geez, I feel like a moron compared to you guys. I know zip about reactors as well as diesel.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Using a field with filename - path only
« Reply #22 on: May 27, 2010, 04:59:34 PM »
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...

Code: [Select]
;;; 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


Code: [Select]
(at:lst2str (cdddr (at:str2lst (getvar 'dwgprefix) "\\")) "\\")If you need to add an additional backslash to the end:
Code: [Select]
(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.
« Last Edit: May 27, 2010, 05:02:54 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using a field with filename - path only
« Reply #23 on: May 27, 2010, 05:21:52 PM »
Perhaps more concise:

Code: [Select]
(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)))
« Last Edit: May 28, 2010, 05:56:22 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using a field with filename - path only
« Reply #24 on: May 27, 2010, 05:27:53 PM »
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  ;-)

KOWBOI

  • Guest
Re: Using a field with filename - path only
« Reply #25 on: May 27, 2010, 05:41:45 PM »
Perhaps more concise:

Code: [Select]
(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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using a field with filename - path only
« Reply #26 on: May 27, 2010, 05:50:01 PM »
Don't worry, "\\" is correct - it is an escape character sequence for "\"

KOWBOI

  • Guest
Re: Using a field with filename - path only
« Reply #27 on: May 27, 2010, 05:52:00 PM »
Right but I also need the string just ahead of the first \.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using a field with filename - path only
« Reply #28 on: May 27, 2010, 05:53:58 PM »
Ok, give this a try...

**  Create a FIELD, DieselExpression > in the box for the DIESEL expression type:

Code: [Select]
$(getvar,users1)
** Place the FIELD - it will probably show "----"  :-)

Now load this LISP:

Code: [Select]
(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

« Last Edit: May 27, 2010, 06:09:59 PM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using a field with filename - path only
« Reply #29 on: May 27, 2010, 05:54:53 PM »
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.  :-)