Jump to content
hanhphuc

New forum Code Tags

Recommended Posts

hanhphuc

Hi does anyone notice that the previous codes (with format) become messy in this new forum code tags.

Im not sure the forum moderators able to overcome this issue otherwise (formatted) codes copied from forum get error!

 

ATM i could only edit for single post using simple code merely remove  contents within the brackets "[" "]".  Hope this help?

 

example: 

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.

(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>"))
  ) 
) 
)
)

 

 

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) ; unformat forum BBcode tags, example: [B] hanhphuc [/B] [Color=blue] defun [/color]

;;;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 )
  )

  (defun *error* (msg) (if fi (close fi)))
  
  (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
		    ''( ( x )(or (listp x) (> x 191 )))
		    (read (strcat "("
				  (apply 'strcat
					 (mapcar ''((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)
  )

 

Step 
1.copy codes from forum, save in *.txt file, example "c:\\user\\CAD\\input.txt"
2.load this "forum.lsp" invoke --> command: forum
3. copy new contents from "cadtutor.lsp" (tags removed), simply paste it back to forum active editor 

 

Any ideas for multiple editing? RegEx ? 

 

Edited by hanhphuc
Code updated with clipboard function
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Tharwat

Hi hanhphuc

Here is my program to reform the AutoLISP codes regardless of the file format if it is .lsp or .txt :)

reform.LSP

  • Thanks 1

Share this post


Link to post
Share on other sites
hanhphuc
4 hours ago, Tharwat said:

Hi hanhphuc

Here is my program to reform the AutoLISP codes regardless of the file format if it is .lsp or .txt :)

reform.LSP

 


as usual Tharwat another way to skin the cat :)
               

It maybe difficult for them (novice or anyone knows nothing/little about Lisp) to debug or unformat these old forum codes.

Hope this thread helps members who maybe have copied 'formated' codes from this forum.

 

since my simple methodology is just to remove brackets "[ ]" , the hiccup if brackets in the prompt string example: 

(getkword "Enter [Yes/No] ? <Y> : ")

i follow your idea to save output as lisp :)

 

Share this post


Link to post
Share on other sites
Grrr

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). :lol:

 

Cheers! :beer:

Edited by Grrr
  • Like 2

Share this post


Link to post
Share on other sites
CADTutor

Thanks for the work guys. We have noticed a few problems with code in moving to the new forum. It didn't help that there was a bug in the code translation programme 🙄 But there has also been a character set translation from Latin1 to UTF-8. As you may know, UTF-8 is the new (actually not so new) universal character set standard on the Web. So at least we are now operating with a modern, universal character set. It's difficult to predict what sort of issues this may have thrown up so it's a good policy always to check any old scripts before you use them or recommend them to novices.

 

I've pinned this topic as it will be useful in the future. 👍

  • Thanks 3

Share this post


Link to post
Share on other sites
hanhphuc
On 9/25/2018 at 10:14 PM, Grrr said:

 

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). 

 

1+




(defun StripForumCodeTags ...

[/Code]

My 'listp' fix limitation brackets must be 'paired' otherwise error missing or extra parentheses.

@Grrr thanks, RegEx literally fixes regardless brackets not paired.

 

another issue is to fix missing fuzz '1e-8)' due to the new code tags do not support smiley '8)'  or '8 )' ?

Append '1e' with '-7)'  or '-9)'

 

Cheers 🍻

 

 

Edited by hanhphuc

Share this post


Link to post
Share on other sites
Grrr
Posted (edited)

[BBC] 2 <HTML>

 

Hey guys,

I had fun today, while assembling this:

 


(defun C:BBC2HTML nil
  (BBC2HTML (getfiled "Specify LISP file" (strcat (getenv "userprofile") "\\Desktop\\TestFolder\\") "bbc;lsp;txt" 16))
  (princ)
); defun C:BBC2HTML

; https://www.cadtutor.net/forum/topic/66065-new-forum-code-tags/
; <!-- BBC 2 HTML, assembled by Grrr, credits to Lee Mac -->
; Substitutes [color="???"][/color] [b][i][u] BBC tags with html ones
; and then it creates an unique .html file and opens it
; NOTE: one still has to be careful and must check where he did used square brackets for his lisp code [] ! - are usually used within ssget/wcmatch patterns or regex 
; 'src' - filepath that contains a BBC-formatted code
(defun BBC2HTML ( src / des rgx rtn str tmp r )
  (if (and (eq 'STR (type src)) (setq des (open src "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
                    (setq tmp (apply 'strcat (reverse tmp)))
                    (foreach x
                      '(
                        ("<" . "&lt")
                        (">" . "&gt")
                        ("\\[\\s*\/*\\s*(color)\\s*\\]" . "<\/font>")
                        ("\\[\\s*(color)\\s*=\\s*\"" . "<font color=\"")
                        ("\"\\s*\\]" . "\">")
                        ("\\[\\s*b\\s*\\]" . "<b>")
                        ("\\[\\s*i\\s*\\]" . "<i>")
                        ("\\[\\s*u\\s*\\]" . "<u>")
                        ("\\[\\s*\/\\s*b\\s*\\]" . "<\/b>")
                        ("\\[\\s*\/\\s*i\\s*\\]" . "<\/i>")
                        ("\\[\\s*\/\\s*u\\s*\\]" . "<\/u>")
                        ("\\[\\s*\/*(code)\\s*\\]" . "")("\\[\\s*(color)\\s*=\\s*" . "<font color=") ("\\s*\\]" . ">") ; for David Bethel's lsp2bbc
                      )
                      (vlax-put-property rgx 'Pattern (car x))
                      (setq tmp (vlax-invoke-method rgx 'Replace tmp (cdr x)))
                    ); foreach
                    tmp
                  ); lambda
                )
              )
            )
          )
          (prompt (strcat "\nError: " (vl-catch-all-error-message rtn)))
        )
        (rtn
          (princ
            (setq rtn
              (strcat 
                "\n<!-- Open this resulted 'html' file with IE/Chrome/Mozilla -->"
                "\n<!-- BBC 2 HTML, assembled by Grrr, credits to Lee Mac -->"
                "\n<html>"
                "\n<head><title>" (cadr (fnsplitl src)) "</title></head>"
                "\n<body>"
                "\n<div style=\"white-space: pre;\">"
                rtn
                "\n</div>"
                "\n</body>"
                "\n</html>"
              ); strcat
            ); setq rtn
            (setq des
              (open
                (setq tmp
                  ; (vl-filename-mktemp ; << not required, (I didn't knew this lol)
                  ( ; unique filename sub
                    (lambda (s / i tmp) 
                      (setq i 0)
                      (while (findfile (setq tmp (strcat s "_" (itoa i) ".html"))) (setq i (1+ i))) tmp
                    ); lambda
                    (apply (function (lambda (a b c) (vl-string-translate "/" "\\" (strcat a b)))) (fnsplitl src)) 
                  )
                  ; ); vl-filename-mktemp
                ); setq tmp
                "W"
              ); open
            ); setq des
          ); princ
          (close des)
          (princ (strcat "\nTemporary html file created at \"" tmp "\", don't forget to erase it.")) 
          (
            (lambda ( fpath / shell ) ; ShellOpen
              (if fpath
                (vl-catch-all-apply
                  (function
                    (lambda nil
                      (setq shell (vlax-get-or-create-object "Shell.Application"))
                      (vlax-invoke-method shell 'Open fpath)
                    )
                  )
                )
              )
              (vl-catch-all-apply 'vlax-release-object (list shell))
            ); lambda 
            tmp
          )
          (setq r rtn)
        ); 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 BBC2HTML

Basically it will attempt to replace the bold/underline/italic/color BBC tags with HTML ones (I'm not so familiar with bbc formatting, so I couldn't figure out any other tags).

Then it will create an unique .html file and open it with your browser to display the colored code.

Demo:

BBC-2-HTML.gif

 

 

I tested it with

• David Bethel's LSP2BBC,

• Lee Mac's LM:Lispstyler (BBC conversion),

• aswell some manual BBC modifications that you saw in the above posts

and it seems to work fine! Although still be careful with your square brackets [ ] in your lisp code!

Hm, now I see that the admins work on that issue!

🍺+🍺=🍻

Edited by Grrr
  • Like 2

Share this post


Link to post
Share on other sites
hanhphuc

Nice idea html idea not sure if work with unicode file? 

i tried another forum powered by Invision has independent color schema like:

[code=lisp] your code here [/code]

 

- avoid comment ,i.e: semi-colon ';'

- missing bracket if 8 is present  

- display weird function name

 

  • Thanks 1

Share this post


Link to post
Share on other sites
CADTutor

 

On 12/10/2018 at 05:36, hanhphuc said:

i tried another forum powered by Invision has independent color schema like:

[code=lisp] your code here [/code]

 

Interesting. Can you give me a link to that forum? I'd like to take a look and see how they've implemented that.

Share this post


Link to post
Share on other sites
hanhphuc
On 10/14/2018 at 3:39 PM, CADTutor said:

https://www.cadviet.com/forum/topic/174032-nhờ-các-bro-sửa-lips-cao-độ/?do=findComment&amp;comment=430352

 

Interesting. Can you give me a link to that forum? I'd like to take a look and see how they've implemented that.

 

Code Tags sample Here :)

 

p/s: i recall there was discussions regarding LISP code tags schema at theswamp.org but i couldn't find it now

Share this post


Link to post
Share on other sites
JRL5735

Well done guys. I've been looking for something like this for a while.

 

J. Logan

ACAD 2018

Share this post


Link to post
Share on other sites
hanhphuc

In fact my intention was simple, in order to clean up the [BBcodes] 
within the new code tags in this forum. 

 

Therefore, IMO optimized with CLIPBOARD without using 'getfiled' is much more convenient, isn't it? 

code updated - post#1

 

Copy text (from forum) ->  run 'FORUM'   (in ACAD) ->  [Ctrl+V] Paste (in forum active editor) Done!

 

bbc5.gif

Edited by hanhphuc
  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×