OK Peter, I found my mistake.
When I read through you code it looked to me as though you were changing all
objects in the Insert to the new layer. Which is what you were doing.
My mistake was not remembering that the actual objects except the attributes
are not in the INSERT but in the BLOCK definition. This BLOCK/INSERT thing has
always caused my grief. After stepping through the code I see that as you
process each object in the INSERT definition none of the objects show up except
the attributes. But when you step through the BLOCK definition the all the objects
show up but you filter for the attribute definition so only it get changed.
Sorry for the confusion, it was all mine.
I know most of this stuff is automatic
to you with your depth of knowledge but I'm not there yet.
Here is you code commented by me as I worked through it.
;; By Peter J
;; ** comments by CAB
(defun BlockAttLay (strBlockName strLayerName / intCount entSelection objSelection ssSelections )
;;========================
;; change all Inserts
;;========================
(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)
)
;; go change the INSERT entities
(compoundObject objSelection strLayerName)
)
;; Now get the block
(setq objBlock (vla-item
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
strBlockName
)
)
;;==========================================
;; change the block attributes entities
;;==========================================
(vlax-for objItem objBlock ; step through the block objects
;; only if it is an attribute
(if (= (vla-get-objectname objItem) "AcDbAttributeDefinition")
(vla-put-layer objItem strLayerName) ; change the layer
)
)
(princ)
)
;;==============================================
;; sub to change sub entities in the Insert
;;==============================================
(defun CompoundObject (objItem strLayerName / entItem2)
;; make sure it's a block
(if (wcmatch (setq strObjectName (vla-get-objectname objItem))
"AcDbBlockReference,AcDbMInsertBlock"
)
;; make sure it has attibutes
(if (= (vla-get-hasattributes objItem) :vlax-true)
(progn
(setq entItem2 (vlax-vla-object->ename objItem))
;; step through the objects within the Insert definition
;; but stop at seqend
(while (/= (cdr (assoc 0 (entget entItem2))) "SEQEND")
(setq objItem2 (vlax-ename->vla-object entItem2))
(vla-put-layer objItem2 strLayerName) ; change the layer
(setq entItem2 (entnext entItem2)) ; next item in the database
)
;; next two lines change the seqend layer
(setq objItem2 (vlax-ename->vla-object entItem2))
(vla-put-layer objItem2 strLayerName)
)
)
)
)