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.
|
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.
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
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.
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
Step 2: Attribute Synchronize (if needed)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 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
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.
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
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