Author Topic: Vla-put-TrueColor on thousands of entities  (Read 6578 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Vla-put-TrueColor on thousands of entities
« Reply #15 on: November 30, 2017, 09:32:16 AM »
Why still:
Code - Auto/Visual Lisp: [Select]
  1. (setq TrCCol (vla-get-TrueColor ObjFor)) (vla-put-ColorIndex TrCCol (caddr TmpLst))
When this does the same thing?
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-Color ObjFor (caddr TmpLst))

Here's some quick thoughts minus the proplist and layer masking:

Code - Auto/Visual Lisp: [Select]
  1. (defun foo (doc color erase_att)
  2.   ;; Unlock all layers first
  3.   (vlax-for l (vla-get-layers doc) (and (= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0)))
  4.     (if (= 0 (vlax-get a 'isxref) (vlax-get a 'islayout))
  5.       ;; Rename block here
  6.       ;; (vl-catch-all-apply 'vla-put-name (list a "yada"))
  7.       (vlax-for b a
  8.         (vl-catch-all-apply 'vla-put-color (list b color))
  9.         (cond
  10.           ((and (= "AcDbBlockReference" (vla-get-objectname b)) (= -1 (vlax-get b 'hasattributes)))
  11.            ;; Do stuff to attributes
  12.            (foreach c (vlax-invoke b 'getattributes)
  13.              (if erase_att
  14.                (vl-catch-all-apply 'vla-delete (list c))
  15.                (vl-catch-all-apply 'vla-put-color (list c color))
  16.              )
  17.            )
  18.           )
  19.         )
  20.       )
  21.     )
  22.   )
  23. )
  24. ;; Change to all to white and leave attributes
  25. ;; Change to all to red and erase attributes

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Vla-put-TrueColor on thousands of entities
« Reply #16 on: November 30, 2017, 10:46:05 AM »

Why still:
Code - Auto/Visual Lisp: [Select]
  1. (setq TrCCol (vla-get-TrueColor ObjFor)) (vla-put-ColorIndex TrCCol (caddr TmpLst))
When this does the same thing?
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-Color ObjFor (caddr TmpLst))
Here's some quick thoughts minus the proplist and layer masking:

...
Code: [Select]
(vl-catch-all-apply ;
                          (function (lambda ( ) (vla-Put-Layer ObjFor (cadr TmpLst)) (vla-put-Color ObjFor (caddr TmpLst)) (vla-put-Linetype ObjFor (cadddr TmpLst))))
  )
I have modified... now it is working... :crazy2: I do not know why!
Your code:
Code: [Select]
(defun foo (doc color erase_att)
  (vlax-for l (vla-get-layers doc) (and (= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0)))
  (vlax-for a (vla-get-blocks doc)
    (if (= 0 (vlax-get a 'isxref) (vlax-get a 'islayout))
      (vlax-for   b a
        (vl-catch-all-apply 'vla-put-color (list b color))
        (print (vla-get-objectname b)) (princ " 1 ")
        (cond
          ( (and (= "AcDbBlockReference" (vla-get-objectname b)) (= -1 (vlax-get b 'hasattributes)))
            (print (vla-get-objectname b)) (princ " 2 ")
            (foreach c (vlax-invoke b 'getattributes)
              (if erase_att
                (vl-catch-all-apply 'vla-delete (list c))
                (vl-catch-all-apply 'vla-put-color (list c color))
              )
            )
          )
        )
      )
    )
  )
)
In my sample DWG:
Code: [Select]
Command: (foo (vla-get-activedocument (vlax-get-acad-object)) 1 t)
"AcDbLine"  1
"AcDbLine"  1
"AcDbLine"  1
"AcDbAttributeDefinition"  1
"AcDbAttributeDefinition"  1
"AcDbAttributeDefinition"  1
"AcDbAttributeDefinition"  1
"AcDbCircle"  1
"AcDbText"  1 nil
Code: [Select]
There are not "AcDbBlockReference" (only  inside Layout/Model) then attribs are not deleted.
Note: my function ALE_Block_Edit_ChangeDef(inition)Props works on "AcDbBlockTableRecord" and delete "AcDbAttributeDefinition" not "AcDbAttribute"
so the "INSERT" loose only constant Attributes.

 

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Vla-put-TrueColor on thousands of entities
« Reply #17 on: November 30, 2017, 10:54:26 AM »
You're right .. copy paste error  :oops: need to take out the layout check:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo (doc color erase_att)
  2.   (vlax-for l (vla-get-layers doc) (and (= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0)))
  3.     (vlax-for b a
  4.       (vl-catch-all-apply 'vla-put-color (list b color))
  5.       (print (vla-get-objectname b))
  6.       (princ " 1 ")
  7.       (cond
  8.         ((and (= "AcDbBlockReference" (vla-get-objectname b)) (= -1 (vlax-get b 'hasattributes)))
  9.          (print (vla-get-objectname b))
  10.          (princ " 2 ")
  11.          (foreach c (vlax-invoke b 'getattributes)
  12.            (if erase_att
  13.              (vl-catch-all-apply 'vla-delete (list c))
  14.              (vl-catch-all-apply 'vla-put-color (list c color))
  15.            )
  16.          )
  17.         )
  18.       )
  19.     )
  20.   )
  21. )
BTW .. why are  you doing this ? Seems like you're intentionally trashing a drawing?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Vla-put-TrueColor on thousands of entities
« Reply #18 on: November 30, 2017, 11:08:56 AM »

You're right .. copy paste error  :oops: need to take out the layout check:
...
BTW .. why are  you doing this ? Seems like you're intentionally trashing a drawing?


Code: [Select]
Yes, I am cleaning all Block definitions (delete attribs), change layers/color/linetype, rename/encrypt.
After, I pass all Model/Layouts change layers/color/linetype for all objects, transform Attribs to Texts. This is done on a copy of the DWG.
I apologize to everyone for Truecolor question, maybe I was initially trying to apply vla-put-color to objects that did not accept it, without using the form
with vl-catch-all-apply.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Vla-put-TrueColor on thousands of entities
« Reply #19 on: November 30, 2017, 12:44:34 PM »

After all discussion on TrueColor... is really true?
https://knowledge.autodesk.com/it/search-result/caas/CloudHelp/cloudhelp/2016/ITA/AutoCAD-ActiveX/files/GUID-A186333C-4857-4DFD-97EC-CDF75523299B-htm.html
Color Property
Specifies the color of an object or layer.
....
This property is obsolete and will be removed in a future version. When using this property, colors can be set and read as numeric index values ranging from 0 to 256. Constants are provided for the standard seven colors, as well as for the BYBLOCK and BYLAYER designations.
If you use acByBlock, AutoCAD draws new objects in the default color (white or black, depending on your configuration) until they are grouped into the block. When the block is inserted in the drawing, the objects in the block inherit the current setting of the color property.
If you use acByLayer, new objects assume the color of the layer upon which they are drawn. The value acByLayer is not valid for a Layer object.