Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(setq e (entget (car (entsel)))) question

16 REPLIES 16
Reply
Message 1 of 17
coachball8
1916 Views, 16 Replies

(setq e (entget (car (entsel)))) question

I need to select a block, then iterate thru the sub-entities to change all the mtext to a different layer. I can get
(setq d (assoc 8 e))
(setq e2 (subst '(8 . "mylayer") d e1))
(entmod e2), however, I can't seem to figure out to isolate the mtext. Another option would be to use nentsel and be able to select all the text at once, but nentsel doesn't allow me to do that. What's the best way to accomplish this? TIA
16 REPLIES 16
Message 2 of 17
BillZ
in reply to: coachball8

I don't know who posted this.

;9/11/02
;to find nested entities in block in a drawing;
;
;
;
;
(defun getNestedEnts (name / rtn)
(setq ename (tblobjname "block" name))
(while ename
(if (/= (cdr (assoc 0 (entget ename))) "INSERT")
(setq rtn (cons ename rtn))
(setq inn (cons ename inn))
)
(setq ename (entnext ename))
)
(reverse rtn)
)

I used it once and it seemed to work.

Bill I changed the description as it was a copy form another program.
Message was edited by: BillZ
Message 3 of 17
coachball8
in reply to: coachball8

Thanks Bill. I saw this post and tried it this way, but on line one I get an "error: bad argument type: stringp nil". Couldn't really figure out what the problem was with it, so I tried some other methods. Can't seem to get there. It's probably really simple once I see how it's done. Any other suggestions?
Message 4 of 17
Anonymous
in reply to: coachball8

If it's mtext, then you must use the block name and do a tblsearch/tblnext thing, see comments and hints in following lisp (defun c:fixents (/ ss1 temp ent1 looper entdat bnm ctr enttyp bl_list) (command ".layer" "t" "0" "un" "0" "s" "0" "") (setq ss1 (ssadd) looper T ctr 0) (while looper (prompt "\nSelect Entities to set to Bylayer for Colour and Linetype: ");;;revise this (setq ss1 (ssget));;;revise this to filter for inserts (if ss1 (setq looper nil)) ) (repeat (sslength ss1) (setq ent1 (ssname ss1 ctr) entdat (entget ent1) enttyp (cdr (assoc 0 entdat))) (if (= enttyp "INSERT") (progn (setq bl_list (list (cdr (assoc 2 entdat)))) (foreach bnm bl_list (jddfixablock bnm) ) ) (progn (setq entdat (subst (cons 62 256)(assoc 62 entdat) entdat) entdat (subst (cons 6 "Bylayer")(assoc 6 entdat) entdat) ) (entmod entdat)(entupd ent1) ) ) (setq ctr (+ ctr 1)) ) (princ) ) (defun jddfixablock (bname / enam1 end1) (setq enam1 (tblobjname "block" bname)) (while (setq enam1 (entnext enam1)) (setq end1 (entget enam1) ;;;step thru block def ;;;put your test for mtext here ;;; end1 (subst (cons 62 256)(assoc 62 end1) end1)) ;;; end1 (subst (cons 6 "Bylayer")(assoc 6 end1) end1)) end1 (subst (cons 8 "0")(assoc 8 end1) end1)) ;;;make this the layer you want ) (entmod end1) ;;;end of mtext test ;;; if your block def contains an insert - get the block name of the insert and add it to our block name list (if (= (cdr (assoc 0 (entget enam1))) "INSERT")(setq bl_list (append bl_list (list (cdr (assoc 2 (entget ent1))))))) ) ) HTH Jamie Duncan "coachball8" wrote in message news:11304391.1085655427886.JavaMail.jive@jiveforum2.autodesk.com... > I need to select a block, then iterate thru the sub-entities to change all the mtext to a different layer. I can get > (setq d (assoc 8 e)) > (setq e2 (subst '(8 . "mylayer") d e1)) > (entmod e2), however, I can't seem to figure out to isolate the mtext. Another option would be to use nentsel and be able to select all the text at once, but nentsel doesn't allow me to do that. What's the best way to accomplish this? TIA
Message 5 of 17
BillZ
in reply to: coachball8

Works here.

(load "getNestedEnts")
(getNestedEnts "NameOfBlock")

Returns a list of enames with the block ename first.

But I don't have any really complex blocks to test.
What's in the blocks you are refering to?

Bill
Message 6 of 17
coachball8
in reply to: coachball8

It's just a rev block. Lines and text. Built on layer 0, inserted on the correct layer for the lines. The text is required to be on a different layer. I'd like to change the text layer with click of a toolbar button, if possible. We can't build the block on the correct layers, because different divisions of the company have different layer tables. However, we all use the same blocks, stored on a server. Just trying to save a few mouse clicks.
Message 7 of 17
BillZ
in reply to: coachball8

Well I just tried it again on a block that has 25 circles, lines and 3d faces and got the list just fine.

Can you post what your lisp looks like so someone may tell you what might be wrong?

Bill
Message 8 of 17
coachball8
in reply to: coachball8

I got it to work......I wasn't adding the block name at the command line. DUH! Thanks for the help, Bill. Long week. I'm ready for a vacation.
Message 9 of 17
BillZ
in reply to: coachball8

You're welcome.

Enjoy your vacation.

Bill
Message 10 of 17
Anonymous
in reply to: coachball8

coachball8 You can't modify Block Inserts, you have to change the Block Reference: (defun BlkMod (Nme Lay / BlkTbl CurEnt EntLst) (setq BlkTbl (tblobjname "BLOCK" Nme) CurEnt (cdr (assoc -2 (entget BlkTbl))) ) (while (setq CurEnt (entnext CurEnt)) (setq EntLst (entget CurEnt)) (if (eq (cdr (assoc 0 EntLst)) "MTEXT") (entmod (subst (cons 8 Lay) (assoc 8 EntLst) EntLst ) ) ) ) (entupd BlkTbl) (command "_.REGEN") (princ) ) Use: (BlkMod "MyBlockName" "NewLayer") Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
Message 11 of 17
coachball8
in reply to: coachball8

Thanks for the help. That's really what I was trying to, but I don't have enough experience to get it done. I came up with this from some code Jason P. had posted:

(defun C:Chrblyr (/ Ent Lst Clr)
(while (not (setq Ent (nentsel "\nselect an object: "))))

(while Ent
(setq Lst (cons (car Ent) Lst))
(setq Ent (nentsel "\nselect an object : "))
)

;(while (or (not Clr) (> Clr 256))
;(initget 6) (setq Clr (getint "\nspecify a color number: "))
😉

(foreach x Lst (vla-put-layer (vlax-ename->vla-object x) "mylayer"))
(princ)
)
It works okay, but you have to select each piece of text, and it doesn't regen. Yours works better. Thanks to you and Bill. You guys are great!
Message 12 of 17
Anonymous
in reply to: coachball8

I think I revised this properly, you may want to check the parenteses...:-) this is done in simple lisp - and offers recursion for nested blocks - an alternate to Jurg's posting Jamie Duncan (defun c:fixents (/ ss1 temp ent1 looper entdat bnm ctr enttyp bl_list new_lay) (command ".layer" "t" "0" "un" "0" "s" "0" "") (setq ss1 (ssadd) looper T ctr 0) (setq new_lay (getvar "clayer")) (while looper (prompt "\nSelect Entities to set to Bylayer for Colour and Linetype: ") (setq ss1 (ssget)) (if ss1 (setq looper nil)) ) (repeat (sslength ss1) (setq ent1 (ssname ss1 ctr) entdat (entget ent1) enttyp (cdr (assoc 0 entdat))) (if (= enttyp "INSERT") (progn (setq bl_list (list (cdr (assoc 2 entdat)))) (foreach bnm bl_list (jddfixablock bnm) ) ) ) (setq ctr (+ ctr 1)) ) (princ) ) (defun jddfixablock (bname new_lay / enam1 end1) (setq enam1 (tblobjname "block" bname)) (while (setq enam1 (entnext enam1)) (setq end1 (entget enam1)) (if (= (cdr (assoc 0 end1)) "MTEXT") (progn (setq end1 (subst (cons 8 new_lay)(assoc 8 end1) end1)) (entmod end1) ) (progn (if (= (cdr (assoc 0 (entget enam1))) "INSERT") (setq bl_list (append bl_list (list (cdr (assoc 2 (entget ent1)))))) ) ) ) ) )
Message 13 of 17
Anonymous
in reply to: coachball8

coachball8 Glad to help you... My proposition to use the function: (remove the Regen command from 'BlkMod') (defun C:ChangeBlockMtextLayer ( / CurEnt CurSet) (princ "\nSelect Blocks...") (if (setq CurSet (ssget '((0 . "INSERT")))) (progn (while (setq CurEnt (ssname CurSet 0)) (BlkMod (cdr (assoc 2 (entget CurEnt))) "NewLayerName") (ssdel CurEnt CurSet) ) (command "_.REGEN") ) ) (princ) ) This allows you to select *all* block you wish to change... Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch
Message 14 of 17
coachball8
in reply to: coachball8

Thanks again, but I have yet another question. I'd like to use a wildcard in the block name, since all the blocks have the same name, but are prefixed by a number (i.e. 1_revblk__000 would be for an a-sized dwg, while 2_revblk___000 would be for a b-size, and so on and so forth). I can't use wildcards with this, so how can I create a list of the blocks, and then search only those on the list. Thanks again for your help.
Message 15 of 17
coachball8
in reply to: coachball8

Thanks to you too, Jamie. I'll give it a whirl.
Message 16 of 17
EC-CAD
in reply to: coachball8

..Loop for each block.
(setq str (substr bname 3 6)); 'revblk' portion
(if (= (strcase str) "REVBLK")
(progn
..do operations
); end prog
); end if
-------------------

Bob
Message 17 of 17
Anonymous
in reply to: coachball8

coachball8 (defun C:ChangeBlockMtextLayer ( / CurEnt CurSet) (if (setq CurSet (ssget "X" '((0 . "INSERT")(2 . "#_revblk__000")))) (progn (while (setq CurEnt (ssname CurSet 0)) (BlkMod (cdr (assoc 2 (entget CurEnt))) "NewLayerName") (ssdel CurEnt CurSet) ) (command "_.REGEN") ) ) (princ) ) Cheers -- Juerg Menzi MENZI ENGINEERING GmbH, Switzerland http://www.menziengineering.ch

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost