I try to save a dwg document but only with selected object , I know I can use a wblock command but i need only use ssget and saveas command.
(setq selection (ssget))
Any know any options ?
If you want to use the SAVEAS command, you have to delete all non-selected objects from the drawing before calling SAVEAS. You have to keep in mind AutoLISP runs in document context so the LISP routine will finish as soon as the SAVEAS command destroys the current document.
(defun c:foo (/ s1 s2 i)
(if (setq s1 (ssget))
(progn
(setq s2 (ssget "_X"))
(repeat (setq i (sslength s1))
(ssdel (ssname s1 (setq i (1- i))) s2)
)
(repeat (setq i (sslength s2))
(entdel (ssname s2 (setq i (1- i))))
)
(command "_.saveas"
""
(strcat
"C:\\Temp\\DrawingFromSelection_"
(menucmd "M=$(edtime,$(getvar,date),YYYYMMDD-HHMMSS)")
)
)
)
)
(princ)
)