+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Forum Newbie
    Using
    not applicable
    Join Date
    Feb 2015
    Posts
    3

    Default Lisp to change the color of all incl blocks

    Registered forum members do not see this ad.

    Hi there
    i found this vba code an it works perfekt when i can use the vba. but in the office there is vba restricted and so i would like to use this in a lisp:
    Code:
    Sub EsWerdeDunkel()
        Dim Entity As AcadEntity, Blockdef As AcadBlock, Blockref As AcadBlockReference
        For Each Entity In ThisDrawing.ModelSpace:  Entity.Color = 254: Next Entity
        
        For Each Blockdef In ThisDrawing.Blocks
            If Blockdef.IsLayout = False Then For Each Entity In Blockdef: Entity.Color = 254: Next Entity
        Next Blockdef
    End Sub
    maybe there is a way to choos the color by a color-promt box...

    hope you understand my english...
    i don't know how to code lisp.

    (i use Bricscad 14, 64Bit at office... but the lisp works the same as in Autocad)

    thanks 4 help
    raffi

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,365

    Default

    As a quick translation of your code:
    Code:
    (defun c:test ( / col doc foo )
        (if (setq col (acad_colordlg 1))
            (progn
                (setq foo (lambda ( obj ) (if (vlax-write-enabled-p obj) (vla-put-color obj col)))
                      doc (vla-get-activedocument (vlax-get-acad-object))
                )
                (vlax-map-collection (vla-get-modelspace doc) 'foo)
                (vlax-map-collection (vla-get-blocks doc)
                   '(lambda ( blk )
                        (if (and (= :vlax-false (vla-get-islayout blk))
                                 (= :vlax-false (vla-get-isxref   blk))
                            )
                            (vlax-map-collection blk 'foo)
                        )
                    )
                )
            )
        )
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Forum Newbie
    Using
    not applicable
    Join Date
    Feb 2015
    Posts
    3

    Default

    hi Lee Mac

    not working... there is an error:
    Code:
    Loading D:\_Witzig\_Admin\CAD\LISP\Farbe.lsp
    : (LOAD "D:/_Witzig/_Admin/CAD/LISP/Farbe.lsp")C:TEST
    : TEST
    
    ; ----- LISP : Call Stack -----
    ; [0]...C:TEST <<--
    ;
    ; ----- Error around expression -----
    'FOO
    ;
    ; error : no function definition <FOO> ; expected FUNCTION at [SYMBOL-FUNCTION]
    the color selection works but after the error stop the script...

  4. #4
    Forum Newbie
    Using
    not applicable
    Join Date
    Feb 2015
    Posts
    3

    Default

    Yess... found it!
    Code:
    (defun c:test ( / col doc foo )
        (if (setq col (acad_colordlg 1))
            (progn
                (setq foo (lambda ( obj ) (if (vlax-write-enabled-p obj) (vla-put-color obj col)))
                      doc (vla-get-activedocument (vlax-get-acad-object))
                )
                (vlax-map-collection (vla-get-modelspace doc) foo)
                (vlax-map-collection (vla-get-blocks doc)
                   '(lambda ( blk )
                        (if (and (= :vlax-false (vla-get-islayout blk))
                                 (= :vlax-false (vla-get-isxref   blk))
                            )
                            (vlax-map-collection blk foo)
                        )
                    )
                )
            )
        )
        (princ)
    )
    the 'foo was the mistake!

    now it works...! many thanks!

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,365

    Default

    Quote Originally Posted by raffich View Post
    hi Lee Mac

    not working... there is an error:
    Code:
    Loading D:\_Witzig\_Admin\CAD\LISP\Farbe.lsp
    : (LOAD "D:/_Witzig/_Admin/CAD/LISP/Farbe.lsp")C:TEST
    : TEST
    
    ; ----- LISP : Call Stack -----
    ; [0]...C:TEST <<--
    ;
    ; ----- Error around expression -----
    'FOO
    ;
    ; error : no function definition <FOO> ; expected FUNCTION at [SYMBOL-FUNCTION]
    the color selection works but after the error stop the script...
    This looks to be a bug with the vlax-map-collection implementation in BricsCAD - the code I have posted performs fine in AutoCAD.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default

    Quote Originally Posted by Lee Mac View Post
    As a quick translation of your code:
    Code:
    (defun c:test ( / col doc foo )
        (if (setq col (acad_colordlg 1))
            (progn
                (setq foo (lambda ( obj ) (if (vlax-write-enabled-p obj) (vla-put-color obj col)))
                      doc (vla-get-activedocument (vlax-get-acad-object))
                )
                (vlax-map-collection (vla-get-modelspace doc) 'foo)
                (vlax-map-collection (vla-get-blocks doc)
                   '(lambda ( blk )
                        (if (and (= :vlax-false (vla-get-islayout blk))
                                 (= :vlax-false (vla-get-isxref   blk))
                            )
                            (vlax-map-collection blk 'foo)
                        )
                    )
                )
            )
        )
        (princ)
    )
    Hi Lee. Is this any different from ColorX by VVA? http://www.cadtutor.net/forum/showth...l=1#post221559

    It seem to change all my blocks & nested blocks alot faster than ColorX (except the leader lines still retain color its grey colour)

    Thanks

  7. #7
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by vernonlee View Post
    Hi Lee. Is this any different from ColorX by VVA? http://www.cadtutor.net/forum/showth...l=1#post221559

    It seem to change all my blocks & nested blocks alot faster than ColorX (except the leader lines still retain color its grey colour)

    Thanks
    Anyone know?

Similar Threads

  1. Change especific True color to especific ASC color by LISP
    By GermanLarraguibel in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 9th Feb 2016, 08:58 pm
  2. Lisp to change background color modelspace and layout
    By Sandervp in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 10th Apr 2015, 12:48 pm
  3. Need a lisp to change the color of the command line
    By MikeP in forum AutoLISP, Visual LISP & DCL
    Replies: 27
    Last Post: 29th Jan 2014, 05:50 pm
  4. Lisp to change all objects with a certain color to another color
    By mikeSIEMENS in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 15th Jan 2010, 04:59 pm
  5. how to change a layer color in a block made out several blocks
    By firsrate_caduser in forum AutoCAD General
    Replies: 6
    Last Post: 16th Nov 2006, 06:25 pm

Bookmarks

Posting Permissions

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