Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Mentor
dtiemeyer
Posts: 378
Registered: ‎01-09-2004
Message 1 of 11 (762 Views)

select and bind all xrefs in modelspace

762 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*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 2 of 11 (759 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
dtiemeyer
Posts: 378
Registered: ‎01-09-2004
Message 3 of 11 (746 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: 5,370
Registered: ‎09-13-2004
Message 4 of 11 (738 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
dtiemeyer
Posts: 378
Registered: ‎01-09-2004
Message 5 of 11 (726 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*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 6 of 11 (716 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
NOD684
Posts: 3
Registered: ‎07-13-2012
Message 7 of 11 (677 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*
pbejse
Posts: 2,459
Registered: ‎11-24-2009
Message 8 of 11 (665 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
NOD684
Posts: 3
Registered: ‎07-13-2012
Message 9 of 11 (658 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
NOD684
Posts: 3
Registered: ‎07-13-2012
Message 10 of 11 (649 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"
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.