Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
zale-86
Posts: 8
Registered: ‎03-21-2012
Message 1 of 4 (257 Views)

Creating an array using split function

257 Views, 3 Replies
01-10-2013 01:37 PM

In asp I'd write:

arrFileName = Split(DrawingName, "_")

JobNumber = arrFileName(0)
DrawingTitle = arrFileName(1)

SheetNumber = arrFileName(2)

 

I'd like to do the same thing in lsp. I don't want to be limited to three fields so the split function is perfect.

 

Is there an equilivant?

 

TIA

 

 

 

 

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 2 of 4 (247 Views)

Re: Creating an array using split function

01-10-2013 02:19 PM in reply to: zale-86

zale-86 wrote:

In asp I'd write:

arrFileName = Split(DrawingName, "_")

JobNumber = arrFileName(0)
DrawingTitle = arrFileName(1)

SheetNumber = arrFileName(2)

 

I'd like to do the same thing in lsp. I don't want to be limited to three fields so the split function is perfect.

 

Is there an equilivant?

....


I don't know asp, but if I'm interpreting what you want to do correctly....

 

There have been many threads here about splitting or subdividing text strings around designated delimiting characters, and put the sub-strings into a list.  You can search and find lots of others, but for instance, my Message 8 here:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Extract-a-folder-name-within-dwgprefi...

 

Load up the (sdtol) function, and do this with it:

 

(setq

  arrFileName (sdtol (getvar 'dwgname) "_")

  JobNumber (nth 0 arrFileName)

  DrawingTitle (nth 1 arrFileName)

  SheetNumber (nth 2 arrFileName)

)

 

...plus whatever other "fields" your drawing name has, separated by underscores.

 

You might also need to add something to whack the ".dwg" off the end of the drawing name, but first see whether it does what you want otherwise.

Kent Cooper
Active Contributor
AlessiMarc'Antonio
Posts: 49
Registered: ‎12-04-2006
Message 3 of 4 (225 Views)

Re: Creating an array using split function

01-11-2013 01:22 AM in reply to: zale-86

Command: (setq InfLst (ALE_String2List "JNumber_Title_SNumber" "_"))
("JNumber" "Title" "SNumber")

Command: (car InfLst)
"JNumber"

Command: (cadr InfLst)
"Title"

Command: (caddr InfLst)
"SNumber"

; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_String2List
;
; Version 1.00 - November 2001
;
; Description:
;   convert a string into a list
;
; Arguments:
;   InpStr = string [STR]
;   CarDlm = delimiter [STR] 1 character
;
(defun ALE_String2List (InpStr CarDlm / SttPos EndPos TmpLst)
  (setq
    CarDlm (ascii CarDlm)   SttPos 0
    EndPos (vl-string-position CarDlm InpStr)
  )
  (while EndPos
    (setq
      TmpLst (cons (substr InpStr (1+ SttPos) (- EndPos SttPos)) TmpLst)
      SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
    )
  )
  (reverse (cons (substr InpStr (1+ SttPos)) TmpLst))
)
; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_String_ToList
;
; Version 1.00 - 01/2010
;
; Description:
;   convert a string into a list of strings
;
; Arguments:
;   InpStr = string [STR]
;   CarDlm = delimiter [STR] 1 character
;   TrueFl = if nil remove dupes delimiter
;
; Examples:
;  (ALE_String_ToList "aaa_vvv_hhh__yyy ___lll_" "_" T)
;  ("aaa" "vvv" "hhh" "" "yyy " "" "" "lll" "lll")
;
;  (ALE_String_ToList "aaa_vvv_hhh__yyy ___lll_" "_" nil)
;  ("aaa" "vvv" "hhh" "yyy " "lll")
;
(defun ALE_String_ToList (InpStr CarDlm TrueFl / SttPos EndPos TmpLst TmpStr)
  (setq
    CarDlm (ascii CarDlm)   SttPos 0
    EndPos (vl-string-position CarDlm InpStr)
  )
  (while EndPos
    (setq
      TmpStr (substr InpStr (1+ SttPos) (- EndPos SttPos))
      SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
    )
    (and
      (or (/= TmpStr "") TrueFl)
      (setq TmpLst (cons TmpStr TmpLst))
    )
  )
  (if (or (/= (setq TmpStr (substr InpStr (1+ SttPos))) "") TrueFl)
    (reverse (cons TmpStr TmpLst))
    (reverse TmpLst)
  )
)

 

Marc'Antonio Alessi

http://alessi.xoom.it//alessi/Programmi.htm
(vl-string-translate "1234567890" "ie@mst.lan" "499825513610716")
2D Parametric for 2000-2013
Active Member
zale-86
Posts: 8
Registered: ‎03-21-2012
Message 4 of 4 (191 Views)

Re: Creating an array using split function

01-15-2013 07:07 AM in reply to: zale-86

Perfect. Thanks a lot

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.