• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Distinguished Contributor
    Posts: 290
    Registered: ‎01-09-2004

    select and bind all xrefs in modelspace

    296 Views, 10 Replies
    10-09-2012 07:25 AM

    Does anybody have any code that will select all xrefs in modelspace and bind (insert) them?

     

    the   -xref  bind command requires explicit names and if I use * it will also bind my titleblock xref in paperspace which I want to avoid.

     

    Striving to be a WOMBAT, Waste Of Money, Brains, & Talent...

    ⁞|⁞ Please use the Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos functions as appropriate to further enhance the value of these forums. Thank you!
    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: select and bind all xrefs in modelspace

    10-09-2012 07:52 AM in reply to: dtiemeyer

    dtiemeyer wrote:

    Does anybody have any code that will select all xrefs in modelspace and bind (insert) them?

     

    the   -xref  bind command requires explicit names and if I use * it will also bind my titleblock xref in paperspace which I want to avoid.

     


    (defun c:XrefBind (/ tmpObj)
      (vl-load-com)
      (vlax-for objs (vla-get-ModelSpace
    		   (vla-get-activedocument (vlax-get-acad-object))
    		 )
        (if
          (and
    	(= (vla-get-ObjectName objs) "AcDbBlockReference")
    	(vlax-property-available-p objs 'Path)
    	(setq
    	  tmpObj (vla-Item
    		   (vla-get-Blocks
    		     (vla-get-ActiveDocument (vlax-get-Acad-Object))
    		   )
    		   (vla-get-Name objs)
    		 )
    	)
    	(not (assoc 71 (entget (tblobjname "block" (vla-get-Name objs)))))
          )
           (vla-Bind tmpObj :vlax-true)
        )
      )
    
      (princ)
    )

     

    HTH

     

    Please use plain text.
    Distinguished Contributor
    Posts: 290
    Registered: ‎01-09-2004

    Re: select and bind all xrefs in modelspace

    10-09-2012 10:28 AM in reply to: pbejse

    Works awesome, thanks. But how would I make it 'just run' without waiting for user input?

    Striving to be a WOMBAT, Waste Of Money, Brains, & Talent...

    ⁞|⁞ Please use the Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos functions as appropriate to further enhance the value of these forums. Thank you!
    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,058
    Registered: ‎09-13-2004

    Re: select and bind all xrefs in modelspace

    10-09-2012 11:57 AM in reply to: dtiemeyer

    dtiemeyer wrote:

    Does anybody have any code that will select all xrefs in modelspace and bind (insert) them?

     

    the   -xref  bind command requires explicit names and if I use * it will also bind my titleblock xref in paperspace which I want to avoid.


    Here's another way to do it [minimally tested]:
     

    (foreach x
      (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (410 . "MODEL")))))
      (setq blk (cdr (assoc 2 (entget x))))
      (if (assoc 1 (tblsearch "block" blk)) (command "_.xref" "_bind" blk))
    )

     

    It finds all insertions in model space, puts them into a list of entity names, and for each one, looks at whether its entry in the Block table is an Xref by checking whether it has an "Xref path name" [the (assoc 1) entry -- regular Blocks don't have one].  If so, it binds that Xref name.

     

    If you want it to "just run" without User input, does that mean you want to do it in all drawings that you open?  Sounds dangerous, but if that's what you mean, you could include the above code in something automatic like acaddoc.lsp.  Otherwise, put it into a command name as with pbejse's routine.

    Kent Cooper
    Please use plain text.
    Distinguished Contributor
    Posts: 290
    Registered: ‎01-09-2004

    Re: select and bind all xrefs in modelspace

    10-09-2012 02:38 PM in reply to: Kent1Cooper

    Hi Kent,

    Thanks for that, it is exactly what I was looking for. And you're right, I did mean to 'invoke' it manually but then let the command complete without user input.

     

    Cheers!

     

    Dustin

    Striving to be a WOMBAT, Waste Of Money, Brains, & Talent...

    ⁞|⁞ Please use the Mark Solutions!.Accept as Solution and Give Kudos!Give Kudos functions as appropriate to further enhance the value of these forums. Thank you!
    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: select and bind all xrefs in modelspace

    10-09-2012 06:14 PM in reply to: dtiemeyer

    dtiemeyer wrote:

    Works awesome, thanks. But how would I make it 'just run' without waiting for user input?


    Glad it helps

     

    Not sure what you meant by 'just run' though.  :smileyhappy:

     

     

     

     

     

    Please use plain text.
    Member
    Posts: 3
    Registered: ‎07-13-2012

    Re: select and bind all xrefs in modelspace

    10-18-2012 10:58 PM in reply to: dtiemeyer

    can it be modified to detach unloaded Xrefs then bind all loaded xref?

    "memories fade but the scars still linger"
    Please use plain text.
    *Expert Elite*
    Posts: 2,057
    Registered: ‎11-24-2009

    Re: select and bind all xrefs in modelspace

    10-19-2012 12:19 AM in reply to: NOD684

    NOD684 wrote:

    can it be modified to detach unloaded Xrefs then bind all loaded xref?


    Are you aware that ithe code process exclusively Model space instances of XREF? also it ignores "unreferenced" xref as it wont be included in the selection set.

     

    Can you give more info.

     

    Cheers

     

    Welcome to the Forum NOD684 :smileyhappy:

    Please use plain text.
    Member
    Posts: 3
    Registered: ‎07-13-2012

    Re: select and bind all xrefs in modelspace

    10-19-2012 12:59 AM in reply to: pbejse

    Thanks for the Welcome pbejse :smileyhappy: 

    Yes am aware of that...i even tested it.

    i have a lisp before that detaches unloaded xref then binds all the loaded xref

     

    but unfortunately its not working in 2010 version...

     

    that is why i ask if it is possible to have such lisp

    "memories fade but the scars still linger"
    Please use plain text.
    Member
    Posts: 3
    Registered: ‎07-13-2012

    Re: select and bind all xrefs in modelspace

    10-19-2012 01:25 AM in reply to: dtiemeyer

    nevermind :smileyhappy: figured it out now :smileyhappy:
    its working fine...

    "memories fade but the scars still linger"
    Please use plain text.