Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/25/2018 in all areas

  1. Hi guys, i.e: previous codes with formatted BBcode tags became messy & erroneous! example: erroneous code copied from forum (setq [b] [color="blue"] pl [/color][/b]'((10. 50.)(20. 50.)(30. 50.)(40. 50.)(50. 50.))[color="green"]; point list[/color] ss ([color="blue"] ssget [/color] (append ([color="blue"] [b]vl-list*[/b] [/color] '(0 . [color="purple"] "CIRCLE,TEXT,INSERT" [/color] ) [color="green"]; filter [/color] '(-4 . "<OR")(apply 'append (mapcar ''((x) (list '(-4 . [color="purple"] "=,=,*" [/color] ) (cons 10 x))) [b] pl [/b])) ) '((-4 . "OR>")) ) ) ) ) After BB codes removed which contents within the brackets "[" "]". (setq pl '((10. 50.)(20. 50.)(30. 50.)(40. 50.)(50. 50.)); point list ss ( ssget (append ( vl-list* '(0 . "CIRCLE,TEXT,INSERT" ) ; filter '(-4 . "<OR")(apply 'append (mapcar ''((x) (list '(-4 . "=,=,*" ) (cons 10 x))) pl )) ) '((-4 . "OR>")) ) ) ) ) ATM i could only edit for single post using this simple code merely remove contents within the brackets "[" "]". Hope this help? here's is very basic idea with minimal error handling. you can put addition ideas in cond etc.. (defun c:forum (/ cbdata *error* $ fn fi fo l) ; example: [B] hanhphuc [/B] [Color=blue] defun [/color] ;; command: forum or command: BBCU (abbreviation of BBCode Unformat) - hanhphuc ;; babe see you (defun *error* (msg) (if fi (close fi))) ;;;http://www.theswamp.org/index.php?topic=21764.msg263322#msg263322 (defun cbdata (/ cb html) ;optimized hp (setq cb (vl-catch-all-apply 'vlax-invoke (list ((lambda (doc) (foreach x '(parentwindow clipboarddata) (setq doc (vlax-get doc x)) ) ) (setq html (vlax-create-object "htmlfile")) ) 'getdata "text" ) ) ) (vlax-release-object html) (if (not (vl-catch-all-error-p cb) ) cb ) ) (and (setq fn (strcat (getvar 'tempprefix) "tmp.txt") fi (open fn "w") ) (setq $ (cbdata)) (write-line $ fi) (progn (close fi) (setq fi (open fn "r"))) (while (setq $ (read-char fi)) (setq l (cons $ l))) (progn (if fi (close fi) ) (setq fn (strcat (getvar 'tempprefix) "cadtutor.lsp")) (setq fo (open fn "w")) ) (foreach x (vl-remove-if '(lambda ( x )(or (listp x) (> x 191 ))) (read (strcat "(" (apply 'strcat (mapcar '(lambda (x) (strcat (if (numberp x) (cond ((= 91 x) "(") ((= 93 x) ")") (t (itoa x)) ) x ) " " ) ) (reverse l) ) ) ")" ) ) ) (write-char x fo) ) (progn (if fo (close fo) ) (findfile fn) ) (vl-cmdf "_.SHELL" (strcat "CLIP < " fn )) (alert "[BBCode Tags] removed! Try [Ctrl^C] in the forum!") ) (princ) ) (defun c:BBCU () (c:forum)(princ)) Step 1.save the above lisp, save in your valid path. APPLOAD in ACAD active drawing. 2.copy any 'infected' codes from forum 3.load this "forum.lsp" invoke --> command: BBCU or command: forum 4. simply paste it back to forum active editor (for coders - if you wanna to modify your previous code) for user - paste it to notepad etc.. save your file as '*.lsp' extension. e.g: 'cadtutor.lsp' Any ideas for multiple editing? RegEx ? Here's another alternative removing color tags using Notepad++ by Lee Mac
    1 point
  2. It wouldn't be so bad if the icons remained consistent across versions. Every so often, though, they completely change the iconography. Just when you learn what all the little buttons do, they turn into different buttons.
    1 point
  3. I had the same thought as hanhphuc since the forum updates, about the "old" forum code tags. However didn't had enough time to practice, but now managed to get some. So this is a variation of Lee's stripcomments that uses regex (I had a hard time to figure out the regex pattern) : ; (StripForumCodeTags (getfiled "Specify LISP file" (strcat (getenv "userprofile") "\\Desktop\\") "lsp" 16)) ; StripForumCodeTags is a variation routine of the "stripcomments" one by Lee Mac https://www.theswamp.org/index.php?topic=53746.30 (Get rid of comments) (defun StripForumCodeTags ( lsp / des rgx rtn str tmp ) (if (and (eq 'STR (type lsp)) (setq des (open lsp "r"))) (progn (while (setq str (read-line des)) (setq tmp (vl-list* "\n" str tmp))) (close des) (cond ( (null (setq rgx (vlax-create-object "vbscript.regexp"))) (prompt "\nUnable to interface with RegEx object.") ) ( (vl-catch-all-error-p (setq rtn (vl-catch-all-apply (function (lambda ( ) (foreach x '(Global Multiline Ignorecase) (vlax-put-property rgx x acTrue) ); foreach (vlax-put-property rgx 'pattern (strcat ; \[\s*\w*\s*=\s*"\s*\w*\s*"\s*\]|\[\s*/*\s*[a-z]\s*\]|\[\s*/*\s*\w*\s*\] "\\[\\s*\\w*\\s*=\\s*\"\\s*\\w*\\s*\"\\s*\\]" "|" "\\[\\s*\/*\\s*[a-z]\\s*\\]" "|" "\\[\\s*\/*\\s*\\w*\\s*\\]" ); strcat ); vlax-put-property (vlax-invoke rgx 'replace (apply 'strcat (reverse tmp)) "") ) ) ) ) ) (prompt (strcat "\nError: " (vl-catch-all-error-message rtn))) ) ( (princ rtn) ) ) ) (princ "\nUnable to read the file.") ) (and (eq 'VLA-OBJECT (type rgx)) (vl-catch-all-apply (function vlax-release-object) (list rgx))) (princ) ); defun StripForumCodeTags And a sample code that I tested: (defun [b][i][u]C:SampleCode[/b][/i][/u] ( / str SS i e o ) ; unformat forum code tags, example ; [I][u][B] Grrr [/B][/u][ / I ] [ color = " blue " ] sample defun [ / color ] ([ color = " blue " ]cond[ / color ] ( (not (setq str (getstring [ color = " purple " ]"\nSpecify a string: "[ / color ]))) (prompt "\nBye") ) ( (= "" str) (prompt "\nBYE!") ) ( (setq SS (ssget [color="purple"]"_:L-I"[/color] '(0 . "*TEXT"))) (repeat (setq i (sslength SS)) (and (setq e (ssname SS (setq i (1- i)))) (setq o (vlax-ename->vla-object e)) (if (vlax-property-available-p o 'TextString) (vlax-put-property o 'TextString str)) )[color="green"]; and [/color] )[color="green"]; repeat [/color] )[ color = "green" ]; setq SS [/color] )[ color = "green" ]; cond [/ color ] )[ color = "green" ]; defun [B][I][U]C:SampleCode[/B][/I][/U] [ / color ] [ color = " blue " ] [color="green"] [ attribute = " value " ] ; something [attribute="value"] [ font = " arial " ] [font="arial"] [ color = " blue " ] [color="green"] [/color] [ / color ] [/whatever] [ / whatever ] [b][i][u] [ / i ] [ / u ] [ / b ] [a] [ a ] [k] [ k ] [ / a ] [ / k ] [ ] [ / ] that will yield result of: (defun C:SampleCode ( / str SS i e o ) ; unformat forum code tags, example ; Grrr sample defun (cond ( (not (setq str (getstring "\nSpecify a string: "))) (prompt "\nBye") ) ( (= "" str) (prompt "\nBYE!") ) ( (setq SS (ssget "_:L-I" '(0 . "*TEXT"))) (repeat (setq i (sslength SS)) (and (setq e (ssname SS (setq i (1- i)))) (setq o (vlax-ename->vla-object e)) (if (vlax-property-available-p o 'TextString) (vlax-put-property o 'TextString str)) ); and ); repeat ); setq SS ); cond ); defun C:SampleCode ; something So you can get an idea of what "stuff" it gets rid off.. NOTE that one must be careful with the square brackets in his .lsp code, that are usually used within ssget/wcmatch patterns or regex (inception). Cheers!
    1 point
  4. Hi hanhphuc Here is my program to reform the AutoLISP codes regardless of the file format if it is .lsp or .txt reform.LSP
    1 point
×
×
  • Create New...