Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Diesel Expression - Part File Name, Start / End Character Number Varies

5 REPLIES 5
Reply
Message 1 of 6
JIC1118
863 Views, 5 Replies

Diesel Expression - Part File Name, Start / End Character Number Varies

Please see the attached image.

 

I was wondering if a Diesel Expression Field could be used within a Title Block to display only Positions C, D, E, F, G, & H – Eliminating A, B, J, K, & L. 

 

I am very new to Diesel, but I think I am encountering an issue because the number of characters varies in Positions A, C, E, G, & K.

 

If this is achievable utilizing Diesel, it would be very helpful if someone could indicate the construction of the code. If not, is there another method?

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: JIC1118

Hi JIC1118,

if I understood correctly, using DIESEL, I think it will not be possible, due to the number of characters will not be constant, but, using Auto/Visual LISP, something like this should do the trick

 

(defun my_dwg (dwg / a b c)
 (if (and (/= "" dwg)
          (setq a (vl-string-search "-" dwg))
          (setq b (vl-string-search " " dwg))
          (> (setq c (- b a)) 1)
          )
   (substr dwg (+ 2 a) (1- c))
   )
  )

 

_$ (my_dwg "0000000-000-0000-00-000 000000.dwg")
"000-0000-00-000"
_$ (my_dwg "000000-00-0-0-000 0000.dwg")
"00-0-0-000"
_$

 

I hope this helps
Henrique

EESignature

Message 3 of 6
Lee_Mac
in reply to: hmsilva

I agree that this would not be possible to achieve using DIESEL (refer to this thread for more information in this regard).

 

Henrique's code offers a good solution, but just to offer a slight alternative, you could also use wcmatch to test the validity of the input string, e.g.:

 

(defun dwgname ( dwg / pos )
    (if (wcmatch dwg "*-*? *")
        (substr dwg
            (+ 2 (setq pos (vl-string-position 45 dwg)))
            (-  (vl-string-position 32 dwg nil t) pos 1)
        )
    )
)

 

Message 4 of 6
hmsilva
in reply to: Lee_Mac


@Lee_Mac wrote:

(wcmatch dwg "*-*? *") 


Nice solution, Lee!

 

Henrique

EESignature

Message 5 of 6
Lee_Mac
in reply to: hmsilva

hmsilva wrote:
Lee_Mac wrote:

(wcmatch dwg "*-*? *") 

Nice solution, Lee!

 

Henrique

 

Thanks Henrique - your code was equally good!

Message 6 of 6
hmsilva
in reply to: Lee_Mac

Thanks Lee!

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost