Visual LISP, AutoLISP and General Customization

Reply
Mentor
Posts: 363
Registered: ‎01-09-2004
Message 1 of 11 (566 Views)

select and bind all xrefs in modelspace

566 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!
*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 2 of 11 (563 Views)

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

 

Mentor
Posts: 363
Registered: ‎01-09-2004
Message 3 of 11 (550 Views)

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!
*Expert Elite*
Kent1Cooper
Posts: 4,939
Registered: ‎09-13-2004
Message 4 of 11 (542 Views)

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
Mentor
Posts: 363
Registered: ‎01-09-2004
Message 5 of 11 (530 Views)

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!
*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 6 of 11 (520 Views)

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:

 

 

 

 

 

Member
Posts: 3
Registered: ‎07-13-2012
Message 7 of 11 (481 Views)

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"
*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 8 of 11 (469 Views)

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:

Member
Posts: 3
Registered: ‎07-13-2012
Message 9 of 11 (462 Views)

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"
Member
Posts: 3
Registered: ‎07-13-2012
Message 10 of 11 (453 Views)

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"

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community