Jump to content

I want just Blocks and not Xrefs


Ahankhah

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by pBe
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 by Lee Mac
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! :unsure:

 

BTW, that boole gives some really "strange" results if you go and play with the "non-documented" bitcodes. :shock: 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 ...)!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

:)

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