Author Topic: delete invisible attributes help  (Read 7181 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
delete invisible attributes help
« on: December 17, 2010, 11:06:59 AM »
Hello

I'm trying to delete invisible attributes in a drawing.  I don't want to burst the blocks.
A client uses some CAD software which displays the invisible attributes, so I want to remove them all together.
I found this lisp here http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Remove-Invisible-Attributes-from-Blocks/m-p/1517876

Code: [Select]
(defun delInvisAtts (bname / )
(if (tblsearch "BLOCK" bname)
(progn
(vl-load-com)
(setq blk (vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
bname
)
)
(vlax-for ent blk
(if (and (eq (vla-get-objectname ent) "AcDbAttributeDefinition")
(eq (vla-get-invisible ent) :vlax-true)
)
(vla-delete ent)
)
)
)
)
)

But I can't get it to work, wondered if somebody could show me where I'm going wrong?


Thanks P

T.Willey

  • Needs a day job
  • Posts: 5251
Re: delete invisible attributes help
« Reply #1 on: December 17, 2010, 11:13:03 AM »
That only deletes them from the definition, not the inserts.  You would have to get the inserts for said block, and then step through the attributes associated with the insert, and then delete those if they are invisible.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Pad

  • Bull Frog
  • Posts: 342
Re: delete invisible attributes help
« Reply #2 on: December 17, 2010, 11:19:32 AM »
ah, thats me stuffed then.
Thanks

Pad

  • Bull Frog
  • Posts: 342
Re: delete invisible attributes help
« Reply #3 on: December 17, 2010, 11:28:03 AM »
ah ha, using the gatte command has let me select the block and attribute to delete.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: delete invisible attributes help
« Reply #4 on: December 17, 2010, 12:08:29 PM »
Something like this?

Code: [Select]
(defun c:DIA nil (c:DeleteInvisibleAttributes))

(defun c:DeleteInvisibleAttributes ( / ss ) (vl-load-com)
  ;; Example by Lee Mac 2010 - www.lee-mac.com

  (if (ssget '((0 . "INSERT") (66 . 1)))
    (progn
      (vlax-for obj
        (setq ss
          (vla-get-ActiveSelectionSet
            (vla-get-ActiveDocument (vlax-get-acad-object))
          )
        )
        (mapcar
          (function
            (lambda ( attrib )
              (if (eq :vlax-true (vla-get-Invisible attrib))
                (vla-delete attrib)
              )
            )
          )
          (vlax-invoke obj 'GetAttributes)
        )
      )
      (vla-delete ss)
    )
  )
  (princ)
)
« Last Edit: December 17, 2010, 12:49:34 PM by Lee Mac »

kpblc

  • Bull Frog
  • Posts: 396
Re: delete invisible attributes help
« Reply #5 on: December 17, 2010, 02:20:40 PM »
Perhaps, command _.attsync helps?
Sorry for my English.

Pad

  • Bull Frog
  • Posts: 342
Re: delete invisible attributes help
« Reply #6 on: December 17, 2010, 06:04:55 PM »
Something like this?


thanks Lee.  It works very well but there is a small problem.
The tag and prompt order becomes messed up.

In this example the 'No' and 'code' attributes are invisible

before:

after:


cheers
P

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: delete invisible attributes help
« Reply #7 on: December 17, 2010, 06:27:03 PM »
Hmmm.. I wasn't expecting that  :oops:

Perhaps altering the block definition is the only way  :|

T.Willey

  • Needs a day job
  • Posts: 5251
Re: delete invisible attributes help
« Reply #8 on: December 17, 2010, 06:41:39 PM »
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: delete invisible attributes help
« Reply #9 on: December 17, 2010, 06:46:40 PM »
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).

Or perhaps use AttSync I suppose after running the first code  :|

I would have thought one could alter the attributes for a single reference though  :-(

T.Willey

  • Needs a day job
  • Posts: 5251
Re: delete invisible attributes help
« Reply #10 on: December 17, 2010, 07:18:20 PM »
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).

Or perhaps use AttSync I suppose after running the first code  :|

I would have thought one could alter the attributes for a single reference though  :-(

I think the problem is with Acad's logic when it comes to attributes.  There is nothing referencing the definition ( of an attribute ) once you insert a block.  I have wondered how it happens before, and could only come up with the idea that is just goes in order, as it appears it does.  So if you erase the invisible attributes from the definition and the insert, then they should be in the same order.

Sidenote:  I wonder why they didn't just put a prompt dxf code with attributes references.  They are only stored in attribute definitions.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: delete invisible attributes help
« Reply #11 on: December 17, 2010, 07:37:14 PM »
Try erasing them from the definition, and the insert.  Run the code in the first post, and then Lee's ( either order, doesn't really matter ).

Or perhaps use AttSync I suppose after running the first code  :|

I would have thought one could alter the attributes for a single reference though  :-(

I think the problem is with Acad's logic when it comes to attributes.  There is nothing referencing the definition ( of an attribute ) once you insert a block.  I have wondered how it happens before, and could only come up with the idea that is just goes in order, as it appears it does.  So if you erase the invisible attributes from the definition and the insert, then they should be in the same order.

That seems to be the case judging by the way the prompt order depends on the Sortents table of the block.

Sidenote:  I wonder why they didn't just put a prompt dxf code with attributes references.  They are only stored in attribute definitions.

That would be nice :-)

Pad

  • Bull Frog
  • Posts: 342
Re: delete invisible attributes help
« Reply #12 on: December 18, 2010, 11:02:10 AM »
thanks guys.
I'l give the first lisp and attsync a go.

to be honest I'm a little bit confused about how to run the first lisp as its a function.
What is the corect syntax for running it?

Cheers
p

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: delete invisible attributes help
« Reply #13 on: December 18, 2010, 11:14:43 AM »
A slight reworking and a wrapper for you:

Code: [Select]
(defun delInvisAtts ( bname ) (vl-load-com)
  (if (tblsearch "BLOCK" bname)
    (vlax-for obj
      (vla-item
        (vla-get-blocks
          (vla-get-activedocument (vlax-get-acad-object))
        )
        bname
      )
      (if (and (eq (vla-get-objectname obj) "AcDbAttributeDefinition")
               (eq (vla-get-invisible obj) :vlax-true)
          )
        (vla-delete obj)
      )
    )
  )
)


(defun c:test ( / bn )

  (delInvisAtts (setq bn (getstring t "\nBlock Name: ")))

  (vl-cmdf "_.attsync" "_N" bn)
  (princ)
)

Pad

  • Bull Frog
  • Posts: 342
Re: delete invisible attributes help
« Reply #14 on: December 20, 2010, 06:47:01 AM »
brilliant
I'll have a look at this soon. 
Thanks