Jump to content

alltobyblock excpet dimensions


jim78b

Recommended Posts

hello please i need change this lisp because i want after execute it change only blocks and not dimensions

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

 

 

Edited by jim78b
Link to comment
Share on other sites

  • jim78b changed the title to alltobyblock excpet dimensions

@jim78b Try this:

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

 

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

(defun c:Atbk (/ 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)
)

this work with dimension lines but not work for dynamic blocks!

Link to comment
Share on other sites

(defun c:AB (/ blk doc obj SS)
  (vl-load-com)
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (vlax-for blk (vla-get-Blocks doc)
    (if (and (= (vla-get-isxref blk) :VLAX-FALSE)           ;ignores xrefs
             (not (wcmatch (vla-get-name blk) "*`**,*|*"))  ;ignores anonymous and xref blocks
        )
      (vlax-for obj blk
        (vla-put-Color obj 0) ;change all elements inside block to byblock
      )
    )
  )
  (if (setq SS (ssget "_X" '((0 . "INSERT"))))
    (foreach blk (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
      (vla-put-Color blk 200) ;added another mapcar to line above to convert at the list level from ename to vla-object
    )
  )
  (vla-regen doc acAllViewports)
  (vla-EndUndoMark doc)
  (princ)
)

tHIS ROUTINE WAS PERFECT but not work with dynamic bloks and anonymous! can you resolve it? please

Edited by jim78b
Link to comment
Share on other sites

6 hours ago, Tharwat said:

@pkenewell you called the vla-get-activedocument two times. 

@Tharwat Oops - your right. I just altered the original routine and didn't check. I updated my post.

 

@jim78b Be more specific on your post. My alteration to your routine just excludes dimensions from the changing of the color that you had in your original. Now I don't really understand exactly what you want. Post a sample drawing with the before and after.

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

@jim78b OK - I see. you have nested blocks within nested dynamic blocks. You need some kind of recursive function to drill all the way down. Not sure if I can help, but I'll give it a try as soon as I have some time.  For now, you can open up one of each of the dynamic clocks in refedit and run your command again and they will be done. Open the main block first with double click, then open the dynamic blocks with double-click and run AB on each of them.

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

I appreciate your help but I would like it to be done automatically the first time... is it difficult?

 

Link to comment
Share on other sites

@jim78b I don't know. I just don't deal with dynamic blocks so I am not sure why its not already working. I'm just missing something that maybe someone else here knows better?

Edited by pkenewell
  • Thanks 1
Link to comment
Share on other sites

OK - found something. I did some searching on earlier solutions to the problem. Try this code - it's working for me. It could be made shorter I think, but it works (use the code below, not the link).

Credit to Roy_043 from this post: 

 

(defun c:AB (/ blk doc i obj SS)
  (vl-load-com)
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  
  (vlax-for blk (vla-get-Blocks doc)
    (if (and (= (vla-get-isxref blk) :VLAX-FALSE)           ;ignores xrefs
             (not (wcmatch (vla-get-name blk) "*`**,*|*"))  ;ignores anonymous and xref blocks
        )
      (vlax-for obj blk
        (vla-put-Color obj 0) ;change all elements inside block to byblock
      )
    )
  )
  (if (setq SS (ssget "_X" '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
       (ChangeDynBlockColor (vla-get-name (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) 0)
       (vla-put-color obj 200)
    )
  )
  (vla-regen doc acAllViewports)
  (vla-EndUndoMark doc)
  (princ)
)

; Blk can be a block name or the ename of a "BLOCK" entity.
(defun KGA_BlockClassic_EffectiveName (blk / elst blkRecHnd)
  (setq elst (entget (if (= 'ename (type blk)) blk (tblobjname "block" blk))))
  (if
    (and
      (= "*" (substr (cdr (assoc 2 elst)) 1 1))
      (setq blkRecHnd (cdr (assoc 1005 (cdadr (assoc -3 (entget (cdr (assoc 330 elst)) '("AcDbBlockRepBTag")))))))
    )
    (cdr (assoc 2 (entget (handent blkRecHnd))))
    (cdr (assoc 2 elst))
  )
)

; (ChangeDynBlockColor (vla-get-name (vlax-ename->vla-object (car (entsel)))) (acad_colordlg 2))
(defun ChangeDynBlockColor (nme col / N_Mod blks i nmeLst)

  (defun N_Mod (blk)
    (vlax-for obj blk
      (if
        (and
          (= "AcDbBlockReference" (vla-get-objectname obj))
          (not (vl-position (strcase (vla-get-effectivename obj)) nmeLst))
        )
        (setq nmeLst (append nmeLst (list (strcase (vla-get-effectivename obj))))) ; Append required.
        (vla-put-color obj col)
      )
    )
  )

  (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
  (setq nmeLst (list (strcase (KGA_BlockClassic_EffectiveName nme))))
  (setq i 0)
  (while (< i (length nmeLst))
    (setq nme (nth i nmeLst))
    (vlax-for blk blks
      (if (= nme (strcase (KGA_BlockClassic_EffectiveName (vla-get-name blk))))
        (N_Mod blk)
      )
    )
    (setq i (1+ i))
  )
)

 

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

8 minutes ago, jim78b said:

wonderful you are the best!!! thanks a lot!

@jim78b OOPS - I made a slight change to the routine above. Re-copy it from the post. I realized it changes everything to color 200, rather than changing everything inside blocks to ByBlock. corrected.

  • Thanks 1
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...