Author Topic: Ethics on combing 2 lisp routines diff. authors and got a better Background Mask  (Read 8079 times)

0 Members and 1 Guest are viewing this topic.

sourdough

  • Bull Frog
  • Posts: 367
Do you have a directory on your computer where you keep all your lisp's? If not, make one. Mine is in
"My Documents\Programing\AutoLisp" But you can make it where ever you want.

Then go grab this program:
[ http://www.theswamp.org/index.php?topic=26914.0 ]

Unzip and take the exe from the bin directory and put in your programing directory (mine is located here: "My Documents\Programing\AutoLisp") You can trash the rest if you want, all that is left is the manual and the source code; you dont need that.

next double click the exe and a new directory will be created for you called "lsp_proj" rename it to what (What do you want to call this program)?

Okay did the directory, I have tons of lisp routines from the last 10+ years. I understand the order of things for this. A name would TBM, I think it has a ring to it.

MJP
LDC 2009/C3D 2010/C3D 2011/C3D 2016

Win 10 64bit

JohnK

  • Administrator
  • Seagull
  • Posts: 10649
Ok, I'll name mine the same in the morning. BTW, i forgot to mention that you need to rename the "main.lsp" to "TBM.lsp".

Do you want to do the Pseudo code or would you like me to?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

sourdough

  • Bull Frog
  • Posts: 367
Hi
   Got your message this morning and responded there. Yes, to you doing the code. Time is precious right now.
I'm also in the throws of a second project in C3D and learning new aspects. So, whatever you can do to make it
better please do. Where is the Main.lsp you are referring to.

MJP
Mike
LDC 2009/C3D 2010/C3D 2011/C3D 2016

Win 10 64bit

JohnK

  • Administrator
  • Seagull
  • Posts: 10649
We'll pick this up when you have more time.

Here is a shortened version (i think) of what you posted. I say "I think" cause i trimmed it down from 300 to 40 lines of code so i think i might be missing something (or several) features. I hope not but, we'll see.

Code: [Select]
(defun c:tbm ( / ssMtext doffset ent)
  (defun sel2lst ( sel / l len )
    ;; convert SELection set to LiST of e-names
    ;; Vladimir Nesterovsky
    ;; 04/30/96 03:40:05
    (if (= 'PICKSET (type sel))
      (repeat (setq len (sslength sel))
              (setq len (1- len) l (cons (ssname sel len) l)))))
  (setq ssMtext (ssget '((-4 . "<OR") (0 . "MTEXT") (-4 . "OR>")))
        ssMtext (sel2lst ssMtext))
  (foreach x ssMtext
              (setq ent (entget x))
              ;; If no background fill exsists
              (if (< (cdr (assoc 90 ent)) 3)
                (progn
                  (if (null doffset)
                    (setq doffset
                          (cond
                            ((getreal
                               (strcat
                                 "\nSpecify border offset factor [1.5]: ")))
                            (1.5)))
                    )
                  ;; mask not present set it.
                  (setq ent (append ent (list (cons 90 3))))
                  (setq ent (append ent (list (cons 63 256))))
                  (setq ent (append ent (list (cons 45 doffset))))
                  (setq ent (append ent (list (cons 441 0))))
                  )
                ;; mask present, kill
                (setq ent (subst  (cons 90 2) (assoc 90 ent) ent))
                )
              (entmod ent)
              ;; write the ent
              )
  (command "draworder" "p" "" "front")
  ;;;    (Princ "\nThe Masking is complete.")
  (princ)
 )
(princ "\nEnter \"TBM\" to start mask routine.")

Hope this works for ya; i took an ultra simplified approach to this and redid the whole thing.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

sourdough

  • Bull Frog
  • Posts: 367
We'll pick this up when you have more time.

Here is a shortened version (i think) of what you posted. I say "I think" cause i trimmed it down from 300 to 40 lines of code so i think i might be missing something (or several) features. I hope not but, we'll see.

Code: [Select]
(defun c:tbm ( / ssMtext doffset ent)
  (defun sel2lst ( sel / l len )
    ;; convert SELection set to LiST of e-names
    ;; Vladimir Nesterovsky
    ;; 04/30/96 03:40:05
    (if (= 'PICKSET (type sel))
      (repeat (setq len (sslength sel))
              (setq len (1- len) l (cons (ssname sel len) l)))))
  (setq ssMtext (ssget '((-4 . "<OR") (0 . "MTEXT") (-4 . "OR>")))
        ssMtext (sel2lst ssMtext))
  (foreach x ssMtext
              (setq ent (entget x))
              ;; If no background fill exsists
              (if (< (cdr (assoc 90 ent)) 3)
                (progn
                  (if (null doffset)
                    (setq doffset
                          (cond
                            ((getreal
                               (strcat
                                 "\nSpecify border offset factor [1.5]: ")))
                            (1.5)))
                    )
                  ;; mask not present set it.
                  (setq ent (append ent (list (cons 90 3))))
                  (setq ent (append ent (list (cons 63 256))))
                  (setq ent (append ent (list (cons 45 doffset))))
                  (setq ent (append ent (list (cons 441 0))))
                  )
                ;; mask present, kill
                (setq ent (subst  (cons 90 2) (assoc 90 ent) ent))
                )
              (entmod ent)
              ;; write the ent
              )
  (command "draworder" "p" "" "front")
  ;;;    (Princ "\nThe Masking is complete.")
  (princ)
 )
(princ "\nEnter \"TBM\" to start mask routine.")

Hope this works for ya; i took an ultra simplified approach to this and redid the whole thing.


This is awesome, it does it all. My only pref. is that the default be 1.15 to keep it close to the text outline.
But, you did it all (Toggle-Background Mask and multi-selection). Now, I'm going to study what you did and learn.

Many Thanks
MJP
Mike
LDC 2009/C3D 2010/C3D 2011/C3D 2016

Win 10 64bit

JohnK

  • Administrator
  • Seagull
  • Posts: 10649
Change those 1.5's to 1.15's in the COND statement and that's done. However, CAB may have a few good improvements for us. 
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
We'll pick this up when you have more time.

Here is a shortened version (i think) of what you posted. I say "I think" cause i trimmed it down from 300 to 40 lines of code so i think i might be missing something (or several) features. I hope not but, we'll see.

Hope this works for ya; i took an ultra simplified approach to this and redid the whole thing.


This is awesome, it does it all. My only pref. is that the default be 1.15 to keep it close to the text outline.
But, you did it all (Toggle-Background Mask and multi-selection). Now, I'm going to study what you did and learn.

Many Thanks
MJP
Mike

It works for me, the only hiccup (and maybe is not a hiccup) is that it allowed the user to select multiple text entities but only the first entity selected was toggled. The rest were ignored.   Much more efficient than Lee's by less enter key strokes to get thru.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

JohnK

  • Administrator
  • Seagull
  • Posts: 10649
I cant reproduce that error.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Just some minor modifications:
Code: [Select]
(defun c:tbm (/ ssMtext MtextList doffset ent x)
  (and (setq ssMtext (ssget '((-4 . "<OR") (0 . "MTEXT") (-4 . "OR>"))))
       (setq MtextList (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssMtext))))
  )
  (foreach x MtextList
    (setq ent (entget x))
    ;; If no background fill exist
    (if (< (cdr (assoc 90 ent)) 3)
      (progn
(or doffset
  (setq doffset
(cond
   ((getdist "\nSpecify border offset factor [1.15]: "))
   (1.15) ; default here
)
  )
)
;; mask not present set it.
(setq ent (append ent (list '(90 . 3) '(63 . 256)(cons 45 doffset) '(441 . 0))))
      )
      ;; mask present, kill
      (setq ent (subst (cons 90 2) (assoc 90 ent) ent))
    )
    (entmod ent)
    ;; write the ent
  )
  (and ssMtext (command "draworder" ssMtext "" "front"))
;;;    (Princ "\nThe Masking is complete.")
  (princ)
)
(princ "\nEnter \"TBM\" to start mask routine.")

<edit: bug fix>
« Last Edit: March 18, 2009, 03:22:17 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Jumped on this a little today at lunch, didn't add multi select but I did add color background colors.

Code: [Select]
;;; ------------------------------------------------------------------------
;;;    TEXT_BMASK.lsp v2.0
;;;
;;;    Copyright © March 16, 2009
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;;    THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;    WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;    PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE
;;;    PROGRAMMER.
;;;
;;; -----------------------------------------------------------------------
(defun C:BM (/ *error* OldCmdEcho BMaskOffset TextObj BMaskOffset BMaskColor TextElist)

;;; Begin Error Handler -------------------------------------------------
(defun *error* (MSG)

(if (not (member MSG '("Function cancelled" "quit / exit abort")))
(princ (strcat "\n*** Program Error: " (strcase MSG) " ***"))
(princ "\n... Program Cancelled ...")
)
(while (< 0 (getvar "cmdactive"))
(command)
)
(setvar "CMDECHO" OldCmdEcho)
)
;; Set variables
(setq OldCmdEcho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq BMaskOffset 2.0);<-- Set default offset

;; Get selection
(setq TextObj (car (entsel "\n Select MTEXT to mask or [ENTER] for Settings: ")))
(if (= (type TextObj) nil)
;; Set the settings
(progn
(setq BMaskOffset (getreal (strcat "\n Enter offset distance <" (rtos BMaskOffset 2 2) ">")))
(setq BMaskColor (acad_colordlg 256 T))
(setq TextObj (car (entsel "\n Select MTEXT to mask or [ENTER] for Settings: ")))
)
)
;; Get text entity list
(setq TextElist (entget TextObj))
;; Check for MTEXT
(if (not (= (cdr (assoc 0 TextElist)) "MTEXT"))
;; If not mtext, alert the user and restart
(progn
(alert "Selected entity is not MTEXT")
;; Reset variables
(setvar "CMDECHO" OldCmdEcho)
;; Restart the program
(C:BM)
)
;; If is mtext add/remove the mask
(progn
(if (or (= (cdr (assoc 90 TextElist)) 1)(= (cdr (assoc 90 TextElist)) 3))
(progn
(setq TextElist (subst (cons 90 2) (assoc 90 TextElist) TextElist))
(princ "\n Background fill removed")
)
(progn
(setq TextElist (subst (cons 90 3)(assoc 90 TextElist) TextElist))
(setq TextElist (append TextElist (list (cons 45 BMaskOffset))))
(princ "\n Background fill applied")
)
)
)
)
;; Check for a masking color
(if (and BMaskColor (< BMaskColor 256))
(progn
(setq TextElist (subst (cons 90 1) (assoc 90 TextElist) TextElist))
(setq TextElist (append TextElist (list (cons 63 BMaskColor))))
(setq TextElist (append TextElist (list (cons 441 0))))
)
)
;; Modify the enityt list
(entmod TextElist)
;; Set the draworder to bring text front
(command "draworder" TextObj "" "front")
;; Reset variables
(setvar "CMDECHO" OldCmdEcho)
(princ)
)
;;;
;;; Echos to the command line
(princ "\n BMask v2.0 ©Timothy Spangler, \n  March, 2009....loaded.")
(terpri)
(princ "C:BM")
(print)
;;; End echo


I will try to get time tonite to add multiselect and gripselect


BTW great code 7, CAB....
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

septicad

  • Guest
here is the version i wrote a while back... just another way to do it...  works well for me and it provides some feedback on the # of entities modified... just select everything and then the function cycles through the selection set toggling the mask on or off.... adding a line to modify the mask border could be added pretty easily. 

I screwed around with this for a while too and i found that the default mask size was acceptable under most circumstances, so what the point to add it to this function.  But its a good way to learn!

I borrow code from where ever i can find it! How much to i need to modify before It's my code?
 

Code: [Select]
;;;---------------------------------------------------------
;;;--- Toggle's background for mText entities --------------
;;;---------------------------------------------------------
(defun c:mtw (/ $CMDECHO ent obj sset1 sset2 newent cnt cnt2 cnt3)

;; get big selection set
  (setq sset1 nil)
  (if (= (last (ssgetfirst)) nil)
   ; IF
    (progn
      (prompt "\nSelect entities to Toggle Background Fill [only mText will be modified]:")
      (setq sset1 (ssget))
    )
   ; ELSE
    (setq sset1 (last (ssgetfirst)))
  )

 (if (/= sset1 nil)
    (progn

(setq $CMDECHO (getvar "CMDECHO"))
(setvar "CMDECHO" 0)

      ;; run through each entity selected
      (setq cnt -1 cnt2 0 cnt3 0)
      (while (< (setq cnt (1+ cnt)) (sslength sset1))
        (setq obj     (vlax-ename->vla-object (ssname sset1 cnt))
              ObjType (vla-get-ObjectName obj)
        )
        (cond
          ((= ObjType "AcDbMText")
            (setq cnt2 (1+ cnt2))
            (setq ent (ssname sset1 cnt))
            (if (= (vla-get-BackgroundFill obj) :VLAX-TRUE)
              ;;;--- IF TRUE - already filled
              (progn
               (vla-put-BackgroundFill obj :VLAX-FALSE)
               (vla-update obj)
               (setq cnt3 (1+ cnt3))
              )
              ;;;--- IF TRUE - already filled
              ;;;--- IF FALSE - no fill
              (progn
               (setq sset2 (ssadd))
               (ssadd ent sset2)

       (command "draworder" sset2 "" "F")
;;; ADD NEW CODE HERE;;;;
;;; TO MODIFY MASK BORDER;;;;
               (setq ent (entget ent))
               (if (= 1 (cdr(assoc 90 ent)))
                 (progn
                    (setq ent
                     (subst (cons 90 1)
                     (cons 90 3)
                     ent)
                    )
            (entmod ent)
                    (entupd (cdr(assoc -1 ent)))           
         )
         (progn
            (setq newent (append ent (list(cons 90 3))))
            (entmod newent)
                    (entupd (cdr(assoc -1 newent)))
         )
       )
              ;;;--- IF FALSE - no fill
          )
        )


          )

        )  ; end COND
      )   ; end WHILE

      (prompt
       (strcat "\nmText Background(s) Modified <"
       (rtos (- cnt2 cnt3) 2 0) " turned ON> "
       "<" (rtos cnt3 2 0) " turned OFF>\n")
      )

      (setvar "CMDECHO" $CMDECHO)

    ); end progn
  ); end if

(princ)
); end MTW
;;;---------------------------------------------------------
;;;---------------------------------------------------------

KewlToyZ

  • Guest
Just some minor modifications:
Code: [Select]
(defun c:tbm (/ ssMtext MtextList doffset ent x)
  (and (setq ssMtext (ssget '((-4 . "<OR") (0 . "MTEXT") (-4 . "OR>"))))
       (setq MtextList (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssMtext))))
  )
  (foreach x MtextList
    (setq ent (entget x))
    ;; If no background fill exist
    (if (< (cdr (assoc 90 ent)) 3)
      (progn
(or doffset
  (setq doffset
(cond
   ((getdist "\nSpecify border offset factor [1.15]: "))
   (1.15) ; default here
)
  )
)
;; mask not present set it.
(setq ent (append ent (list '(90 . 3) '(63 . 256)(cons 45 doffset) '(441 . 0))))
      )
      ;; mask present, kill
      (setq ent (subst (cons 90 2) (assoc 90 ent) ent))
    )
    (entmod ent)
    ;; write the ent
  )
  (and ssMtext (command "draworder" ssMtext "" "front"))
;;;    (Princ "\nThe Masking is complete.")
  (princ)
)
(princ "\nEnter \"TBM\" to start mask routine.")

<edit: bug fix>

Hello CAB,
I wanted to know where I would look up the codes for MTEXT.
Reading this line
Code: [Select]
(if (< (cdr (assoc 90 ent)) 3)
      (progn
(or doffset
  (setq doffset
So far it appears 90 is code of the list in MTEXT object variables?
MTEXT DXF Reference codes?
Note: I found 90 in the Developer Documentation. Thanks.
I was trying to do something similiar with just MTEXT colors in the contents of the MTEXT object properties.
I just wanted to set them bylayer or 0 for the color where for example it reads:
{\C2;100'-6"\PT.O. PARAPET}
« Last Edit: April 27, 2009, 05:16:24 PM by KewlToyZ »

KewlToyZ

  • Guest
After looking through them, I'm not sure it applies to content formatting of the text itself?

Quote
90
 Background fill setting:

0 = Background fill off

1 = Use background fill color

2 = Use drawing window color as background fill color
 
63
 Background color (if color index number)
 
420 - 429
 Background color (if RGB color)
 
430 - 439
 Background color (if color name)

347
 Hard-pointer ID/handle to material object (present if not BYLAYER)
 BYLAYER
 
62
 Color number (present if not BYLAYER); zero indicates the BYBLOCK (floating) color; 256 indicates BYLAYER; a negative value indicates that the layer is turned off (optional)

I wondered if 62 may be a place to start?
« Last Edit: April 27, 2009, 05:30:10 PM by KewlToyZ »