Jump to content

Lisp to change the color of all incl blocks


raffich

Recommended Posts

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:

[font=Courier New][size=2]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[/size][/font]

 

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

Link to comment
Share on other sites

As a quick translation of your 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)
)

Link to comment
Share on other sites

hi Lee Mac

 

not working... there is an error:

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...

Link to comment
Share on other sites

Yess... found it!

(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!

Link to comment
Share on other sites

hi Lee Mac

 

not working... there is an error:

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.

Link to comment
Share on other sites

As a quick translation of your 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/showthread.php?533-Lisp-colour-change-for-all-layers-and-blocks&p=221559&viewfull=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

Link to comment
Share on other sites

Hi Lee. Is this any different from ColorX by VVA? http://www.cadtutor.net/forum/showthread.php?533-Lisp-colour-change-for-all-layers-and-blocks&p=221559&viewfull=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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...