Jump to content

Recommended Posts

Posted

I am trying to write a diesel expression that will extract the first part of the drawing file name. 

Full Drawing File Name: XXX-ZINC-XX-XX-DR-C-01000_S278 Sections

First Part:  XXX-ZINC-XX-XX-DR-C-

My question: Is there a smarter way to extract the first part rather than relaying on the number of characters? If everyone is following the correct naming protocol it would be 20 characters but sometimes you have people instead of -C- they put -CE- so I am wondering is there a way to future proof it.

 

Thank you.

 

$(substr,$(getvar,"dwgname"),1,20)

 

Posted

One of the others ways to do this is to use a lisp and break the string into individual bits. As you have a "-" as a common item in the string you can blow it apart and rejoin. Thanks to Lee-mac parse lsp. Something like this.

; Parse string to a list ny Lee-mac

(defun csv->lst (str ans / pos )
(if (setq pos (vl-string-position ans str))
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2)) ans))
    (list str)
    )
)

(setq str "XXX-ZINC-XX-XX-DR-C-01000_S278 Sections") ; use (getvar 'dwgname)
(setq newstr "" x 0)
(setq ans (csv->lst str 45))
(repeat (- (length ans) 2)
(setq newstr (strcat newstr (nth x ans) "-"))
(setq x (1+ x))
)
(setq newstr (strcat newstr (nth x ans)))

 

Ps ; tab 9 space 32 (chr 32) comma 44 semicolon 59 slash / 47 - 45

  • Like 1
Posted

Thank you so much! After playing with lisp for over a two months now I am so happy that I can understand the above!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...