Jump to content

Recommended Posts

Posted

I need modify this lisp because i want set on color 200 only blocks and groups (no other elements like dimensions lines etc).

i mean that all elements inside groups or blocks are (colour setbyblock) and then change outside them to colour 200

thanks in advance

(defun c:AllToByBlock (/ doc)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
    (if (= :vlax-false (vla-get-IsLayout b) (vla-get-IsXref b))
      (vlax-for o b
        (vla-put-Color o 0)
      )
    )
  )
  (vla-regen doc acAllViewports)
  (princ)
)

 

Posted

Your Wording is a little hard to follow. You want to change all elements of blocks to color 200?

 

(vla-put-Color o 0)
to 
(vla-put-Color o 200)

 

Posted (edited)

yes but inside blocks or groups i want colour setallbyblock and then put all blocks on color 200

 

can you use this for select all blocks after execute my lisp?

 

  (ssget "_X" '((0 . "INSERT")(2 . "Block_Name")))

and then sett all them on colour 200?

Edited by jim78b
Posted
(defun C:test (/ ss e blk doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(if
  (setq ss (ssget ":L" '((0 . "INSERT"))))
  (repeat (setq i (sslength ss))
     (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
     (setq blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e)))
     (vlax-for x blk
       (vla-put-color x 200)
     )
  )
)
(vla-regen doc acAllViewports)
(princ)
)

i have this and works but not in nested and dynamic blocks can you work with them please?

 

Posted (edited)

Think you just need to add one line.

 

(defun c:AllToByBlock (/ doc b o SS blk)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
    (if (= :vlax-false (vla-get-IsLayout b) (vla-get-IsXref b))
      (vlax-for o b
        (vla-put-Color o 0) ;change all elements inside block to byblock
      )
    )
  )
  (if (setq SS (ssget "_X" '((0 . "INSERT"))))
    (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq blk (vlax-ename->vla-object blk))
      (vla-put-Color blk 200)
    )
  )
  (vla-regen doc acAllViewports)
  (princ)
)
Edited by mhupp
Code Updated
Posted

thanks but give me

 


; error: ActiveX Server returned the error: unknown name: color

Posted

didn't realize they are stepping though the block library and changing all the elements that way.

Need to add the 2nd if to select all the blocks in the drawing itself to change their color

Posted

Sorry should have said i updated my code above to work.

  • Like 1
Posted

the problem of my lisp is that change even the dimension color, i don't want it

Posted (edited)

ok now work just for the dimension text color , the original is white but when i execute code his color is of the layer that is assigned .

Can you exclude dimensions please?

Edited by jim78b
Posted (edited)

Updated the if statement to ignore block names that start with a "*"  this will ignore anonymous blocks like xref and dimensions.

 

(defun c:AllToByBlock (/ doc b o SS blk)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
    (if (/= (vl-string-elt (vla-get-name b) 0) 42)
      (vlax-for o b
        (vla-put-Color o 0) ;change all elements inside block to byblock
      )
    )
  )
  (if (setq SS (ssget "_X" '((0 . "INSERT"))))
    (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq blk (vlax-ename->vla-object blk))
      (vla-put-Color blk 200)
    )
  )
  (vla-regen doc acAllViewports)
  (princ)
)

 

Edited by mhupp
  • Thanks 1
Posted

Ok later or tomorrow i will test it. I don't know how thanks you !!

Posted

hello! i test the lisp it is work! thans a lot Best regards, many thanks

  • Like 1
  • 1 year later...
Posted

sorry your lisp with dynamic nested blocks don't work

Posted (edited)

@jim78b Why did you post the same topic twice 3 times with different titles? Did you know you can edit your posts? Select the "..." in the upper right and select "Edit" and you can edit posts.

Edited by pkenewell

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