Author Topic: Attributes in Block Change Layer?  (Read 9298 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Attributes in Block Change Layer?
« on: January 20, 2006, 08:55:14 PM »

Ok,

I have many blocks, so I need a automated routine to search the drawing for a particular block, once found I need to get all of the attributes in the block layer to change to a different layer. How do I go around doing this?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Attributes in Block Change Layer?
« Reply #1 on: January 20, 2006, 09:38:18 PM »

Still stuck. I have tried this code but it does not seem to work..

Code: [Select]
(defun c:alcc ()
(setq attl(getstring "\nEnter new attribute layer: "))
(command "attedit" "y" "*" "*" "*" "c" pause pause)
(while
(= 1 (logand (getvar "cmdactive") 1))
(command "l" attl "n")
);;; end while
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Attributes in Block Change Layer?
« Reply #2 on: January 20, 2006, 09:53:37 PM »
Hi Don,
Give this a whirl......
Code: [Select]
(defun c:att2layr (/ layr ss atts idx)
  (vl-load-com)
  (if (and (setq layr (getstring "\nLayer for attributes: "))
   (setq ss (ssget '((0 . "INSERT")(66 . 1))))
   )
    (progn
      (setq idx -1)
      (while (setq ent (ssname ss (setq idx (1+ idx))))
(setq atts (vlax-invoke (vlax-ename->vla-object ent) 'getattributes))
(foreach att atts
  (vla-put-layer att layr)
  )
)
      )
    )
  ;;Note that there is no error trapping included in this example!
  ;;At the bare minimum, a check should be made for the existence of the destination layer.
  (princ)
  )

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Attributes in Block Change Layer?
« Reply #3 on: January 21, 2006, 12:53:26 AM »

Great, Question, after running your code I explode the block and manually select on an attribute and when I do that it still says it's the old layer. Basically, I am trying to put all of the attributes of my block on a specific layer so that I may PURGE out the unwanted layers.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Crank

  • Water Moccasin
  • Posts: 1503
Re: Attributes in Block Change Layer?
« Reply #4 on: January 21, 2006, 02:48:41 AM »
That's because the block defenition hasn't changed.

If you want to get rid of a layer without losing objects you can better use the LAYTRANS command, or use LYDELMRG.LSP from the express tools.

Vault Professional 2023     +     AEC Collection

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Attributes in Block Change Layer?
« Reply #5 on: January 21, 2006, 10:28:38 AM »

Quote
If you want to get rid of a layer without losing objects you can better use the LAYTRANS command, or use LYDELMRG.LSP from the express tools.

Neither of these options will work. I have tried them with no success.  LayTrans will not work because the target layer that I want the attributes to be on already exist in the block itself. As for LayDel,  it will not work at all. I guess I need the block Definition to change so that I may purge out the unwanted layers.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Crank

  • Water Moccasin
  • Posts: 1503
Re: Attributes in Block Change Layer?
« Reply #6 on: January 21, 2006, 11:36:03 AM »
It doesn't matter if the layer already exists.

If you want to use lisp, try this LayMerge routine.

It is a modified version of the LYDELMRG.LSP that came with Acad2004.

Code: [Select]
(laymerge "merge" "SourceLayer" DestLayer")
Vault Professional 2023     +     AEC Collection

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Attributes in Block Change Layer?
« Reply #7 on: January 21, 2006, 11:44:05 AM »

Thanks Crank, that did work. Much appreciated...

TY
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attributes in Block Change Layer?
« Reply #8 on: January 21, 2006, 12:25:16 PM »
Ooops too late. :?

I just threw this together, but try it.
The block selection code needs work.
Exclude all but one or add code to step through the ss.
My code changes the block definition & jeff's changes all the Inserts.

Code: [Select]
(defun c:att2layr (/ layr ss atts idx bname blk)
  (vl-load-com)
  (cond
    ((or (not (setq layr (getstring t "\nLayer for attributes: ")))
         (not (tblsearch "LAYER" layr))
     )
     (prompt "\nERROR in layer name.")
    )
    ((not (and
            (not (prompt "\nSelect the block to change."))
            (setq ss (ssget '((0 . "INSERT") (66 . 1))))
            (setq ent (ssname ss 0))
            (< (sslength ss) 2) ; only one pick allowed
          )
     )
     (prompt "\nERROR in block selection.")
    )
    (t
     (setq ent (ssname ss 0))
     (setq ent (tblobjname "BLOCK" (setq bname (cdr (assoc 2 (entget ent)))))
           blk ent
     )
     (setq entl (entget ent))
     (while (and ent
                 (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent)))))
            )
       (if (= (cdr (assoc 0 entl)) "ATTDEF")
         (entmod (subst (cons 8 layr) (assoc 8 entl) entl))
       )
       (setq ent (entnext ent))
     )
     (entupd blk)
     ;;  Change the Inserts, by Jeff
     (vl-load-com)
     (setq ss (ssget "x" (list '(0 . "INSERT") '(66 . 1) (cons 2 bname))))
     (setq idx -1)
     (while (setq ent (ssname ss (setq idx (1+ idx))))
       (setq atts (vlax-invoke (vlax-ename->vla-object ent) 'getattributes))
       (foreach att atts
         (vla-put-layer att layr)
       )
     )
    )
  )
  (princ)
)
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.

CADaver

  • Guest
Re: Attributes in Block Change Layer?
« Reply #9 on: January 21, 2006, 09:55:46 PM »
ummm...  refedit the block then attsync ??

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attributes in Block Change Layer?
« Reply #10 on: January 21, 2006, 10:13:15 PM »
In ACAD 2000 the refedit won't let you at the attributes to change the layer.
Or did I miss something?

Good to see ya Randy. :-)
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.

CADaver

  • Guest
Re: Attributes in Block Change Layer?
« Reply #11 on: January 21, 2006, 10:23:43 PM »
R2002 you get a dialog box that you check the "Display attributes definitions for editting" box and attributes become refeditable.  once complete use attsync to force all block instances to the new block definition.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attributes in Block Change Layer?
« Reply #12 on: January 22, 2006, 01:07:49 AM »
Well that's just too easy. :-)
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.

Peter Jamtgaard

  • Guest
Re: Attributes in Block Change Layer?
« Reply #13 on: January 22, 2006, 05:36:17 PM »
It is pretty easy with lisp too

The syntax is (blockattlay "MyblockName" "NewAttributeLayer")

Peter

Code: [Select]
(defun BlockAttLay (strBlockName strLayerName / intCount entSelection objSelection ssSelections )
 (setq ssSelections (ssget "X" (list (cons 2 strBlockName))))
 (repeat (setq intCount (sslength ssSelections))
  (setq intCount     (1- intCount)
        entSelection (ssname ssSelections intCount)
        objSelection (vlax-ename->vla-object entSelection)
  )
  (compoundObject objSelection strLayerName)
 )
 (setq objBlock (vla-item
                 (vla-get-blocks
                  (vla-get-activedocument
                   (vlax-get-acad-object)
                  )
                 )
                 strBlockName
                )
 )
 (vlax-for objItem objBlock
  (if (= (vla-get-objectname objItem) "AcDbAttributeDefinition")
   (vla-put-layer objItem strLayerName)
  )
 )
 (princ)
)

(defun CompoundObject (objItem strLayerName / entItem2)
 (if (wcmatch (setq strObjectName (vla-get-objectname objItem))
     "AcDbBlockReference,AcDbMInsertBlock"
     )
  (if (= (vla-get-hasattributes objItem) :vlax-true)     
   (progn
    (setq entItem2 (vlax-vla-object->ename objItem))
    (while (/= (cdr (assoc 0 (entget entItem2))) "SEQEND")
     (setq objItem2 (vlax-ename->vla-object entItem2))
     (vla-put-layer objItem2 strLayerName)     
     (setq entItem2 (entnext entItem2))
    )
    (setq objItem2 (vlax-ename->vla-object entItem2))
    (vla-put-layer objItem2 strLayerName)   
   )
  )
 )
)




gatorcadd

  • Guest
Re: Attributes in Block Change Layer?
« Reply #14 on: January 22, 2006, 11:00:13 PM »
uh, wont battman do the same thing?  not the winged character...

i thought battman had a global editor in it.