(ALE_String2List
(vl-string-left-trim
"{\\Q15.00;"
(vl-string-right-trim
"}"
"{\\Q15.00;DOUBLE BED\nperimeter 31.37336 m\narea 61.14046 m2\nvolume 550.26412 m3\nlateral surface 282.36021 m2\nheight 9.00000 m}"
)
)
"\n"
)
==> ("DOUBLE BED" "perimeter 31.37336 m" "area 61.14046 m2" "volume 550.26412 m3" "lateral surface 282.36021 m2" "height 9.00000 m")
; Marc'Antonio Alessi, Italy
;
; 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))
)\
(defun UnFormat2 ( str mtx / _replace rx )
; LM:UnFormat original code by Lee Mac modified in ***
(defun _replace ( new old str )
(vlax-put-property rx 'pattern old)
(vlax-invoke rx 'replace str new)
)
(if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
(progn
(setq str
(vl-catch-all-apply
(function
(lambda ( )
(vlax-put-property rx 'global actrue)
(vlax-put-property rx 'multiline actrue)
(vlax-put-property rx 'ignorecase acfalse)
(foreach pair
'(
("\032" . "\\\\\\\\")
(" " . "\\\\P|\\t") ; *** ex (" " . "\\\\P|\\n|\\t")
("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
("$1" . "[\\\\]({)|{")
)
(setq str (_replace (car pair) (cdr pair) str))
)
(if mtx
(_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
(_replace "\\" "\032" str)
)
)
)
)
)
(vlax-release-object rx)
(if (null (vl-catch-all-error-p str))
str
)
)
)
)
How did you get the \n in the MText? Isn’t it supposed to be \P ?someone gave me a DWG that contains MTEXTs that contain "\n"
if you don't want to modify original Lee's code, then do a temporary substitution with vl-string-translate before unformating and undo it afterwards
p.s. don't use \032 as a substitution character ;)
if you don't want to modify original Lee's code, then do a temporary substitution with vl-string-translate before unformating and undo it afterwards
p.s. don't use \032 as a substitution character ;)
I don't understand what you want mean ... sorry!
; thanks to Lee-mac for this defun
;renamed to suit delimeter value in this case -
(defun csv->lst45 ( str / pos )
(if (setq pos (vl-string-position 45 str))
(cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
(list str)
)
)
@xdcad
You can also add something like this as a utility to strip mtext formattingCode - C++: [Select]
//.formatted string AcValue acval(val); acutPrintf(acval.format(AcValue::kIgnoreMtextFormat));
@xdcad
You can also add something like this as a utility to strip mtext formattingCode - C++: [Select]
//.formatted string AcValue acval(val); acutPrintf(acval.format(AcValue::kIgnoreMtextFormat));
@xdcad
While passing by I noticed your function and had a few quick questions.Code - C++: [Select]
int MTextUnformat() { // Add function header!! // MTextUnformat // Unformats a text string. ... // // ARGS: // // RETURNS: resbuf* rb = ads_getargs(); if (!rb) { return RSRSLT; } AcDbObjectId id; const TCHAR* str = NULL; if (rb->restype == RTENAME) { // Should you consider // a separate function // to replace nested // if's below? if (acdbGetObjectId(id, rb->resval.rlname) == eOk) { AcDbMText* pMtext; if (acdbOpenObject(pMtext, id, kForRead) == eOk) { str = pMtext->contents(); pMtext->close(); } } } else if (rb->restype == RTSTR) { // Should this be IF? str = rb->resval.rstring; } else { // Is this ELSE needed? -i.e. checked already. return RSRSLT; } AcValue acval(str); ads_retstr(acval.format(AcValue::kIgnoreMtextFormat)); return RSRSLT; }
---->%
=============Code - C++: [Select]Supports two types of parameters, one is the MTEXT entity name, and the other is a formatted string
else if (rb->restype == RTSTR) { // Should this be IF? str = rb->resval.rstring; }
=============Code - C++: [Select]
else { // Is this ELSE needed? -i.e. checked already. return RSRSLT; }
If it is not an entity name or a string, other parameters given to the function will not be processed and will exit directly.
I would use a smart pointer for AcDbMText
Quote from: DanI would use a smart pointer for AcDbMText
Is it possible that a lot of this code was generated before smart pointers were available ??
[added]
. . . and the code base is probably used for multiple acad versions
[/added]
Would this be a case of "it's not broken so don't fix it" ?
or are there discernable advantages ?
Quote from: DanI would use a smart pointer for AcDbMText
Is it possible that a lot of this code was generated before smart pointers were available ??
[added]
. . . and the code base is probably used for multiple acad versions
[/added]
Would this be a case of "it's not broken so don't fix it" ?
or are there discernable advantages ?
Would this be a case of "it's not broken so don't fix it" ?This is a newly created function, you’re in the code, might as well improve it
This is a newly created function, you’re in the code, might as well improve it
QuoteThis is a newly created function, you’re in the code, might as well improve it
ahh, yes good point.
wait, wouldn't one of the old compliers spit the dummy ??
I don't have an R14 SDK