Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

select and bind all xrefs in modelspace

10 REPLIES 10
Reply
Message 1 of 11
dtiemeyer
7111 Views, 10 Replies

select and bind all xrefs in modelspace

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.

 

My other CAD is a Cadillac and I like to Revit to the Max!
10 REPLIES 10
Message 2 of 11
pbejse
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

 

Message 3 of 11
dtiemeyer
in reply to: pbejse

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

My other CAD is a Cadillac and I like to Revit to the Max!
Message 4 of 11
Kent1Cooper
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, AIA
Message 5 of 11
dtiemeyer
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

My other CAD is a Cadillac and I like to Revit to the Max!
Message 6 of 11
pbejse
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.  Smiley Happy

 

 

 

 

 

Message 7 of 11
NOD684
in reply to: dtiemeyer

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

"memories fade but the scars still linger"
Message 8 of 11
pbejse
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 🙂

Message 9 of 11
NOD684
in reply to: pbejse

Thanks for the Welcome pbejse 🙂 

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"
Message 10 of 11
NOD684
in reply to: dtiemeyer

nevermind 🙂 figured it out now 🙂
its working fine...

"memories fade but the scars still linger"
Message 11 of 11
msarqui
in reply to: NOD684

Hi NOD684

 

Could you share your routine because I am looking for something similar?

 

I am searching for a routine that detach all unreferenced xrefs (including dwg, image, dwf, dgn and pdf) and then bind all referenced dwg xrefs.

 

Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost