TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dubb on May 08, 2019, 06:39:43 PM
-
I am trying to end a while loop when vl-string-search is nil. Not sure what I'm missing here.
(defun c:foo( / txt)
;(setq txt (dos_editbox "Editor" "Enter some text" ""))
(setq txt "alpha\tbravo\ncharlie\tdelta")
(while
(princ (substr txt 1 (vl-string-search "\t" txt)))
(setq txt (substr txt (+ 2 (vl-string-search "\t" txt)) (strlen txt)))
(princ(substr txt 1 (vl-string-search "\n" txt)))
(setq txt (substr txt (+ 2 (vl-string-search "\n" txt)) (strlen txt)))
)
(princ)
)
-
You probably wanted to print on text screen something like this :
(defun c:foo ( / txt )
;(setq txt (dos_editbox "Editor" "Enter some text" ""))
(setq txt "alpha\tbravo\ncharlie\tdelta")
(while (or (vl-string-search "\t" txt) (vl-string-search "\n" txt))
(if (vl-string-search "\t" txt)
(progn
(princ (strcat "\n" (substr txt 1 (vl-string-search "\t" txt))))
(setq txt (substr txt (+ 2 (vl-string-search "\t" txt))))
)
(princ (strcat "\n" txt))
)
(if (vl-string-search "\n" txt)
(progn
(princ (strcat "\n" (substr txt 1 (vl-string-search "\n" txt))))
(setq txt (substr txt (+ 2 (vl-string-search "\n" txt))))
)
(princ (strcat "\n" txt))
)
)
(princ)
)
-
purrrfect! Thank you bro!
Here is my script.
Quickdwgprops
Will add custom dwgprops by copying two columns on a spreadsheet and pasting into the dialog box.
Free to distribute and modify.
Dependencies from dos_lib required.
;quickdwgprops
;remove all custom dwgprops
;copy two columns from spreadsheet
;paste into notes dialogue box
;dependencies: dos_lib
(defun c:qdw ( / txt name value)
(cd:DWG_RemoveCustomProp (cd:ACX_ADoc) T)
(setq txt (dos_editbox "Editor" "Enter some text" "")) ;dos_lib depencies
; (setq txt "alpha\tbravo\ncharlie\tdelta")
(while (or (vl-string-search "\t" txt) (vl-string-search "\n" txt))
(if (vl-string-search "\t" txt)
(progn
(setq name (substr txt 1 (vl-string-search "\t" txt)))
(setq txt (substr txt (+ 2 (vl-string-search "\t" txt))))
)
(setq name txt)
);end if
(if (vl-string-search "\n" txt)
(progn
(setq value (substr txt 1 (vl-string-search "\n" txt)))
(setq txt (substr txt (+ 2 (vl-string-search "\n" txt))))
)
(setq value txt)
);end if
(addp name value)
);end while
(princ)
)
;add dwgprops function
(defun addp (FieldName FieldValue / acadObj acDoc acDocSumInfo)
(vl-load-com)
(setq acadObj (vlax-get-acad-object))
(setq acDoc (vlax-get-property acadObj 'ActiveDocument))
(setq acDocSumInfo (vlax-get-property acDoc 'SummaryInfo))
(vlax-invoke-method acDocSumInfo 'AddCustomInfo FieldName FieldValue)
)
; =========================================================================================== ;
; Usuwa wlasciwosci uzytkownika / Removes custom drawing properties ;
; Doc [VLA-Object] - document / document ;
; Mode [LIST/T] - LIST = lista wlasciwosci do usuniecia / list of properties to remove ;
; T = usuwa wszystkie wlasciwosci / removes all properites ;
; ------------------------------------------------------------------------------------------- ;
; (cd:DWG_RemoveCustomProp (cd:ACX_ADoc) (list "One" "Two")) ;
; =========================================================================================== ;
(defun cd:DWG_RemoveCustomProp (Doc Mode / si)
(setq si (vla-get-SummaryInfo Doc))
(if (listp Mode)
(foreach % Mode
(vl-catch-all-apply
(quote vla-RemoveCustomByKey)
(list si %)
)
)
(foreach % (mapcar (quote car) (cd:DWG_GetCustomProp Doc))
(vla-RemoveCustomByKey si %)
)
)
)
; =========================================================================================== ;
; Aktywny dokument / Active document ;
; =========================================================================================== ;
(defun cd:ACX_ADoc ()
(or
*cd-ActiveDocument*
(setq *cd-ActiveDocument*
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)
*cd-ActiveDocument*
)
; =========================================================================================== ;
; Lista wlasciwosci uzytkownika / Custom drawing properties ;
; Doc [VLA-Object] - document / document ;
; ------------------------------------------------------------------------------------------- ;
; (cd:DWG_GetCustomProp (cd:ACX_ADoc)) ;
; =========================================================================================== ;
(defun cd:DWG_GetCustomProp (Doc / si n k v lst)
(setq si (vla-get-SummaryInfo Doc)
n (vla-NumCustomInfo si)
)
(while (> n 0)
(vla-GetCustomByIndex si (- n 1) 'k 'v)
(setq lst (cons (cons k v) lst)
n (1- n)
)
)
lst
)
You probably wanted to print on text screen something like this :
(defun c:foo ( / txt )
;(setq txt (dos_editbox "Editor" "Enter some text" ""))
(setq txt "alpha\tbravo\ncharlie\tdelta")
(while (or (vl-string-search "\t" txt) (vl-string-search "\n" txt))
(if (vl-string-search "\t" txt)
(progn
(princ (strcat "\n" (substr txt 1 (vl-string-search "\t" txt))))
(setq txt (substr txt (+ 2 (vl-string-search "\t" txt))))
)
(princ (strcat "\n" txt))
)
(if (vl-string-search "\n" txt)
(progn
(princ (strcat "\n" (substr txt 1 (vl-string-search "\n" txt))))
(setq txt (substr txt (+ 2 (vl-string-search "\n" txt))))
)
(princ (strcat "\n" txt))
)
)
(princ)
)