本帖最后由 zhb236623 于 2011-12-26 14:49 编辑
修改完的程序。
-
- ;;程序中的字符串哪里来的?我有个从cad中复制到剪切板的。
- ;;;=================================================================*
- ;;;功能:向系统剪贴板写入文字 *
- (defun ZML-CLIP-SETSTRING (STR / HTML RESULT)
- (and (= (type STR) 'STR)
- (setq HTML (vlax-create-object "htmlfile"))
- (setq RESULT (vlax-invoke
- (vlax-get (vlax-get HTML 'PARENTWINDOW)
- 'CLIPBOARDDATA
- )
- 'SETDATA
- "Text"
- STR
- )
- )
- (vlax-release-object HTML)
- )
- )
- ;;;=================================================================*
- ;;函数测试
- (defun c:cc ()
- (vl-load-com)
- (setq ss (ssget '((0 . "*TEXT"))))
- (setq i 0)
- (setq last_stri_str "")
- (repeat (sslength ss)
- (setq txtcon (cdr (assoc 1 (entget (ssname ss i)))))
- (setq txtcon_kuohao (strcat "(" txtcon ")"))
- (setq last_stri (vl-prin1-to-string txtcon_kuohao))
- (setq last_stri_str (strcat last_stri_str last_stri))
- (setq i (1+ i))
- )
- (setq str0 (getvar "DwgName") ;"宗地图.dwg"
- str0 (substr str0 1 )
- ) ;"宗地图"
- (setq str1 (vl-string-translate "/" "-" last_stri_str))
- (setq str2 (vl-string-translate "\"" " " str1))
- (while (> (strlen str2) (strlen (setq str2 (vl-string-subst "" " " str2))))) ;;加了这句就可以了。
- (setq str0 (vl-string-subst "" ".dwg" str0)) 。
- (setq str3 (strcat str0 str2))
- (ZML-CLIP-SETSTRING str3)
- (princ "\n文字已复制到剪切板,可以直接粘贴了!")
- (princ)
- )
- ;;(while (> (strlen str) (strlen (setq str (vl-string-subst "" " " str)))))
- (defun c:c1 ()
- (vl-load-com)
- (setq ss (ssget '((0 . "*TEXT"))))
- (setq i 0)
- (setq last_stri_str "")
- (setq last_stri_hanzi "")
- (repeat (sslength ss)
- (setq txtcon (cdr (assoc 1 (entget (ssname ss i)))))
- (if (> (ascii txtcon) 175)
-
- (progn
- (setq txtcon_hanzi txtcon)
- (setq last_stri_hanzi (strcat last_stri_hanzi txtcon "、"))
- )
- (progn
- (setq txtcon_kuohao (strcat "(" txtcon ")"))
- (setq last_stri (vl-prin1-to-string txtcon_kuohao))
- (setq last_stri_str (strcat last_stri_str last_stri))
-
- )
- )
- (setq i (1+ i))
- )
- (setq str1 (vl-string-translate "/" "-" last_stri_str))
- (setq str2 (vl-string-translate "\"" " " str1))
- (while (> (strlen str2) (strlen (setq str2 (vl-string-subst "" " " str2))))) ;;加了这句就可以了。
- (setq str3 (strcat last_stri_hanzi str2))
- (ZML-CLIP-SETSTRING str3)
- (princ "\n文字已复制到剪切板,可以直接粘贴了!")
- (princ)
- )
- (defun c:c2 ()
- (vl-load-com)
- (setq txtss (ssget '((0 . "*TEXT"))))
- (while (> (sslength txtss) 1)
- (alert "只能选择一个文字串,请重新选择!")
- (setq txtss (ssadd))
- (setq txtss (ssget '((0 . "*TEXT"))))
- )
- (setq txtcon (cdr (assoc 1 (entget (ssname txtss 0)))))
- (setq ent_str_last (vl-string-translate "/" "-" txtcon))
- (setq ent_str_last_kuahao (strcat "(" ent_str_last ")"))
- (ZML-CLIP-SETSTRING ent_str_last_kuahao)
- (princ "\n文字已复制到剪切板,可以直接粘贴了!")
- (princ)
- ) ;;end defun
|