Jump to content

Select inside block and change color prop


jim78b

Recommended Posts

i need a macro or a lisp to permit to select a block, refedit and then in silent change all lines and elements color to bylayer.

Then when i exit from refedit the entities color turn back on byblock.

 

is possible with a macro?

 

Link to comment
Share on other sites

Trying to think how to do all this in a single routine, I assume while you are editing the block you are changing it, not just opening the block, seeing all the elements change colour, close the block and see the elements go back to ByBlock.

 

The tricky part is editing the block and then setting the elements back to byblock when you close the block. You can do this with 2 LISPS I reckon, one to open the block to edit, ssget all the block elements and set them to bylayer, and then a second LISP once you have edited the block to set the elements to byblock, save and close the block editor... but a single LISP could be tricky.

Link to comment
Share on other sites

 Correct me if I'm wrong but i don't think you can do this in just one lisp. because you can only run one lisp at a time.

 

This is half of it just don't know how to change everything back to byblock before exit.

ssget "_x" maybe? everything outside block won't get changed.

 

this lisp will ask you to select a block to change its colors and refedit that block. You have to use the command again to save/exit if you want the colors to change back. or You could set up a reactor.

(defun C:BlkEdit (/ Drawing ent blk)
  (vl-load-com)
  (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))
  (if (/= (getvar 'refeditname) "")
    (progn
      (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname)))
      (vl-cmdf "_.Refclose" "S")
      (vlax-for x blk
        (vla-put-Color x 0)
      )
      (vla-Regen Drawing acAllViewports)
    )
    (progn
      (if (eq (cdr (assoc 0 (setq ent (entget (car (entsel "\nSelect Blocks")))))) "INSERT")
        (progn
          (setq blk (vla-item (vla-get-blocks Drawing) (cdr (assoc 2 ent))))
          (vlax-for x blk
            (vla-put-Color x 256)
          )
          (sssetfirst nil (ssadd (cdr (assoc -1 ent))))
          (vl-cmdf "-REFEDIT" "O" "A" "N")
        )
        (Prompt "\nNothing Selected")
      )  
    )
  )
  (princ)
)

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

Yes right when i will exit from refedit i think load another routine .tomorrow i will try.

But this lisp must chance in automatic color to bylayer when i refedit i hope?....thanks for your big help

Edited by jim78b
Link to comment
Share on other sites

38 minutes ago, jim78b said:

hello thanks i tried your code work perfectly! for exit from refedit and set all color to byblock can i make a macro right?

 

Just run the same macro to exit.

  • Thanks 1
Link to comment
Share on other sites

Sorry but i did it with no success. All my block return to byblock but the color that i assigned (purple) is turned on byblock. 

 

Another request if possible ...can you edit the code even with line and line scale to return bylayer ?

 

Thanks a lot

Link to comment
Share on other sites

I am not brilliant at VLA, however in mhupps code above he has this which is the settings when you exit the refedit

 

  (if (/= (getvar 'refeditname) "")
    (progn
      (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname)))
      (vl-cmdf "_.Refclose" "S")
      (vlax-for x blk
        (vla-put-Color x 0)
      )
      (vla-Regen Drawing acAllViewports)
    )

 

If you add the settings you want in this part of the code then that should set up what you want as you exit.

(vlax-for x blk
  (vla-put-Color x 0)

 

;; - ADDING THIS FOR LINETYPE AS AN EXAMPLE. THE LINE TYPE HAS TO BE LOADED FOR THIS TO WORK

(vla-put-Linetype x "DASHDOT")

;;

 

 )

 

vla-put-Color x 0, change the '0' for the colour code you want if you want it all to be purple.

I think vla-put-linetypescale doeslinetype scale... follow the above to add that in.

 

 

 

Pretty sure I am going to be corrected in a moment or 2, but try that as a start

Edited by Steven P
  • Agree 1
Link to comment
Share on other sites

On 2/16/2022 at 11:32 AM, jim78b said:

Then when i exit from refedit the entities color turn back on byblock.

 

🤔

if you want to ignore a color and set everything else back to byblock.

(vlax-for x blk
  (if (/= (vla-get-color x) #) ;if not color purple # change it back to byblock
    (vla-put-Color x 0)
  )
  (vla-put-linetype x "ByLayer") ;line type must be loaded to work
  (vla-put-linetypescale x #)
)

 

6 hours ago, Steven P said:

I am not brilliant at VLA, ...

 

Same, coming here each day is mostly to learn from everyone and have some light bulb moments from time to time if I'm lucky. just so happened to have this lisp already made up just had to edit it a little bit.

 

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...
5 minutes ago, jim78b said:

Please can you you make it work with nested blocks ?have a nice day

 

update this line of code.

 

(if (eq (cdr (assoc 0 (setq ent (entget (car (nentsel "\nSelect Blocks")))))) "INSERT") ;entsel to nentsel aka nested entsel

 

  • Thanks 1
Link to comment
Share on other sites

sorry i edit but don't work give me:

Select Blocks
Nothing Selected

 

(defun C:BlkEdit (/ Drawing ent blk)
  (vl-load-com)
  (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))
  (if (/= (getvar 'refeditname) "")
    (progn
      (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname)))
      (vl-cmdf "_.Refclose" "S")
      (vlax-for x blk
        (vla-put-Color x 6)
      )
      (vla-Regen Drawing acAllViewports)
    )
    (progn
      (if (eq (cdr (assoc 0 (setq ent (entget (car (nentsel "\nSelect Blocks")))))) "INSERT") ;
        (progn
          (setq blk (vla-item (vla-get-blocks Drawing) (cdr (assoc 2 ent))))
          (vlax-for x blk
            (vla-put-Color x 256)
          )
          (sssetfirst nil (ssadd (cdr (assoc -1 ent))))
          (vl-cmdf "-REFEDIT" "O" "A" "N")
        )
        (Prompt "\nNothing Selected")
      )  
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

That was a lot more work then I thought.  Used some of danallen code. had to add in another "n" to get to the right nested block. this will go 6 nest deep. but im sure you could make that dynamic somehow.  Used the repeat command!

 

(defun C:BlkEdit (/ Drawing e ent blk blkname nest)
  (vl-load-com)
  (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))
  (if (/= (getvar 'refeditname) "")
    (progn
      (setq blk (vla-item (vla-get-blocks Drawing) (getvar 'refeditname)))
      (vl-cmdf "_.Refclose" "S")
      (vlax-for x blk
        (vla-put-Color x 6)
      )
      (vla-Regen Drawing acAllViewports)
    )
    (progn
      (if (setq e (nentselp "\nSelect Block: "))
        (progn
          (if (and (> (length e) 2) (setq blkname (cdr (assoc 2 (entget (car (last e)))))))
            (progn  
              (setq blk (vla-item (vla-get-blocks Drawing) blkname))
              (vlax-for x blk
                (vla-put-Color x 256)
              )
            )
            (Prompt "\nNot A Block")
          )
          (setq nest (length (cadddr e)))
          (setvar 'cmdecho 0)
          (command "refedit" (cadr e))
          (repeat (- nest 1)
            (command "n")
          )
          (command "ok" "all" "y")
          (setvar 'cmdecho 1)
        )
        (Prompt "\nNothing Selected")
      )  
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

yes i understand, i need that after open block i see all object inside bylayer even nested block.

Edited by jim78b
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...