Jump to content

select xrefs lisp


daisenson

Recommended Posts

Could anyone tell me how to select all the xrefs in a drawings and move them to a specific layer (440_XREF)?

 

I've tried all other posts related to this topic, but unfortunately my knowledge of coding doesn't stretch further than:

 

(setq sel1 (ssget "x" '((0 . "insert"))))

this will select all blocks, including xrefs but I don't know how to filter them.

 

thanks

Link to comment
Share on other sites

[b][color=BLACK]([/color][/b]defun c:xreflist [b][color=FUCHSIA]([/color][/b]/ tdef xl[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq tdef [b][color=MAROON]([/color][/b]tblnext [color=#2f4f4f]"BLOCK"[/color] [b][color=GREEN]([/color][/b]not tdef[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]logand [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 70 tdef[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] 4[b][color=GREEN])[/color][/b] 4[b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]setq xl [b][color=GREEN]([/color][/b]cons [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 2 tdef[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] xl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 xl[b][color=BLACK])[/color][/b]

 

 

You have to examine each BLOCK table defintion to determine if the BLOCK is an external reference

 

Step through the BLOCK table definitions using (tblnext)

If the BLOCK flag ( group 70 ) 4 bit is set,

then add the BLOCK name ( group 2) to the list 'xl

 

xl is a list containing the names of xrefs found

 

The problem then lays in the fact that some of these BLOCKs may nested in other xrefs, so that CHPROP cannot manipulate the layers.

 

Or it may be as simple as:

[b][color=BLACK]([/color][/b]foreach b xl
 [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]cons 2 b[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_.CHPROP"[/color] ss [color=#2f4f4f]""[/color] [color=#2f4f4f]"_LA"[/color] [color=#2f4f4f]"440_XREF"[/color] [color=#2f4f4f]""[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

HTH -David

Link to comment
Share on other sites

you can also do it this way

 

(setq xr_dwg (vla-get-activedocument (vlax-get-acad-object))
xr_blk (vla-get-blocks xr_dwg))
(vlax-for blk xr_blk
  (if (= (vla-get-IsXRef blk) :vlax-true)
    (setq xl (cons (vla-get-name blk) xl))
  )
 )

 

and used the second part of daivds :)

Link to comment
Share on other sites

you can also do it this way

(setq xr_dwg (vla-get-activedocument (vlax-get-acad-object))
xr_blk (vla-get-blocks xr_dwg))
(vlax-for blk xr_blk
  (if (= (vla-get-IsXRef blk) :vlax-true)
    (setq xl (cons (vla-get-name blk) xl))
  )
 )

 

and used the second part of daivds :)

 

Great work pBe.

 

May I ask you how to get the full path of the Xref dwg. ?

 

Many thanks

Link to comment
Share on other sites

(setq xr_dwg (vla-get-activedocument (vlax-get-acad-object))
xr_blk (vla-get-blocks xr_dwg))
(vlax-for blk xr_blk
  (if (= (vla-get-IsXRef blk) :vlax-true)(progn
    (setq xl (cons (vla-get-name blk) xl))
  (print (vla-get-path blk))(princ))        
  )
 )

 

just add (vla-get-path ..)

there you go

 

thanks michaels

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