update layer color in documents collection

Discussion in 'AutoCAD' started by Joe Burke, Apr 5, 2005.

  1. Joe Burke

    Joe Burke Guest

    All,

    Using 2004. The following is driving me slightly crazy.

    Assuming I have two files open and both have objects on layer zero color bylayer.
    Layer zero is just an example.

    This "test" function changes the color of layer zero in all files contained in the
    documents collection.

    (defun c:test ( / documents clrnum layers )
    (setq documents (vla-get-documents (vlax-get-acad-object)))
    (initget 7)
    (setq clrnum (getint "\nEnter layer zero color number: "))
    (vlax-for x documents
    (setq layers (vla-get-layers x))
    (vlax-put (vla-item layers "0") 'Color clrnum)
    )
    )

    OK so far. The color of layer zero is changed in all open files. But I only see the
    layer color update in the active file. Switching to the other open file does not
    reflect the updated layer zero color. Regen or regenall does not update the color of
    objects on layer zero in the other open file. Though the layer color is in fact
    changed.

    What does update objects on layer zero (in the other open file) is simply picking the
    layer toolbar dropdown menu or opening Layer Manager without any changes.

    Any thoughts regarding what's going on here would be welcome.

    Thanks
    Joe Burke
     
    Joe Burke, Apr 5, 2005
    #1
  2. Hi Joe,

    Dives me crazy also, and it is not just layer zero.
    Noticed this the other day when penning a quick
    and dirty function to match up some layer colors
    from an open file. Using 2005 here.
     
    Jason Piercey, Apr 5, 2005
    #2
  3. Joe Burke

    Joe Burke Guest

    Hi Jason,

    It's nice to know I'm not alone in this quandary. :)

    I only used layer zero as an example so the demo code would work given any set of
    files. Agreed, the issue isn't limited to layer zero.

    Regards
    Joe
     
    Joe Burke, Apr 5, 2005
    #3
  4. Joe and Jason,

    See if that works.


    (defun c:test ( / documents clrnum layers )
    (setq documents (vla-get-documents (vlax-get-acad-object)))
    (initget 7)
    (setq clrnum (getint "\nEnter layer zero color number: "))
    (vlax-for x documents
    (setq layers (vla-get-layers x))
    (vlax-put (vla-item layers "0") 'Color clrnum)

    (vla-save x)

    )
    )


    LE.
     
    Luis Esquivel, Apr 5, 2005
    #4
  5. Hi Luis,

    I'll have to test that out later, work is getting in the
    way of everything right now.
     
    Jason Piercey, Apr 5, 2005
    #5
  6. Joe Burke

    Joe Burke Guest

    Hi Luis,

    Adding (vla-save x) doesn't seem to make a difference.

    And of course I wouldn't want to be forced to such a solution, since I go out of my
    way to not to save open documents when dealing with a mix of ODBX documents and docs
    in the documents collection. An issue I didn't mention previously, though in play
    given the bigger picture.

    Regards
    Joe Burke
     
    Joe Burke, Apr 5, 2005
    #6
  7. Okay, if you guys need help or have a Janitor position, let me know..... :)

    LE.
     
    Luis Esquivel, Apr 5, 2005
    #7
  8. Is working here Joe at least on all the tests I did on acad 2005...
     
    Luis Esquivel, Apr 5, 2005
    #8
  9. Sorry Joe,

    I closed and re open autocad, and now what I was doing does not work.....
    very strange....


    LE.
     
    Luis Esquivel, Apr 5, 2005
    #9
  10. ok.... I did the test with two drawings again....

    1. I open two dwgs
    2 I did the color change with your code on the active dwg
    3. I open the other drawing and the color is not updated
    4. went I go to the other drawing and manually click on the qsave, the color
    is updated
    5. if I go back to the previous dwg and call your routine and change the
    color, now both dwgs are updated.

    hope that makes some sense... even if not works for you....

    LE.
     
    Luis Esquivel, Apr 5, 2005
    #10
  11. Joe Burke

    Joe Burke Guest

    Hi Luis,

    Thanks for trying. I understand what you mean, but it doesn't work that way under
    2004.

    I also tried releasing the "layers" object inside the vlax-for function. No help.

    Strange....

    Joe Burke
     
    Joe Burke, Apr 6, 2005
    #11
  12. Joe Burke

    James Allen Guest

    Hi Joe, just taking a shot here that I haven't noticed mention of yet.

    Perhaps adding (vla-Update AcadObject) would help? Luis recently introduced
    me to this and it has been helpful, though I am still at a loss how to know
    when it needs to be used.

    Also, does it make any difference to use the TrueColor property rather than
    Color? I expect not, but perhaps worth a try. Regardless, I remember
    someone mentioning that the Color prop will cease to be supported.
     
    James Allen, Apr 6, 2005
    #12
  13. Joe Burke

    Joe Burke Guest

    Hi James,

    That's an interesting idea. Unfortunately it doesn't seem to solve the problem.

    Here's a revised "test" function which incorporates the idea as I understand it.

    (defun c:test ( / *acad* documents clrnum layers )
    (setq *acad* (vlax-get-acad-object))
    (setq documents (vla-get-documents *acad*))
    (initget 7)
    (setq clrnum (getint "\nEnter layer zero color number: "))
    (vlax-for x documents
    (setq layers (vla-get-layers x))
    (vlax-put (vla-item layers "0") 'Color clrnum)
    ;(vlax-release-object layers) ;doesn't help
    ;(vla-update *acad*) ;here
    )
    (vla-update *acad*) ;or here
    (princ)
    )

    Regardless, I'm curious about the application of (vla-update AcadObject). When,
    where, and to what purpose? I must have missed Luis speaking on this topic.

    I'll try using TrueColor, but I also expect not. Right, the Color property will be
    phased out. I wonder, is it still supported under 2006?

    Regards,
    Joe Burke
     
    Joe Burke, Apr 6, 2005
    #13
  14. Joe Burke

    James Allen Guest

    James Allen, Apr 6, 2005
    #14
  15. Joe Burke

    Joe Burke Guest

    James,

    Oh, that thread... another flying saucer. :)

    Joe
     
    Joe Burke, Apr 7, 2005
    #15
  16. Joe Burke

    LUCAS Guest

    ;;By LUCAS
    ;;change the "CTAB"
    ;;but not for odbx
    (defun C:TEST (/ DOCUMENTS CLRNUM LAYERS NAME)
    (setq DOCUMENTS (vla-get-documents (vlax-get-acad-object)))
    (initget 7)
    (setq CLRNUM (getint "\nEnter layer zero color number: "))
    (vlax-for X DOCUMENTS
    (setq LAYERS (vla-get-layers X))
    (vlax-put (vla-item LAYERS "0") 'COLOR CLRNUM)
    (if (= (setq NAME (vla-getvariable X "ctab")) "Model")
    (progn
    (vla-setvariable X "ctab" NAME)
    (vla-setvariable X "ctab" "Model")
    )
    (progn
    (vla-setvariable X "ctab" "Model")
    (vla-setvariable X "ctab" NAME)
    )
    )
    )
    )
     
    LUCAS, Apr 8, 2005
    #16
  17. Joe Burke

    LUCAS Guest

    ;;RENEW
    (defun C:TEST (/ DOCUMENTS CLRNUM LAYERS NAME)
    (setq DOCUMENTS (vla-get-documents (vlax-get-acad-object)))
    (initget 7)
    (setq CLRNUM (getint "\nEnter layer zero color number: "))
    (vlax-for X DOCUMENTS
    (setq LAYERS (vla-get-layers X))
    (vlax-put (vla-item LAYERS "0") 'COLOR CLRNUM)
    (if
    (= (strcase
    (vlax-variant-value (setq NAME (vla-getvariable X "ctab")))
    )
    "MODEL"
    )
    (progn
    (vla-setvariable
    X
    "ctab"
    (vla-get-name (vla-item (vla-get-layouts X) 1))
    )
    (vla-setvariable X "ctab" "MODEL")
    )
    (progn
    (vla-setvariable X "ctab" "MODEL")
    (vla-setvariable X "ctab" NAME)
    )
    )
    (vla-regen X acallviewports)
    )
    )
     
    LUCAS, Apr 8, 2005
    #17
  18. Muy bien Lucas,

    Here is another form, using one reactor and the vl-propagate function.

    Code:
    (defun C:TEST  (/ DOCUMENTS CLRNUM LAYERS NAME)
    (setq DOCUMENTS (vla-get-documents (vlax-get-acad-object)))
    (initget 7)
    (setq CLRNUM (getint "\nEnter layer zero color number: "))
    (vlax-for X  DOCUMENTS
    (setq LAYERS (vla-get-layers X))
    (vlax-put (vla-item LAYERS "0") 'COLOR CLRNUM)
    ;;;    (if	(= (setq NAME (vla-getvariable X "ctab")) "Model")
    ;;;      (progn
    ;;;	(vla-setvariable X "ctab" NAME)
    ;;;	(vla-setvariable X "ctab" "Model")
    ;;;	)
    ;;;      (progn
    ;;;	(vla-setvariable X "ctab" "Model")
    ;;;	(vla-setvariable X "ctab" NAME)
    ;;;	)
    ;;;      )
    )
    
    (vl-propagate 'CLRNUM)
    
    )
    
    ;; also place the update and the reactor calls in the acad.mnl
    
    (defun update  (reactor params / layers dwg layer)
    
    (setq	layer
    (vla-item (setq layers	(vla-get-layers
    (setq	dwg (vla-get-activedocument
    (vlax-get-acad-object)))))
    "0"))
    
    (vlax-put layer 'color CLRNUM)
    
    ;;;;;;;;;  (vla-regen dwg acAllViewports)
    
    )
    
    (if (not reactor)
    (setq	reactor
    (vlr-docmanager-reactor
    nil
    '((:vlr-documentBecameCurrent . update)))))
    
    
    
    Also, notice if you change on the command line the variable CLRNUM and then (vl-propagate 'CLRNUM)

    Now go from one drawing to another.... is the color for the layer changing?

    LE
     
    Luis Esquivel, Apr 8, 2005
    #18
  19. Joe Burke

    Joe Burke Guest

    Lucas,

    I tested both versions you posted. Neither one solves the problem on my machine
    running 2004. I still have to use the layer dropdown menu, or invoke Layer Manager,
    for the color of layer zero to change as it should in open documents other than the
    active document.

    I appreciate the effort.

    Thanks
    Joe Burke
     
    Joe Burke, Apr 8, 2005
    #19
  20. Hi Joe,

    I'm testing the following under AutoCAD 2004, and appears to work.... please give it a try...

    Code:
    (defun C:TEST  (/ DOCUMENTS CLRNUM LAYERS NAME)
    (setq DOCUMENTS (vla-get-documents (vlax-get-acad-object)))
    (initget 7)
    (setq CLRNUM (getint "\nEnter layer zero color number: "))
    (vlax-for X  DOCUMENTS
    (setq LAYERS (vla-get-layers X))
    (vlax-put (vla-item LAYERS "0") 'COLOR CLRNUM))
    (if CLRNUM
    (vl-propagate 'CLRNUM)))
    
    ;; this function must be also loaded from the acad.mnl
    (defun update  (reactor params / layers dwg layer acado)
    (setq	layer
    (vla-item (setq layers	(vla-get-layers
    (setq	dwg (vla-get-activedocument
    (setq acado (vlax-get-acad-object))))))
    "0"))
    (if CLRNUM
    (vlax-put layer 'color CLRNUM)))
    
    ;; this function must be also loaded from the acad.mnl
    (if (not reactor)
    (setq	reactor
    (vlr-docmanager-reactor
    nil
    '((:vlr-documentBecameCurrent . update)))))
    
    (princ)
    
     
    Luis Esquivel, Apr 8, 2005
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.