;Code adapted from LeeMac's code at: http://www.theswamp.org/index.php?topic=43352.msg507568#msg507568
(defun c:EraseOutsideTitleBlock (/ SS BOX SS_ALL SS_KEEP LLP URP ENT idx flg tab)
;; Block Name - Lee Mac
;; Returns the true (effective) name of a supplied block reference
(defun LM:blockname ( obj )
(if (vlax-property-available-p obj 'effectivename)
(defun LM:blockname ( obj ) (vla-get-effectivename obj))
(defun LM:blockname ( obj ) (vla-get-name obj))
)
(LM:blockname obj)
)
;; Selection Set Bounding Box - Lee Mac
;; Returns a list of the lower-left and upper-right WCS coordinates of a
;; rectangular frame bounding all objects in a supplied selection set.
;; sel - [sel] Selection set for which to return bounding box
(defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp )
(repeat (setq idx (sslength sel))
(setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
(if (and (vlax-method-applicable-p obj 'getboundingbox)
(not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
)
(setq ls1 (mapcar 'min (vlax-safearray->list llp) (cond (ls1) ((vlax-safearray->list llp))))
ls2 (mapcar 'max (vlax-safearray->list urp) (cond (ls2) ((vlax-safearray->list urp))))
)
)
)
(if (and ls1 ls2) (list ls1 ls2))
)
(setq tab (getvar "ctab"))
(if (setq SS (ssget "_X" (list '(0 . "INSERT") '(8 . "$TB") (cons 410 tab))))
(progn
(setq BOX (LM:ssboundingbox SS)
LLP (car BOX)
URP (cadr BOX)
SS_ALL (ssget "_X" (list (cons 410 tab)))
SS_KEEP (ssget "_W" (mapcar '- llp '(1e-2 1e-2)) (mapcar '+ urp '(1e-2 1e-2)) (list (cons 410 tab)))
)
(repeat (setq idx (sslength SS_all))
(if
(not
(or (ssmemb (setq ent (ssname SS_all (setq idx (1- idx)))) SS_KEEP)
(or (and (= "INSERT" (cdr (assoc 0 (entget ent))))
(wcmatch (strcase (LM:blockname (vlax-ename->vla-object ent))) "PLOT STAMP*")
)
(= "$$tbinfo" (cdr (assoc 8 (entget ent))))
(= "$tbinfo" (cdr (assoc 8 (entget ent))))
)
)
)
(progn
(entdel ent)
(or flg (setq flg (princ "\nObject(s) found outside the title block and will now be deleted.")))
)
)
)
)
)
)
The quick and dirty if you have a fixed size title block ours was always at 0,0 and 1:1 size then do a move window, way past the junk use extmax then erase the window of previous extmin extmax move your title block back all done.A fixed size title block would be simple, unfortunately we have to use client title blocks that can range anywhere from 8.5x11 on up to 36x48, sometimes larger.
Again if you have a title block scaled then you can still work out a move window of just the title block as you know its true size.
Can still be done as you know the name and the size of the title block, so can still get a window size and location. If they are blocks can also use bounding box to find the title window. You may just have to provide title block name/s.That is the issue, programmatically, I don't have anyway to know what size the title block is that I can think of that doesn't involve ActiveX. If I could read page setups without ActiveX, that might be a way around that though.
Maybe you can use this: (dictsearch (namedobjdict) "ACAD_LAYOUT")Can still be done as you know the name and the size of the title block, so can still get a window size and location. If they are blocks can also use bounding box to find the title window. You may just have to provide title block name/s.That is the issue, programmatically, I don't have anyway to know what size the title block is that I can think of that doesn't involve ActiveX. If I could read page setups without ActiveX, that might be a way around that though.
;Code adapted from LeeMac's code at: http://www.theswamp.org/index.php?topic=43352.msg507568#msg507568
(defun EraseOutsideTitleBlock (/ SS BOX SS_ALL SS_KEEP LLP URP ENT idx flg tab)
(defun DTR (a) ;degrees to radians function
(* PI (/ a 180.0))
);defun
(defun CW:BoundingBox (ss / psize i EntType LLP URP PT2)
; get paper size on current tab - Adapted from JTB World - https://jtbworld.com/autocad-pagesetup-lsp
(defun papersize (/ psn scale)
(setq
psn (member '(100 . "AcDbPlotSettings")
(dictsearch
(cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
(getvar "ctab")
)
)
)
(if (= (caadr psn) 1) ; Page Setup Name exist
(progn (setq scale (if (= 0 (cdr (assoc 72 psn)))
25.4
1.0
)
)
(list (/ (cdr (assoc 45 psn)) scale) (/ (cdr (assoc 44 psn)) scale))
)
)
)
(setq psize (papersize))
(if psize
(progn
(repeat (setq i (sslength ss))
(setq ent (entget (ssname ss (setq i (1- i))))
EntType (cdr (assoc 0 ent))
LLP (cdr (assoc 10 ent))
PT2 (polar LLP (DTR 90.0) (cadr psize))
URP (polar PT2 (DTR 0.0) (car psize))
)
)
)
)
(if (and llp urp)
(list LLP URP)
)
)
(setq tab (getvar "ctab"))
(if (setq SS (ssget "_X" (list '(0 . "INSERT") '(8 . "$TB") (cons 410 tab))))
(progn
(setq BOX (CW:BoundingBox SS)
LLP (car BOX)
URP (cadr BOX)
SS_ALL (ssget "_X" (list (cons 410 tab)))
SS_KEEP (ssget "_W" (mapcar '- llp '(1e-2 1e-2)) (mapcar '+ urp '(1e-2 1e-2)) (list (cons 410 tab)))
)
(if (and (/= SS_ALL nil) (/= SS_KEEP nil))
(progn
(command "._-layer" "_unlock" "*" "")
(repeat (setq idx (sslength SS_all))
(if
(not
(or (ssmemb (setq ent (ssname SS_all (setq idx (1- idx)))) SS_KEEP)
(or
(= "$$tbinfo" (cdr (assoc 8 (entget ent))))
(= "$tbinfo" (cdr (assoc 8 (entget ent))))
)
)
)
(progn
(entdel ent)
(or flg (setq flg (princ "\nObject(s) found outside the title block and will now be deleted.")))
)
)
)
)
)
)
)
(princ)
)
I still think it can be done easier again I ask do you have a title block that encloses the area you want to keep ? The scale etc does not matter as the bounding box will give size. then just move that window out of harms way why you erase the junk.You can't get a bounding box through the AcCoreConsole.exe, as it requires ActiveX to do so and there are actually a few reasons for the erasing of items outside the title block:
If you dont have a title block draw a rectang on a non plot layer, its really about some form of dwg standards so clean up can occur.
(COMMAND "-PLOT" "Y" "" "dwg to Pdf"
"Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE" "N" "W" "-6,-6" "807,560" "1=2" "C"
"y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y"
)
I still think this is doable no VL.Ok, but how would I get the boundary of the title block without VL? Keep in mind, the title block can be any size from 8.5x11 to I believe our largest is 48x52 and all are named identically and there isn't always a box around them and going back and modifying them isn't an option.
(http://)
I understand the OCD of not wanting to have stuff outside of the titleblock .. I have it too. :-D If you plot to VIEW you don't have to worry about the stuff outside though. I've never seen files that have been 'corrupted' from having stuff outside of plotting extents?I still think this is doable no VL.Ok, but how would I get the boundary of the title block without VL? Keep in mind, the title block can be any size from 8.5x11 to I believe our largest is 48x52 and all are named identically and there isn't always a box around them and going back and modifying them isn't an option.
(http://)
I also have a ton of stuff in paperspace that has to stay, so I can't just erase everything outside the moved title block.
I understand the OCD of not wanting to have stuff outside of the titleblock .. I have it too. :-D If you plot to VIEW you don't have to worry about the stuff outside though. I've never seen files that have been 'corrupted' from having stuff outside of plotting extents?I still think this is doable no VL.Ok, but how would I get the boundary of the title block without VL? Keep in mind, the title block can be any size from 8.5x11 to I believe our largest is 48x52 and all are named identically and there isn't always a box around them and going back and modifying them isn't an option.
(http://)
I also have a ton of stuff in paperspace that has to stay, so I can't just erase everything outside the moved title block.
Sounds like you have your hands full! Have you thought about processing these files with ODBX ?I understand the OCD of not wanting to have stuff outside of the titleblock .. I have it too. :-D If you plot to VIEW you don't have to worry about the stuff outside though. I've never seen files that have been 'corrupted' from having stuff outside of plotting extents?I still think this is doable no VL.Ok, but how would I get the boundary of the title block without VL? Keep in mind, the title block can be any size from 8.5x11 to I believe our largest is 48x52 and all are named identically and there isn't always a box around them and going back and modifying them isn't an option.
(http://)
I also have a ton of stuff in paperspace that has to stay, so I can't just erase everything outside the moved title block.
Unfortunately, that assumes that view is always setup correctly, which isn't always the case. If it were just me working on drawings, it wouldn't be a big deal, I could ensure that everything is setup correctly, but I am a single CAD manger trying to support and manage 73 AutoCAD users at present, across two countries. As a result, I pretty much need to do everything I can to idiot proof things.
And unfortunately, upper management often makes this even worse when they insist on hiring people that don't know AutoCAD at all (because they are good with the engineering) and expects that we can train them overnight in how to use AutoCAD, I keep trying to tell them it doesn't work that way.
So again, I am left with idiot proofing these things and even the page layouts aren't always setup correctly for plotting, so I can't just use layout, extents really is the ideal choice after a lot of extensive testing.
As far as corruption, we have had some drawings be corrupted due to objects (generally AEC objects, which is another pain point) outside the plotting extents and if you can get the file opened and move them back within the plotting extents, the file is fine.
Company standards comes to mind sounds like that is your first step.Hey, we are a far cry better than it used to be, I will take the baby steps, at least I have number bubbles in reference and general notes lining up and sheet indexes reflecting the correct deltas, etc.
I actually already do some processing with OBX, not sure how I would do this using OBX though, but that would be awesome.Sounds like you have your hands full! Have you thought about processing these files with ODBX ?I understand the OCD of not wanting to have stuff outside of the titleblock .. I have it too. :-D If you plot to VIEW you don't have to worry about the stuff outside though. I've never seen files that have been 'corrupted' from having stuff outside of plotting extents?I still think this is doable no VL.Ok, but how would I get the boundary of the title block without VL? Keep in mind, the title block can be any size from 8.5x11 to I believe our largest is 48x52 and all are named identically and there isn't always a box around them and going back and modifying them isn't an option.
(http://)
I also have a ton of stuff in paperspace that has to stay, so I can't just erase everything outside the moved title block.
Unfortunately, that assumes that view is always setup correctly, which isn't always the case. If it were just me working on drawings, it wouldn't be a big deal, I could ensure that everything is setup correctly, but I am a single CAD manger trying to support and manage 73 AutoCAD users at present, across two countries. As a result, I pretty much need to do everything I can to idiot proof things.
And unfortunately, upper management often makes this even worse when they insist on hiring people that don't know AutoCAD at all (because they are good with the engineering) and expects that we can train them overnight in how to use AutoCAD, I keep trying to tell them it doesn't work that way.
So again, I am left with idiot proofing these things and even the page layouts aren't always setup correctly for plotting, so I can't just use layout, extents really is the ideal choice after a lot of extensive testing.
As far as corruption, we have had some drawings be corrupted due to objects (generally AEC objects, which is another pain point) outside the plotting extents and if you can get the file opened and move them back within the plotting extents, the file is fine.
There is some good posts around about creating company standards what to look for do a google, sounds like the 1st step, new employee here is our rules you must use. Maybe forums/autodesk.Again, we have CAD Standards, that isn't the issue, unfortunately, not everyone follows the CAD standards all of the time, even though they know the rules. I try my best to enforce them, but I can only do so much. Simply put, this is NOT about our CAD Standards, but how to deal with people drawing outside of title blocks. We also run into this issue with files sent to us from other companies that we have to use as xrefs and that also causes a lot of issues, so having a handy way to clean it up rapidly is worthwhile.
I previously had some interesting input from a Cad manager multi millions $$ project 200 + building sites revamp of corporate appearance the Cad manager removed the standard menu and replaced with a custom one that had draw objects, not lines, so always correct, that was a outsourced project to a cheaper country where he went to live for 6 months to ensure company standards.
(setq SS (ssget "_X" (list '(0 . "INSERT") '(8 . "$TB") (cons 410 tab))))