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

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attributes in Block Change Layer?
« Reply #15 on: January 23, 2006, 12:09:32 AM »
Peter
Looks like you changed the attribute def in the BLOCK but changed all objects within all the INSERTS
including the SEQEND to the new layer.
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 #16 on: January 23, 2006, 08:28:52 PM »
Well that's just too easy. :-)
those of us with no discernible lisp skills have to resort to using the commands available   :-)

Peter Jamtgaard

  • Guest
Re: Attributes in Block Change Layer?
« Reply #17 on: February 04, 2006, 05:05:23 PM »
Peter
Looks like you changed the attribute def in the BLOCK but changed all objects within all the INSERTS
including the SEQEND to the new layer.

The routine does change the block definition and it change the attribute entities, but not all of the objects in the block.

Using the (entnext (car (entsel))) selecting a block with attributes will return the first attribute in a block.

The routine I shared switches the attribute defintions in the blocks collection and it changes the existing block instances in a drawing. It changes the seqend (nasty little problem in drawings) to the desired layer. If you don't there are drawings that when you change the layer of the block, the seqend used to not change. If you use activex to change the attributes it can also not change. The only way to get at it was through the entnext procedure. hence the code above.


Peter :-o

Fatty

  • Guest
Re: Attributes in Block Change Layer?
« Reply #18 on: February 05, 2006, 12:59:45 PM »
Peter
Looks like you changed the attribute def in the BLOCK but changed all objects within all the INSERTS
including the SEQEND to the new layer.
Hi Alan, glad to meet you again
I agree with you about "SEQEND"...
I wrote similar routine but I have feeling that I missed
something here (include locked layers)
Are you can to explain to me where I mistaken seriously?

Code: [Select]
(defun chatlay (bname lname /  a adoc atts axss b
blkcol blkdef lname ss)
  (or (vl-load-com))
  (or adoc
      (setq adoc (vla-get-activedocument
   (vlax-get-acad-object)
)
      )
  )
  (setq blkcol (vla-get-blocks adoc))
  (if (setq ss (ssget "X" (list (cons 2 bname))))
    (progn
      (setq axss (vla-get-activeselectionset adoc))
      (vlax-for a axss
(if (eq :vlax-true (vla-get-hasattributes a))
  (progn
    (setq atts (vlax-invoke a 'Getattributes))
    (foreach at atts
      (vl-catch-all-apply
(function (lambda ()
    (progn
      (vla-put-layer at lname)
      (vla-update at)
    )
  )
)
      )
    )
    (vla-update a)
    (setq blkdef (vla-item blkcol bname))

    (vlax-for b blkdef
      (if (eq "AcDbAttributeDefinition" (vla-get-objectname b))
(vl-catch-all-apply
  (function (lambda ()
      (vla-put-layer b lname)
    )
  )
)
      )
    )
  )
)
      )
    )
    (prompt
      "\nHere aren't block insertions with the same block name ...\n"
    )
  )
  (princ)
)
;CaLL : (chatlay "MYBLOCK" "NEWLAYER")

My apologies to Peter for an offtopic

~'J'~
« Last Edit: February 05, 2006, 01:57:29 PM by Fatty »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attributes in Block Change Layer?
« Reply #19 on: February 06, 2006, 10:07:15 AM »
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. 8-) 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.
Code: [Select]
;;  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)
     )
    )
  )
)
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Attributes in Block Change Layer?
« Reply #20 on: February 06, 2006, 10:14:50 AM »
Fatty,
Glad to see you here.

I think you should be asking Peter. :)

Quote from: Peter
The only way to get at it was through the entnext procedure.
I think that answered your question.
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.

Fatty

  • Guest
Re: Attributes in Block Change Layer?
« Reply #21 on: February 06, 2006, 12:12:51 PM »
Fatty,
Glad to see you here.

I think you should be asking Peter. :)

Quote from: Peter
The only way to get at it was through the entnext procedure.
I think that answered your question.

Yes you are right, I think also,
thank you for an explanation

Fatty