1. if you want just how to input wmf to excel.
my routine makes .wmf image file in .dwg file's directory. just insert like png or jpeg same way.
2. if you want just image with fixed size.
jpgout or pngout make same pixel size with your autocad drawing window. (not coordinates or size in drawing, just window box size you can see)
so, this is Cheating way. I like cheating
When specifying pt1 and pt2, you do not enter pixels. just picking coordinates.
so, width of the output image value is entered
height of the output image is automatically adjusted according to the xy ratio of pt1 and pt2.
Because it is affected by the window size, it worked normally at a width of 1500 or less in an environment of 1920x1080.
and, In my environment
-16px is insufficient in width
-55px is insufficient in height.
it's probably because of the scrollbars and titles of the drawing window.
You can test it in your own environment and change this number.
(defun c:ss (/ ods pt1 pt2 patch nm ss acdoc input_width input_height x_dist_selection y_dist_selection xy_ratio _opendirectory)
(setvar "cmdecho" 0)
(setq ods (getvar "osmode"))
(setvar "osmode" 0)
(setq acdoc (vla-get-activedocument (vlax-get-acad-object))) ;edited line
(setq pt1 (getpoint "\nSelect the first point:")
pt2 (getcorner pt1
"\nselect the second point:"
)
ph (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname")) ".png") ;edited line
)
(setq x_dist_selection (abs (- (car pt1) (car pt2)) )) ;edited line
(setq y_dist_selection (abs (- (cadr pt1) (cadr pt2)) )) ;edited line
(setq xy_ratio (/ y_dist_selection x_dist_selection)) ;edited line
(initget 7) ;edited line
(setq input_width (getint "\nInput image width (under approx.1500 is best):"))
(setq input_height (atoi (rtos (* input_width xy_ratio) 2 0)) )
; if 1:1 scale, delete above 3 lines (initget 7)~(setq input_height ~)
; and add this (setq input_width x_dist_selection) (setq input_height y_dist_selection)
(setq input_width (+ input_width 16)) ; 16 is my environment gap of window size & image size. shoud be edited
(setq input_height (+ input_height 55)) ; 45 is my environment gap of window size & image size. shoud be edited
;(princ "\n xy_ratio - ")
;(princ xy_ratio)
;(princ "\n input_width - ")
;(princ input_width)
;(princ "\n input_height - ")
;(princ input_height)
(if (setq ss (ssget "w" pt1 pt2)) ;'((0 . "lwpolyline,line,ARC"))))
(progn
(command "_Zoom" "OB" ss "")
(vla-put-height acdoc input_height) ;edited line
(vla-put-width acdoc input_width) ;edited line
(command "_pngout" ph "all" "") ;edited line for all entities, replace with (command "_pngout" ph ss "")
)
)
(command "_Zoom" "p")
(vla-put-windowstate acdoc 3) ;edited line
(command "_syswindows" "c") ;edited line
(setvar "osmode" ods)
(princ "\ndone.")
(princ (strcat "\nimage output path:" ph))
(defun _opendirectory (path / sa) ;edited line
(if (and (eq 'str (type path)) ;edited line
(findfile (vl-string-right-trim "\\" path)) ;edited line
(setq sa (vlax-create-object "Shell.Application")) ;edited line
) ;edited line
(progn (vlax-invoke sa 'explore path) (vlax-release-object sa)) ;edited line
) ;edited line
(princ) ;edited line
) ;edited line
(_opendirectory (getvar 'dwgprefix)) ;edited line
(setvar "osmode" ods)
(princ)
)
Because png has better quality than jpeg, I changed it at will