Ahankhah Posted July 23, 2011 Share Posted July 23, 2011 Hi everyone, I want to wblock all blocks, even not inserted, but existing as named objects. But, when I use tblsearch, tblnext, ... functions, they return xrefs as well. How I can distinguish blocks from the list of names returned by mentioned functions? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
pBe Posted July 23, 2011 Share Posted July 23, 2011 tblsearch True for regualr blocks (< (logior 2 (cdr (assoc 70 (tblsearch "BLOCK" "XrefBlock")))) 3) (< (logior 2 (cdr (assoc 70 (tblsearch "BLOCK" "RegularBlock")))) 3) tblnext (< (logior 2 (cdr(assoc 70 (tblnext "BLOCK")))) 3) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 23, 2011 Share Posted July 23, 2011 This may do the trick . (defun c:ExportBlks (/ blk l ss) ;; Tharwat 23. 07. 2011 (while (setq blk (tblnext "BLOCK" (null blk))) (member (cdr (assoc 2 blk)) (setq l (cons (cdr (assoc 2 blk)) l)) ) ) (setq ss (ssadd)) (foreach x l (command "_.-insert" x '(0. 0. 0.) "" "" "") (ssadd (entlast) ss) ) (command "._wblock" (strcat (getvar 'dwgprefix) "DrawingName.dwg") "" "_Non" '(0.0 0.0 0.0) ss "" ) (command "_.erase" (sssetfirst nil ss) "") (princ) ) Tharwat Quote Link to comment Share on other sites More sharing options...
pBe Posted July 23, 2011 Share Posted July 23, 2011 tharwat.. You need to filter the list to exclude XREFS and with proper function you dont need to insert the blocks before invoking Wblock. look into WBLOCK Method or supply the block name here Enter name of existing block or [= [b](block=output file)/[/b]* (whole drawing)] <define new drawing>: Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 23, 2011 Share Posted July 23, 2011 I guess the Xref Blocks can not be inserted by the insert command and that's why I use it to avoid selecting Xref's . Quote Link to comment Share on other sites More sharing options...
pBe Posted July 23, 2011 Share Posted July 23, 2011 The point is not to invoke unecessary lines as overhead like "INSERT" "ERASE" a simple test will tell you its not an XREF (< (logior 2 (cdr(assoc 70 (tblnext "BLOCK")))) 3) Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted July 23, 2011 Author Share Posted July 23, 2011 pBe and Tharwat, thank you for your kind help. I will try them. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 23, 2011 Share Posted July 23, 2011 The point is not to invoke unecessary lines as overhead like "INSERT" "ERASE" a simple test will tell you its not an XREF (< (logior 2 (cdr(assoc 70 (tblnext "BLOCK")))) 3) That's right if the OP wants to use ssget "_x" to select all blocks and filter them to avoid the Xref , and check this out . I want to wblock all blocks, even not inserted, but existing as named objects. Quote Link to comment Share on other sites More sharing options...
pBe Posted July 23, 2011 Share Posted July 23, 2011 (edited) The best way is to make a list of Blocks not thru selection but from Block Table. SSGET wont select you UN-INSERTED blocks and you can supply just the block name (after filtering the list) without selecting the block itself. the name alone will be sufficient enough So no need to invoke INSERT and ERASE something like this (while (setq blk (tblnext "BLOCK" (null blk))) (if (< (logior 2 (cdr(assoc 70 blk))) 3) (command "._wblock" (strcat "d:\\[color=blue]path[/color]\\" (setq nm (cdr (assoc 2 blk)))) nm ))) EDIT: (defun c:WBBlock (/ blk ChkNme nm) (while (setq blk (tblnext "BLOCK" (null blk))) (if (< (logior 2 (cdr (assoc 70 blk))) 3) (progn (command "._wblock" (setq ChkNme (strcat "d:\\path\\" (setq nm (cdr (assoc 2 blk))) ".dwg"))) (while (> (getvar 'cmdactive) 0) (if (findfile ChkNme) (command "Y" nm) (command nm))) ) ) ) ) Edited July 23, 2011 by pBe Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 23, 2011 Share Posted July 23, 2011 pBe your routine would write each block to a separate drawing which would contain one block only . Regards. Quote Link to comment Share on other sites More sharing options...
pBe Posted July 23, 2011 Share Posted July 23, 2011 pBe your routine would write each block to a separate drawing which would contain one block only . Regards. Yes it does, does it? Not really sure what Ahankhah is intending to do with the blocks. but Wblocks purpose is to Writes objects or a block to a new drawing file if he wanted to collect blocks into a single drawing might as well use Design Center. browse thru the folder list and drag over to a new drawing and save it. Then he can use that new drawing to retrieve the blocks thru Design Center as well. Better yet use Tool Palettes (its a great tool) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 23, 2011 Share Posted July 23, 2011 pBe , I know that my routine have a crazy idea , but it gives a good result Quote Link to comment Share on other sites More sharing options...
pBe Posted July 23, 2011 Share Posted July 23, 2011 pBe , I know that my routine have a crazy idea , but it gives a good result Indeed :wink: Cheers Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 23, 2011 Share Posted July 23, 2011 (edited) To check for Xrefs, I use: (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" <BlockName>))))) But you might also want to exclude externally dependent blocks, i.e. blocks within xRefs, by filtering out bit 16. This could be a general function: (defun _BlockList ( ignore / def lst ) (while (setq def (tblnext "BLOCK" (null def))) (if (zerop (boole 1 ignore (cdr (assoc 70 def)))) (setq lst (cons (cdr (assoc 2 def)) lst)) ) ) lst ) List excluding xRefs (and xRef dependent): (_BlockList 20) To exclude anonymous blocks also: (_BlockList 21) Edited July 23, 2011 by Lee Mac Quote Link to comment Share on other sites More sharing options...
irneb Posted July 23, 2011 Share Posted July 23, 2011 Good one Lee! BTW, why did you use (boole 1 ...)? Why not simply (logand ...)? Does the same right? Boole: http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6a92.htm LogAnd: http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69bb.htm Or am I missing something? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 23, 2011 Share Posted July 23, 2011 Good one Lee! BTW, why did you use (boole 1 ...)? Why not simply (logand ...)? Does the same right? Yup, does the same thing - just wanted to mix it up I suppose, boole is a lot more versatile in many situations Quote Link to comment Share on other sites More sharing options...
irneb Posted July 23, 2011 Share Posted July 23, 2011 Oh ... OK! I guess the boole was added way back when, because the original creator(s) of AutoLisp started with logand & logior and then thought: "Aghhh! Too much hassles, just combine them into one!" Otherwise we'd have had a logxor and lognor as well! BTW, that boole gives some really "strange" results if you go and play with the "non-documented" bitcodes. I suppose you "might" have a strange situation where you want a result of 1 coming from 1 & 2, but 2 coming from 2 & 1 ... try that with (boole 3 ...)! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 23, 2011 Share Posted July 23, 2011 I usually find the boole function very useful for situations in which the bitwise logic is dependent upon the supplied argument, as a quick example: ;; Freeze/Thaw Layer - Lee Mac ;; layer - layer name ;; freeze - t/nil (defun _FreezeThawLayer ( layer freeze ) (if (setq layer (tblobjname "LAYER" layer)) ( (lambda ( elist ) (entmod (subst (cons 70 (boole (if freeze 7 4) 1 (cdr (assoc 70 elist)))) (assoc 70 elist) elist))) (entget layer) ) ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted July 24, 2011 Share Posted July 24, 2011 But you might also want to exclude externally dependent blocks, i.e. blocks within xRefs, by filtering out bit 16...... I hadnt thought of that.. good point Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 24, 2011 Share Posted July 24, 2011 I guess the boole was added way back when, because the original creator(s) of AutoLisp started with logand & logior and then thought: "Aghhh! Too much hassles, just combine them into one!" Otherwise we'd have had a logxor and lognor as well! Just for fun... Assume the boole function doesn't exist... ([color=BLUE]defun[/color] logxor ( a b ) ([color=BLUE]logand[/color] ([color=BLUE]logior[/color] a b) ([color=BLUE]~[/color] ([color=BLUE]logand[/color] a b))) ) ([color=BLUE]defun[/color] lognor ( a b ) ([color=BLUE]~[/color] ([color=BLUE]logior[/color] a b)) ) ([color=BLUE]defun[/color] lognor ( a b ) ([color=BLUE]logand[/color] ([color=BLUE]~[/color] a) ([color=BLUE]~[/color] b)) ) ([color=BLUE]defun[/color] lognand ( a b ) ([color=BLUE]~[/color] ([color=BLUE]logand[/color] a b)) ) ([color=BLUE]defun[/color] lognand ( a b ) ([color=BLUE]logior[/color] ([color=BLUE]~[/color] a) ([color=BLUE]~[/color] b)) ) ([color=BLUE]defun[/color] logxnor ( a b ) ([color=BLUE]logior[/color] ([color=BLUE]logand[/color] a b) ([color=BLUE]logand[/color] ([color=BLUE]~[/color] a) ([color=BLUE]~[/color] b))) ) Of course, the boole function makes life easier... ([color=BLUE]defun[/color] logxor ( a b ) ([color=BLUE]boole[/color] 6 a b) ) ([color=BLUE]defun[/color] lognor ( a b ) ([color=BLUE]boole[/color] 8 a b) ) ([color=BLUE]defun[/color] lognand ( a b ) ([color=BLUE]boole[/color] 14 a b) ) ([color=BLUE]defun[/color] logxnor ( a b ) ([color=BLUE]boole[/color] 9 a b) ) Quick example: [color=GREEN];;;---------------------------------[/color] [color=GREEN];;; 32 16 8 4 2 1 [/color] [color=GREEN];;;=================================[/color] [color=GREEN];;; Int1 0 1 1 0 1 0 = 26[/color] [color=GREEN];;;---------------------------------[/color] [color=GREEN];;; Int2 1 1 0 1 1 0 = 54[/color] [color=GREEN];;;=================================[/color] [color=GREEN];;; LOGAND 0 1 0 0 1 0 = 18[/color] [color=GREEN];;;=================================[/color] [color=GREEN];;; LOGIOR 1 1 1 1 1 0 = 62[/color] [color=GREEN];;;=================================[/color] [color=GREEN];;; LOGXOR 1 0 1 1 0 0 = 44[/color] [color=GREEN];;;=================================[/color] Or for multiple integers... ([color=BLUE]defun[/color] logxor ( l ) ([color=BLUE]logand[/color] ([color=BLUE]apply[/color] '[color=BLUE]logior[/color] l) ([color=BLUE]~[/color] ([color=BLUE]apply[/color] '[color=BLUE]logand[/color] l))) ) ([color=BLUE]defun[/color] lognor ( l ) ([color=BLUE]~[/color] ([color=BLUE]apply[/color] '[color=BLUE]logior[/color] l)) ) ([color=BLUE]defun[/color] lognor ( l ) ([color=BLUE]apply[/color] '[color=BLUE]logand[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]~[/color] l)) ) ([color=BLUE]defun[/color] lognand ( l ) ([color=BLUE]~[/color] ([color=BLUE]apply[/color] '[color=BLUE]logand[/color] l)) ) ([color=BLUE]defun[/color] lognand ( l ) ([color=BLUE]apply[/color] '[color=BLUE]logior[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]~[/color] l)) ) ([color=BLUE]defun[/color] logxnor ( l ) ([color=BLUE]logior[/color] ([color=BLUE]apply[/color] '[color=BLUE]logand[/color] l) ([color=BLUE]apply[/color] '[color=BLUE]logand[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]~[/color] l))) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.