Jump to content

Compressing/Simplifying a Lisp


Aes

Recommended Posts

So I created a lisp to explode mtext and then justify it to it's previous justification before being exploded.

It works well, and doesn't take that long to run, but I was just wondering if there was a better way to go about writing it. It just seems clunky to me and I'm sure there is a better way than my novice attempt.

 

(defun c:XtoJ()
(setq UserQA (getvar "QAFLAGS"))
(setvar "QAFLAGS" 1)
(setq topleft (ssget "_X" '((0 . "MTEXT")(71 . 1))))		;Select TopLeft MTEXT
(command "._explode" topleft "")							;Explode TopLeft MTEXT
(setq middleleft (ssget "_X" '((0 . "MTEXT")(71 . 4))))	;Select MiddleLeft MTEXT
(command "._explode" middleleft "")						;Explode MiddleLeft MTEXT
(setq bottomleft (ssget "_X" '((0 . "MTEXT")(71 . 7))))	;Select BottomLeft MTEXT
(command "._explode" bottomleft "")						;Explode BottomLeft MTEXT
(setq lefttext (ssget "_X" '((0 . "TEXT")(72 . 0))))		;Select All Left Justified TEXT
(setq topright (ssget "_X" '((0 . "MTEXT")(71 . 3))))		;TopRight Start
(command "._explode" topright "")							;TopRight Explode
(setq topright (ssget "_X" '((0 . "TEXT")(72 . 0))))
(command "justifytext" topright "" "R")					;TopRight End
(command "justifytext" lefttext "" "L")					;Fix LeftText
(setq middleright (ssget "_X" '((0 . "MTEXT")(71 . 6))))	;MiddleRight Start
(command "._explode" middleright "")						;MiddleRight Explode
(setq middleright (ssget "_X" '((0 . "TEXT")(72 . 0))))
(command "justifytext" middleright "" "R")					;MiddleRight End
(command "justifytext" lefttext "" "L")					;Fix LeftText
(setq bottomright (ssget "_X" '((0 . "MTEXT")(71 . 9))))	;BottomRight Start
(command "._explode" bottomright "")						;BottomRight Explode
(setq bottomright (ssget "_X" '((0 . "TEXT")(72 . 0))))
(command "justifytext" bottomright "" "R")					;BottomRight End
(command "justifytext" lefttext "" "L")					;Fix LeftText
(setq topcenter (ssget "_X" '((0 . "MTEXT")(71 . 2))))		;TopCenter Start
(command "._explode" topcenter "")							;TopCenter Explode
(setq topcenter (ssget "_X" '((0 . "TEXT")(72 . 0))))
(command "justifytext" topcenter "" "C")					;TopCenter End
(command "justifytext" lefttext "" "L")					;Fix LeftText
(setq middlecenter (ssget "_X" '((0 . "MTEXT")(71 . 5))))	;MiddleCenter Start
(command "._explode" middlecenter "")						;MiddleCenter Explode
(setq middlecenter (ssget "_X" '((0 . "TEXT")(72 . 0))))
(command "justifytext" middlecenter "" "C")				;MiddleCenter End
(command "justifytext" lefttext "" "L")					;Fix LeftText
(setq bottomcenter (ssget "_X" '((0 . "MTEXT")(71 . )))	;BottomCenter Start
(command "._explode" bottomcenter "")						;BottomCenter Explode
(setq bottomcenter (ssget "_X" '((0 . "TEXT")(72 . 0))))
(command "justifytext" bottomcenter "" "C")				;BottomCenter End
(command "justifytext" lefttext "" "L")					;Fix LeftText
(setvar "QAFLAGS" UserQA)
)

Link to comment
Share on other sites

The notes were lined up in my text editor, didn't copy over very well though... I would edit it but for some reason forgot how to edit a post.

Link to comment
Share on other sites

I changed the code a little bit.

(defun c:XtoJ()

(setq UserQA (getvar "QAFLAGS"))

(setvar "QAFLAGS" 1)

(setq topleft (ssget "_X" '((0 . "MTEXT")(71 . 1)))) ;Select TopLeft MTEXT

(command "._explode" topleft "") ;Explode TopLeft MTEXT

(setq middleleft (ssget "_X" '((0 . "MTEXT")(71 . 4)))) ;Select MiddleLeft MTEXT

(command "._explode" middleleft "") ;Explode MiddleLeft MTEXT

(setq bottomleft (ssget "_X" '((0 . "MTEXT")(71 . 7)))) ;Select BottomLeft MTEXT

(command "._explode" bottomleft "") ;Explode BottomLeft MTEXT

(setq topright (ssget "_X" '((0 . "MTEXT")(71 . 3)))) ;TopRight Start

(command "._explode" topright "") ;TopRight Explode

(setq topright (ssget "P"))

(command "justifytext" topright "" "R") ;TopRight End

(setq middleright (ssget "_X" '((0 . "MTEXT")(71 . 6)))) ;MiddleRight Start

(command "._explode" middleright "") ;MiddleRight Explode

(setq middleright (ssget "P"))

(command "justifytext" middleright "" "R") ;MiddleRight End

(setq bottomright (ssget "_X" '((0 . "MTEXT")(71 . 9)))) ;BottomRight Start

(command "._explode" bottomright "") ;BottomRight Explode

(setq bottomright (ssget "P"))

(command "justifytext" bottomright "" "R") ;BottomRight End

(setq topcenter (ssget "_X" '((0 . "MTEXT")(71 . 2)))) ;TopCenter Start

(command "._explode" topcenter "") ;TopCenter Explode

(setq topcenter (ssget "P"))

(command "justifytext" topcenter "" "C") ;TopCenter End

(setq middlecenter (ssget "_X" '((0 . "MTEXT")(71 . 5)))) ;MiddleCenter Start

(command "._explode" middlecenter "") ;MiddleCenter Explode

(setq middlecenter (ssget "P"))

(command "justifytext" middlecenter "" "C") ;MiddleCenter End

(setq bottomcenter (ssget "_X" '((0 . "MTEXT")(71 . 8)))) ;BottomCenter Start

(command "._explode" bottomcenter "") ;BottomCenter Explode

(setq bottomcenter (ssget "P"))

(command "justifytext" bottomcenter "" "C") ;BottomCenter End

(setvar "QAFLAGS" UserQA)

)

Link to comment
Share on other sites

Oops, I quoted instead of code.

(defun c:XtoJ()
(setq UserQA (getvar "QAFLAGS"))
(setvar "QAFLAGS" 1)
(setq topleft (ssget "_X" '((0 . "MTEXT")(71 . 1))))		;Select TopLeft MTEXT
(command "._explode" topleft "")					;Explode TopLeft MTEXT
(setq middleleft (ssget "_X" '((0 . "MTEXT")(71 . 4))))	;Select MiddleLeft MTEXT
(command "._explode" middleleft "")				;Explode MiddleLeft MTEXT
(setq bottomleft (ssget "_X" '((0 . "MTEXT")(71 . 7))))	;Select BottomLeft MTEXT
(command "._explode" bottomleft "")				;Explode BottomLeft MTEXT
(setq topright (ssget "_X" '((0 . "MTEXT")(71 . 3))))		;TopRight Start
(command "._explode" topright "")				;TopRight Explode
(setq topright (ssget "P"))
(command "justifytext" topright "" "R")				;TopRight End
(setq middleright (ssget "_X" '((0 . "MTEXT")(71 . 6))))	;MiddleRight Start
(command "._explode" middleright "")				;MiddleRight Explode
(setq middleright (ssget "P"))
(command "justifytext" middleright "" "R")			;MiddleRight End
(setq bottomright (ssget "_X" '((0 . "MTEXT")(71 . 9))))	;BottomRight Start
(command "._explode" bottomright "")				;BottomRight Explode
(setq bottomright (ssget "P"))
(command "justifytext" bottomright "" "R")			;BottomRight End
(setq topcenter (ssget "_X" '((0 . "MTEXT")(71 . 2))))	;TopCenter Start
(command "._explode" topcenter "")				;TopCenter Explode
(setq topcenter (ssget "P"))
(command "justifytext" topcenter "" "C")				;TopCenter End
(setq middlecenter (ssget "_X" '((0 . "MTEXT")(71 . 5))))	;MiddleCenter Start
(command "._explode" middlecenter "")				;MiddleCenter Explode
(setq middlecenter (ssget "P"))
(command "justifytext" middlecenter "" "C")			;MiddleCenter End
(setq bottomcenter (ssget "_X" '((0 . "MTEXT")(71 . )))	;BottomCenter Start
(command "._explode" bottomcenter "")				;BottomCenter Explode
(setq bottomcenter (ssget "P"))
(command "justifytext" bottomcenter "" "C")			;BottomCenter End
(setvar "QAFLAGS" UserQA)
)

Link to comment
Share on other sites

Hi AES.

 

The edit message is at the bottom right of any posts you created. Another option is to make your new post, then suppress the old one (again by edit > delete).

 

Removing the ssget "text" was good, it removed some bugs, right?

One thing I could add, now that your code probably works as intended... you don't need to store "previous" in a variable in order to use it in your next command. Use it as is (You will see what I mean in my code). Also note how I used foreach with some commands instead of repeating each set of commands 9 times. I also made that all conditionnal IF a selection set is returned. some commands might not bomb if provided with nil as an argument, but it is a good practice to avoid it. It also prevent executing code uselessly. That could be shorten to that extent:

 

;Jef! 2017-06-12
(defun c:moo ( / tmp)
 (foreach itm (list '(1 . "TL") '(2 . "TC") '(3 . "TR")'(4 . "ML") '(5 . "MC") '(6 . "MR")'(7 . "BL") '(8 . "BC") '(9 . "BR"))
          (if (setq tmp (ssget "_X" (list '(0 . "MTEXT")(cons 71 (car itm)))))
              (and  (vl-cmdf "._explode" tmp "")
                    (vl-cmdf "._justifytext" "P" "" (cdr itm))
              )
          )
 )
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...