Check code below.
Change the block name and attribute tag to what you need. If no block is found with the specified attribute tag or it is empty, the drawing will not be plotted. If multiple blocks and/or attribute tags with the same name are found, only the first one will be used to determine the plot file name.
Also change the plotting variables to whatever you need.
(defun c:PlotTest (/ PT_Selection PT_Attributes PT_Filename)
(if
(setq PT_Selection (ssget "_X" '((0 . "INSERT")(2 . "BLOCK_NAME")(66 . 1))))
(progn
(setq PT_Attributes (vla-GetAttributes (vlax-ename->vla-object (ssname PT_Selection 0))))
(foreach PT_Object (vlax-safearray->list (vlax-variant-value PT_Attributes))
(if
(and
(not PT_Filename)
(= (vla-get-TagString PT_Object) "ATT_TAG")
)
(setq PT_Filename (vla-get-TextString PT_Object))
)
)
(if
(and
PT_FileName
(/= PT_FileName "")
)
(progn
(mapcar 'setvar '("CMDECHO" "FILEDIA") '(0 0))
(command "_.ZOOM" "E")
(command
"_.PLOT"
"Y" ; detailed plot
"Model" ; layout name
"DWG To PDF.pc3" ; plot device
"ISO A3 (420.00 x 297.00 MM)" ; paper size
"M" ; units
(if ;---
(apply '> (reverse (cdr ;
(reverse (mapcar '- ;
(getvar "EXTMAX") ;
(getvar "EXTMIN") ; paper orientation depending on extents
)) ;
))) ;
"L" ; landscape
"P" ; portrait
) ;---
"N" ; plot upside down
"EXTENTS" ; what to plot
"F" ; scale of plot
"0,0" ; plot offset
"Y" ; plot with plot styles
"monochrome.ctb" ; plot style table
"Y" ; plot with lineweights
"As Displayed" ; shading
PT_FileName ; file name
"N" ; save changes to page setup
"Y" ; proceed
)
(mapcar 'setvar '("CMDECHO" "FILEDIA") '(1 1))
)
)
)
)
(princ)
)