See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Keep attribute properties when updating blocks

  1. #1
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Keep attribute properties when updating blocks

    I change the colour of specific attributes within blocks. (Don't ask, its a long answer).
    Is there a way to keep the colours when updating the blocks with new versions? The attribute labels and (text) contents remain the same.
    John B

    "You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,486
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Not that I can think off hand. When the attributes are synchronized with the block definition, the color of the attribute would also be updated. You may be able to extract the colors prior to the synchronization and the replace the colors, but this will take programming of some nature.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,273
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Silly question..(maybe this doesn't work). why don't you change the color of the raw attributes of the new block?
    Then when you attsync they should take on those properties.
    Ted
    ____________________________________________________________________ ________________
    Windows 10
    AutoCAD 2018 - REVIT 2019 - Inventor Professional 2017 (when I can)

  4. #4
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Quote Originally Posted by tedg View Post
    Silly question..(maybe this doesn't work). why don't you change the color of the raw attributes of the new block?
    Then when you attsync they should take on those properties.
    Because there are a dozen attributes in each block and, at any one time, any, all or none of them might have had a different colour applied; the base colour in the block definitions is White so that they are not affected by layer. At the moment, I place a coloured rectangle around non-White attributes before updating the blocks - it allows me to change the colours but its a PITA with a thousand blocks in a hundred drawings.

    Opie, yes, thanks, that what I thought.
    John B

    "You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan

  5. #5
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,486
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Try these two autolisp routines. This is dependent on the handle remaining the same between updates. The first routine saves a list of handles of each attribute with the currently assigned color of the attribute. The second restores the color of that handle. If an error occurs, it will stop / crash. No error handling is implemented at the moment.
    Step 1: Save Attribute Colors
    Code:
    (defun c:SaveAttColors (/ cnt y l)
      (defun :VLA_GET_COLOR	(object / COLOR-METHOD COLOR-OBJECT color-list)
        (setq color-object (vla-get-TrueColor object)
    	  color-method (vla-get-ColorMethod color-object)
        )
        (cond ((= color-method acColorMethodByRGB)
    	   (setq color-list
    		  (mapcar
    		    '(lambda (l) (vlax-get color-object l))
    		    '(Red Green Blue)
    		  )
    	   )
    	  )
    	  ((= color-method acColorMethodByACI)
    	   (setq color-list (vla-get-ColorIndex color-object))
    	  )
        )
        (setq color-list
    	   (cons (vla-get-handle object)
    		 (list color-method color-list)
    	   )
        )
      )
      (setq lstHandles nil)
      (repeat (setq cnt (sslength (setq y (ssget '((0 . "INSERT"))))))
        (foreach n
    	     (m:safelist
    	       (vla-getattributes
    		 (vlax-ename->vla-object (ssname y (setq cnt (1- cnt))))
    	       )
    	     )
          (setq l (append l (list (vla-get-handle n))))
        )
      )
      (if l
        (setq lstHandles
    	   (mapcar
    	     (function (lambda (x)
    			 (:vla_get_color
    			   (vlax-ename->vla-object (handent x))
    			 )
    		       )
    	     )
    	     l
    	   )
        )
      )
    )
    Step 2: Attribute Synchronize (if needed)

    Step 3: Restore Attribute Colors
    Code:
    (defun c:RestoreAttColors (/)
      (defun :VLA_SET_COLOR	(object color-list / COLOR-METHOD)
    
        	(setq color-object
    	       (vla-GetInterfaceObject
    		 (setq :ACAD_OBJECT (vlax-get-acad-object))
    		 (strcat "AutoCAD.AcCmColor."
    			 (substr (getvar 'ACADVER) 1 2)
    		 )
    	       )
    	)
    
        (setq color-method (nth 0 color-list))
        (vla-put-ColorMethod color-object color-method)
        (if	(= color-method acColorMethodByRGB)
          (vla-SetRGB
    	color-object
    	(nth 0 (setq color-list (nth 1 color-list)))
    	(nth 1 color-list)
    	(nth 2 color-list)
          )
          (vla-put-ColorIndex color-object (nth 1 color-list))
        )
        (vla-put-TrueColor object color-object)
        (vlax-release-object color-object)
        object
      )
      (if (and lstHandles
    	   (= (type lstHandles) 'LIST)
          )
        (foreach n lstHandles
          (:VLA_SET_COLOR
    	(vlax-ename->vla-object (handent (car n)))
    	(cdr n)
          )
        )
      )
      (princ)
    )
    Last edited by Opie; 2016-01-27 at 04:38 PM. Reason: removed or funciton
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  6. #6
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Thanks for that, Opie.
    Unfortunately the result is -

    ; error: no function definition: M:SAFELIST
    -
    followed by an unhandled exception with the message that Application does not support JIT debugging. Why, I have no idea.
    John B

    "You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan

  7. #7
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,486
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Sorry about that.

    Add these two subroutines and it should work.

    Code:
    ;_ Convert Safearray to list
    (defun m:safelist (value)
      (if (= (type value) 'VARIANT)
        (setq value (m:variantvalue value))
      )
      (setq value (vl-catch-all-apply 'vlax-safearray->list (list value)))
      (if (vl-catch-all-error-p value)
        nil
        value
      )
    )
    ;_ Get value of variant
    (defun m:variantvalue (value)
      (setq value (vl-catch-all-apply 'vlax-variant-value (list value)))
      (if (vl-catch-all-error-p value)
        nil
        value
      )
    )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #8
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Quote Originally Posted by Opie View Post
    Sorry about that.

    Add these two subroutines and it should work.

    Code:
    ;_ Convert Safearray to list
    (defun m:safelist (value)
      (if (= (type value) 'VARIANT)
        (setq value (m:variantvalue value))
      )
      (setq value (vl-catch-all-apply 'vlax-safearray->list (list value)))
      (if (vl-catch-all-error-p value)
        nil
        value
      )
    )
    ;_ Get value of variant
    (defun m:variantvalue (value)
      (setq value (vl-catch-all-apply 'vlax-variant-value (list value)))
      (if (vl-catch-all-error-p value)
        nil
        value
      )
    )
    Close. The Save seems to work but Restore gives -
    ; error: null interface pointer: #<VLA-OBJECT 0000000000000000>
    John B

    "You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan

  9. #9
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,486
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Are you doing this in the same drawing session? Can you provide a sample drawing or two showing the various steps?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  10. #10
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: Keep attribute properties when updating blocks

    Quote Originally Posted by Opie View Post
    Are you doing this in the same drawing session? Can you provide a sample drawing or two showing the various steps?
    Yes, all within one session.
    Here is a file with two instances of the block and a copy of the revised block and my copy of your code.
    Attached Files Attached Files
    John B

    "You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan

Page 1 of 2 12 LastLast

Similar Threads

  1. 2015: Field in an Attribute not updating
    By derek.96018 in forum AutoCAD Customization
    Replies: 5
    Last Post: 2015-09-09, 05:06 PM
  2. Updating blocks nested within Dynamic Blocks
    By mattr.143859 in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2009-09-30, 04:14 PM
  3. Updating blocks nested within Dynamic Blocks
    By mattr.143859 in forum CAD Management - General
    Replies: 1
    Last Post: 2009-09-28, 01:09 PM
  4. Replies: 11
    Last Post: 2007-05-17, 06:56 AM
  5. updating attribute text
    By thomas_raftery in forum AutoCAD General
    Replies: 4
    Last Post: 2005-04-25, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •