Ok I have updated the code again to include a keyword prompt for users to choose the type of selectionset filter they want to use when are making the selection set to be wblocked out.
Only problem with this I can not seem to run from the command line in the batch process using a call like
(c:AL-WBLOCK_MODELSPACE" "" "A" "") to choose one of the options is there a trick to defining your custom function so it will work like and shipped command in lisp?
(defun c:AL-WBLOCK_MODELSPACE ( / doc idx lst sel ssc vsl corner1 corner2 kword )
;Original code source from here
;https://www.cadtutor.net/forum/topic/56202-make-selection-set-active/
;Original code asks for user to select objects to wblock out
;---------------------------------------------------------------------------------------------------
;Following code has been updated by Justin Ralston (JR) to select just visible objects
;in modelspace by switching to modelspace, zooming to extents and then doing a crossing window selection.
;The objects are then wblocked to a file in the same directory in a new folder called "wBlockedofModelspace"
;-----------------------------------------------------------------------------------------------------
;When using BatchinEditor type the following to have command run and switched to right filter
;(c:AL-WBLOCK_MODELSPACE) A
;((c:AL-WBLOCK_MODELSPACE) "A")x
;((c:-AL-WBLOCK_MODELSPACE) "A")x
;(c:AL-WBLOCK_MODELSPACE "A" "")x
(c:AL-WBLOCK_MODELSPACE" "" "A" "")x
;-----------------------------------Additional Code added by JR-----------------------------------
;select all objects in modelspace of the drawing
;Make sure the drawing is in modelspace
(setvar 'ctab "MODEL")
;Zoom to extents of modelspace to refresh the modelspace extents
(command "_.zoom" "_extents")
;Get the extents of modelspace
(Setq corner1 (getvar 'extmin)) ;Get the lower corner
(Setq corner2 (getvar 'extmax)) ;Get the upper corner
;Restore the drawing Zoom to previous state
(command "_.zoom" "_previous")
;---------------------------------Added by JR [if statement for user to choose filter]--------------------------------
(initget "AllinModel VisibleinModel NonC3DObjectsOnly C3DObjectsOnly")
(setq Kword (getkword "\nSelect Object Types to wblock [AllinModel/VisibleinModel/NonC3DObjectsOnly/C3DObjectsOnly] <AllinModel>: "))
(cond
((or (= kword nil)(= kword "AllinModel"))(Setq SelectTheseObjects (ssget "X" (list (cons 410 (getvar 'ctab))))) (prompt "\n You Selected AllinModel this selects everything in modelspace even if hidden and frozen plus C3d pipenetworks and site even if empty and does a wblock export"))
((= kword "VisibleinModel") (Setq SelectTheseObjects (ssget "_C" corner1 corner2 )) (prompt "\n You selected VisibleinModel this does a crossing window selection of only visible objects in modelspace and does a wblock export"))
((= kword "NonC3DObjectsOnly")(Setq SelectTheseObjects (ssget "_C" corner1 corner2 '((0 . "~AECC*")))) (prompt "\n You selected NonC3DObjectsOnly this does a crossing window selection of only visible objects in modelspace excluding civil3d objects and does a wblock export"))
((= kword "C3DObjectsOnly")(Setq SelectTheseObjects (ssget "_C" corner1 corner2 '((0 . "AECC*")))) (prompt "\n You selected C3DObjectsOnly this does a crossing window selection of all visible civil3d objects in modelspace only and does a wblock export"))
)
;Different ssget functions
;see http://www.lee-mac.com/ssget.html
;(ssget "_C" corner1 corner2 ) ; crossing window selection all objects
;(ssget "X" (list (cons 410 (getvar 'ctab)))) ;selects everything in modelspace even if hidden and frozen plus C3d pipenetworks and site even if empty
;Exclude all Civil3d Objects
;See https://forums.augi.com/showthread.php?172844-Lisp-code-to-wblock-all-objects-except-Civil-3D-object...
;(ssget "_C" corner1 corner2 '((0 . "~AECC*"))) ;crossing window selection all objects excluding civil3d
;Includes only Civil3d objects
;(ssget "_C" corner1 corner2 '((0 . "AECC*"))) ;crossing window selection all civil3d objects only
;---------------------------------Orginal Code by Lee Mac--------------------------------------------------
(if (setq sel SelectTheseObjects );Changed the ssget function here to select what you want to export
;---------------------------------Orginal Code Unchanged--------------------------------------------------
(progn
(repeat (setq idx (sslength sel))
(setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
ssc (vla-get-selectionsets doc)
vsl (vla-add ssc (uniqueitem ssc "mywb"))
)
(vla-additems vsl
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray vlax-vbobject (cons 0 (1- (length lst))))
lst
)
)
)
;-----------------------------------Added by JR-----------------------------------
;Add Create the name of the new file from the exisitng
;Get the existing file path
(Setq ExFilePath (getvar "dwgprefix"))
;Get the existing file name
(Setq ExFileName (getvar "dwgname"))
;Create a new folder for the wblock to be written out to.
(Setq NewFolderpath (strcat ExFilePath "wBlockedofModelspace"))
(vl-mkdir NewFolderpath) ; no error is thrown if it exists.
;Create a new file name for the wblock to write out to.
(Setq NewFilePathAndName (strcat NewFolderpath "//" ExFileName))
;(princ NewFilePathAndName)
;export the contents of just model space to a new drawing
;----------------------------------------------------------------------------------
;(vla-WBlock doc NewFilePathAndName vsl)
(vla-wblock doc
NewFilePathAndName
vsl
)
;(vla-wblock doc
; (vl-filename-mktemp
; (vl-filename-base (getvar 'dwgname)) ;Drawing Name strippped of path and extension
; (getvar 'dwgprefix) ;Drive and folderpath of current drawing
; ".dwg"
😉
;vsl
😉
(vla-delete vsl)
(prompt (strcat "\n Your new file has been written out to " NewFilePathAndName))
)
)
(princ)
)
(defun uniqueitem ( col key / int rtn )
(setq int 0)
(while
(not
(vl-catch-all-error-p
(vl-catch-all-apply 'vla-item
(list col (setq rtn (strcat key (itoa (setq int (1+ int))))))
)
)
)
)
rtn
)
(vl-load-com) (princ)
Regards
Justin Ralston
http://c3dxtreme.blogspot.com/