@bsanada hi,
check this XREFOUT command.
Run this only on master.dwg after you exactly placed all your xrefs.
the command starts by asking the folder to save the xrefs. of course you could select the origin folder and override the origin xrefs but it's recommended to place them in a new.
thank you Lee Mac for the amazing (LM:browseforfolder) function.
before run, it is recommended to manually try to bind each xref to reduce failures at run time.
to achieve what you want, xrefout do:
1. set xref scale to 1x1
2. set xref rotation to 0
3. xref bind
4. explode blocks
5. turn all layers on
6. gather all exploded objects to SS selection set.
7. write out block (WBLOCK)
Cause you said i have several hundred xrefs this could be long process... a progress bar is used.
if it work without errors, your master drawing should be left intact 😀
enjoy
Moshe
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
(setq err
(vl-catch-all-apply
(function
(lambda ( / app hwd )
(if (setq app (vlax-get-acad-object)
shl (vla-getinterfaceobject app "shell.application")
hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
)
(setq slf (vlax-get-property fld 'self)
pth (vlax-get-property slf 'path)
pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
)
)
)
)
)
)
(if slf (vlax-release-object slf))
(if fld (vlax-release-object fld))
(if shl (vlax-release-object shl))
(if (vl-catch-all-error-p err)
(prompt (vl-catch-all-error-message err))
pth
)
)
(defun c:xrefout (/ is_acetutil_modula_exist objects_counter get_last_ent
adoc blocks folder ctr pbar_ctr AcDbEntity AcDbBlkTblRec
xname xrefname newxrefname ename ss xn xname)
(defun is_acetutil_modula_exist ()
(if (null (member "acetutil.arx" (arx)))
(progn
(setq *isAcetUtil* :vlax-false)
(vlr-beep-reaction)
(prompt "\nacetutil.arx modula is not loaded.")
)
(setq *isAcetUtil* :vlax-true)
)
)
(defun objects_counter (/ counter AcDbBlkTblRec)
(setq counter -1)
(vlax-for AcDbBlkTblRec blocks
(if (and
(eq (vla-get-isXref AcDbBlkTblRec) :vlax-true)
(ssget "_x" (list '(0 . "insert") (cons '2 (vla-get-name AcDbBlkTblRec))))
)
(setq counter (+ counter (vla-get-count AcDbBlkTblRec)))
)
)
counter
)
(defun get_last_entity ()
(command "._point" "0,0,0")
(entlast)
)
: Here start c:xrefout
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark adoc)
(setq blocks (vla-get-blocks adoc))
(setvar "cmdecho" 0)
(setvar "expert" 5)
(if (setq folder (LM:browseforfolder "Select a folder" (getvar "dwgprefix") 0))
(progn
(is_acetutil_modula_exist)
(setq ctr (objects_counter))
(if (eq *isAcetUtil* :vlax-true)
(progn
(acet-ui-progress-init "Processing" ctr)
(setq pbar_ctr -1)
)
)
(vlax-for AcDbEntity (vla-get-modelspace adoc)
(if (and
(eq (vla-get-objectname AcDbEntity) "AcDbBlockReference")
(not (wcmatch (setq xname (vla-get-name AcDbEntity)) "`*U*"))
(null (member (strcase xname) lst))
(setq AcDbBlkTblRec (vla-item blocks xname))
(eq (vla-get-isXref AcDbBlkTblRec) :vlax-true)
(setq xrefname (vla-get-path AcDbBlkTblRec))
(setq newxrefname (strcat folder "\\" (vl-filename-base xrefname) ".dwg"))
)
(progn
(vlax-release-object AcDbBlkTblRec)
(setq AcDbBlkTblRec nil)
(if (eq *isAcetUtil* :vlax-true)
(progn
(setq pbar_ctr (1+ pbar_ctr))
(acet-ui-progress-safe pbar_ctr)
)
)
(command "._undo" "_begin")
(setq ss (ssadd) ename (get_last_entity))
(vla-put-XScaleFactor AcDbEntity 1.0)
(vla-put-YScaleFactor AcDbEntity 1.0)
(vla-put-ZScaleFactor AcDbEntity 1.0)
(vla-put-rotation AcDbEntity 0.0)
(command "._xref" "_bind" xname)
(command "._explode" (vlax-vla-object->ename AcDbEntity))
(command "._layer" "_thaw" "*" "_on" "*" "_unlock" "*" "")
(while (setq ename (entnext ename))
(ssadd ename ss)
)
(command "._wblock" (strcat folder "\\" xname) "" "0,0,0" "_si" ss)
(command "._undo" "_end")
(command "._u")
(setq lst (cons (strcase xname) lst))
)
(if (and
AcDbBlkTblRec
(eq (type AcDbBlkTblRec) VLA-Object)
)
(progn
(vlax-release-object AcDbBlkTblRec)
(setq AcDbBlkTblRec nil)
)
)
)
(vlax-release-object AcDbEntity)
)
(if (eq *isAcetUtil* :vlax-true)
(acet-ui-progress-done)
)
)
)
(setvar "expert" 0)
(setvar "cmdecho" 1)
(vlax-release-object blocks)
(vla-endundomark adoc)
(vlax-release-object adoc)
(princ "\nDone.")
(princ)
)