Author Topic: Attribute background mask  (Read 9455 times)

0 Members and 2 Guests are viewing this topic.

imbeer

  • Guest
Attribute background mask
« on: February 08, 2013, 06:09:24 AM »
Hello
I've got a block containing some multiline attributes.
I'd like to change background masks of those attributes via lisp (on/off, offset, color). But unfortunately I've got no idea how.
To be clear I could use some workaround like creating a set of blocks, but I'm really curious if it is possible to do that for a particular insert.
I managed to extract attribute from insert and dumped its properties to see which is responsible for masking, but I found nothing. Any help appreciated.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Attribute background mask
« Reply #1 on: February 08, 2013, 07:16:25 AM »
Welcome to the Swamp :-)

In my program here:

Change Line 110 from:
Code: [Select]
"_:L" ((0 . "MTEXT,MULTILEADER"))to:
Code: [Select]
"_:L" ((-4 . "<OR") (0 . "MTEXT,MULTILEADER") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>"))
And change the repeat expression at Lines 354 - 360 from:
Code: [Select]
(repeat (setq inc (sslength sel))
    (setq enx (entget (ssname sel (setq inc (1- inc)))))
    (if (= "MTEXT" (cdr (assoc 0 enx)))
        (_MTextFunction enx)
        (_MLeadFunction enx)
    )
)
to:
Code: [Select]
(repeat (setq inc (sslength sel))
    (setq ent (ssname sel (setq inc (1- inc)))
          enx (entget ent)
    )
    (cond
        (   (= "MTEXT" (cdr (assoc 0 enx)))
            (_MTextFunction enx)
        )
        (   (= "MULTILEADER" (cdr (assoc 0 enx)))
            (_MLeadFunction enx)
        )
        (   (setq ent (entnext ent)
                  enx (entget  ent)
            )
            (while (= "ATTRIB" (cdr (assoc 0 enx)))
                (if (member '(101 . "Embedded Object") enx)
                    (_MTextFunction enx)
                )
                (setq ent (entnext ent)
                      enx (entget  ent)
                )
            )
        )
    )
)

The above modifications will mean the program will alter the Background Mask for every Multiline Attribute found in every selected Block (in addition to MText & MLeaders).

The reason I didn't include this functionality in the original program is that without an additional prompt for tag selection or single object selection (e.g. using nentsel[p]), the program would change the background mask for ALL Multiline attributes, which may be undesired.

I may modify the program at some point in the future to include a DCL list box to allow the user to select the tags to be modified when attributed blocks containing multiline attributes are selected.

Finally, I would ask that you do not post the modified version of my program.

Dave M

  • Newt
  • Posts: 196
Re: Attribute background mask
« Reply #2 on: February 08, 2013, 10:37:21 AM »
Lee,
That would be a very nice improvement to an already great routine.  It would sure beat modifing blocks the long way.
Cheers!
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

imbeer

  • Guest
Re: Attribute background mask
« Reply #3 on: February 08, 2013, 10:38:46 AM »
Thanks for your answer Lee, I'm surprised I got what i wanted so fast ;)

I tried modified code and found out it has a glitch, at least combined with AutoCAD 2010.
It won't turn off mask when it is already set in block definition, because ActiveX seems not to recognize BackgroundFill property. I've worked it out though.

You've asked me not to post modified code of yours, still I'll share the actual function I need it for. I hope you don't mind I used a part of bmask.

Code: [Select]
; InsertBlock
;  Inserts a block in specified point and fills it with values from list.
;  Arguments:
;   blk - Block name.
;   lyr - Layer.
;   pt - Insertion point.
;   sc - Scale.
;   rt - Rotation.
;   lst - List of values to fill the block with, as (tag . value). Skip an attribute to leave it default.
;   bm - Background mask offset, less than 1.0 will turn mask off.
;  Returns VLA Insert Object.

(defun InsertBlock ( blk lyr pt sc rt lst bm / obj att el pair )
(if (or
(tblsearch "block" blk) ; block already loaded to the drawing
(setq blk (findfile (strcat blk ".dwg"))) ; swap block name with full path (or nil if block file doesnt exist)
)
(progn
; insert block
(setq obj (vla-insertblock
((if (eq (getvar "cvport") 1) vla-get-paperspace vla-get-modelspace)
(vla-get-ActiveDocument (vlax-get-acad-object))
)
(vlax-3D-point pt) ; insertion point
blk ; block name
sc ; scale X
sc ; scale Y
sc ; scale Z
rt ; rotation
))
; change layer (create if doesn't exist)
(if (not (tblsearch "layer" lyr)) (command "_.-layer" "_n" lyr ""))
(vla-put-layer obj lyr)
; upcase tags in lst
(setq lst (mapcar
(function (lambda ( pair )
(cons (strcase (car pair)) (cdr pair))
))
lst
))
; fill attributes
(foreach att (vlax-safearray->list (vlax-variant-value (vla-getattributes obj)))
; put value
(if (setq pair (assoc (strcase (vla-get-tagstring att)) lst))
(vla-put-textstring att (cdr pair))
)
; set background mask
(setq el (entget (vlax-vla-object->ename att)))
(if (member '(101 . "Embedded Object") el)
(entmod (append
; el without mask related pairs
(vl-remove-if
(function (lambda ( pair )
(member (car pair) '(45 63 90 421 431 441))
))
el
)
; new mask related pairs
(if (>= bm 1)
(list
(cons 90 3) ; background fill setting (transparent)
(cons 63 256) ; background color
(cons 45 bm) ; fill box scale
(cons 441 0) ; transparency of background fill
)
(list
(cons 90 2) ; background fill setting (off)
)
)
))
)
)
)
)
obj
)

DraxJDM

  • Newt
  • Posts: 47
Re: Attribute background mask
« Reply #4 on: April 08, 2013, 04:09:37 AM »
I like the attribute mask.

Like Lee said, it is only very practical if you can pick certain attribute from a block.

Athor question, is there a way to use the color "bylayer"? can be very handy ;)

Greetz John


jpcadconsulting

  • Newt
  • Posts: 56
Re: Attribute background mask
« Reply #5 on: September 16, 2015, 12:01:15 PM »
IMBEER, LEE,

I had the same problem after modifying MaskV1-1.lsp.  Works great to tun the mask on, but won't turn it off.

I'll admit, I'm having trouble understanding how to modify MaskV1-1.lsp based on your routine.  I'm respecting Lee Mac's wishes not to post the modified code, but any help on what to change/add etc. would be great.

Thanks guys,

-JP
Technology will save us all! *eyeroll*

jpcadconsulting

  • Newt
  • Posts: 56
Re: Attribute background mask
« Reply #6 on: September 16, 2015, 12:23:58 PM »
Actually. I have this routine which simply toggles the text mask on/off for anything selected (currently Dimensions, Text, Mtext and Mleaders)

Ideally, I'd love to modify this to include attributes within blocks.

As always, any help is appreciated.

Code: [Select]
(vl-load-com)
(defun c:TMask (/ ent entdata hnd i newentdata ob1 ss xdata)
  (if (setq ss (ssget "_:L" '((0 . "DIMENSION,MTEXT,MULTILEADER"))))
    (repeat (setq i (sslength ss))
      (setq hnd (ssname ss (setq i (1- i)))
            ent (entget hnd)
      )
      (cond ((wcmatch (cdr (assoc 0 ent)) "*TEXT")
             (setq ob1 (vlax-ename->vla-object hnd))
             (vlax-put ob1 'backgroundfill (~ (vlax-get ob1 'backgroundfill)))
            )
            ((= (cdr (assoc 0 ent)) "MULTILEADER")
             (setq ob1 (vlax-ename->vla-object hnd))
             (vlax-put ob1 'textbackgroundfill (~ (vlax-get ob1 'textbackgroundfill)))
            )
            (T
             (setq ent (entget hnd '("ACAD")))
             (if (or (not (setq xdata (assoc -3 ent)))
                     (and (setq xdata (assoc -3 ent))
                          (member '(1000 . "DSTYLE") (last xdata))
                          (/= (cdr (assoc 1070 (reverse (last xdata)))) 1)
                          (setq ent (vl-remove-if '(lambda (x) (= -3 (car x))) ent))
                     )
                 )
               (setq entdata    '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 1) (1002 . "}"))))
                     newentdata (append ent entdata)
               )
               (setq ent        (vl-remove-if '(lambda (x) (= -3 (car x))) ent)
                     entdata    '((-3 ("ACAD" (1000 . "DSTYLE") (1002 . "{") (1070 . 69) (1070 . 0) (1002 . "}"))))
                     newentdata (append ent entdata)
               )
             )
             (entmod newentdata)
            )
      )
    )
  )
  (princ)
)

Technology will save us all! *eyeroll*

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Attribute background mask
« Reply #7 on: September 16, 2015, 03:48:50 PM »
I had the same problem after modifying MaskV1-1.lsp.  Works great to tun the mask on, but won't turn it off.

A while ago I invested a lot of time working on this problem and found that AutoCAD would not seem to accept the DXF group denoting a disabled background mask for an MText Attribute (an 'MAttribute' if you will).

FWIW, this bug does not appear to be present in BricsCAD.

jpcadconsulting

  • Newt
  • Posts: 56
Re: Attribute background mask
« Reply #8 on: September 23, 2015, 12:21:05 PM »
So it's a legit bug? Bummer... so close.
Technology will save us all! *eyeroll*

jpcadconsulting

  • Newt
  • Posts: 56
Re: Attribute background mask
« Reply #9 on: September 23, 2015, 12:48:48 PM »
Hi gang,

I've been poking around a bit, wrestling with the fact that Lee's command (which is awesome) does not seem to be able to turn the mask OFF.

Quote
A while ago I invested a lot of time working on this problem and found that AutoCAD would not seem to accept the DXF group denoting a disabled background mask for an MText Attribute (an 'MAttribute' if you will). -Lee Mac

I did find that issuing the ATTSYNC command and selecting the block turns off the textmask.

Lee - maybe there is a way to work that into the code?
« Last Edit: September 23, 2015, 01:17:00 PM by jpcadconsulting »
Technology will save us all! *eyeroll*

jpcadconsulting

  • Newt
  • Posts: 56
Re: Attribute background mask
« Reply #10 on: September 23, 2015, 02:00:14 PM »
Quick update...

ATTSYNC removes the mask for ALL blocks of the same name as the one you select.

So that's out as a viable option.
« Last Edit: September 23, 2015, 02:03:59 PM by jpcadconsulting »
Technology will save us all! *eyeroll*

MatGrebe

  • Mosquito
  • Posts: 16
Re: Attribute background mask
« Reply #11 on: August 30, 2017, 06:51:04 AM »
In LeeMac's first post he gave some lines to change for attributes.
But it seems to be related to an older version than current MaskV1.4.lsp

How can i modify current version, to include attribut-texts ?

Thanks

Mathias

ahsattarian

  • Newt
  • Posts: 112
Re: Attribute background mask
« Reply #12 on: August 23, 2021, 06:46:36 AM »
Hello

Is there any way to remove mask from a specific block attribute by selection ( Not all instances of that block )  ????

Attsync removes from all occurances of that block  !!!!

Regards

Amir

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Attribute background mask
« Reply #13 on: August 23, 2021, 03:28:22 PM »
Hello

Is there any way to remove mask from a specific block attribute by selection ( Not all instances of that block )  ????

Attsync removes from all occurances of that block  !!!!

Regards

Amir
You'd have to create a new renamed block.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

vuhoahc1989

  • Mosquito
  • Posts: 2
Re: Attribute background mask
« Reply #14 on: May 24, 2022, 06:27:14 AM »
In LeeMac's first post he gave some lines to change for attributes.
But it seems to be related to an older version than current MaskV1.4.lsp

How can i modify current version, to include attribut-texts ?

Thanks

Mathias

It 's MaskV1.1. I has changed.