@cbujor,
here is your solution:
two nice functions (read_layout_settings) & (restore_layout_settings)
replace (c:test) with your command
as you can see it's a lot of code but that's the nature of using VisualLISP ActiveX (you want it without creating layout)
some properties are dependent on other so you must be careful about the order they are used.
some properties can not be just null string or "none" like configName so a default value is set to
"DWG to PDF.pc3" if none real value was read.
line code 32 and 36 i use i variable (only for debug) if you encounter errors at restoring, check the i and you'll know on what property no it fail. i believe more exploring will be need from your side.
and if you do not understand what\how i did this code, do not hesitate to ask 😀
enjoy
Moshe
(defun read_layout_settings (AcDbObj props^)
(mapcar
(function
(lambda (prop)
(eval (list (eval (read (strcat "vla-get-" prop))) AcDbObj))
)
)
props^
)
); read_layout_settings
(defun restore_layout_settings (AcDbObj props^ vals^ Numerator Denominator / setMediaSize)
(defun setMediaSize (obj media / err)
(if (not
(vl-catch-all-error-p
(setq err (vl-catch-all-apply 'vla-put-CanonicalMediaName (list obj media)))
)
)
T
(progn
(prompt (strcat "\n* " (vl-catch-all-error-message err) " *"))
(exit)
)
); if
); setMediaSize
(vla-refreshPlotDeviceInfo AcDbObj)
(setq i 0)
(mapcar
(function
(lambda (prop val)
(setq i (1+ i))
(if (vlax-property-available-p AcDbObj (read prop) t)
(cond
((and
(eq prop "configName")
(or (eq val "") (eq val "None"))
)
(eval (list (eval (read (strcat "vla-put-" prop))) AcDbObj "DWG to PDF.pc3")) ; must set some reasonable value
); case
((eq prop "CanonicalMediaName")
(setMediaSize AcDbObj val)
); case
((eq prop "centerPlot")
(if (/= (vla-get-plotType AcDbObj) acLayout)
(eval (list (eval (read (strcat "vla-put-" prop))) AcDbObj val))
)
); case
((eq prop "ViewToPlot")
(if (eq (vla-get-plotType AcDbObj) acView)
(eval (list (eval (read (strcat "vla-put-" prop))) AcDbObj val))
)
); case
((eq prop "UseStandardScale")
(eval (list (eval (read (strcat "vla-put-" prop))) AcDbObj val))
(if (= val :vlax-false)
(vla-setCustomScale AcDblayout Numerator Denominator)
)
); case
( t
(eval (list (eval (read (strcat "vla-put-" prop))) AcDbObj val))
); case
); cond
); if
); lambda
); function
props^ vals^
); mapcar
); restore_layout_settings
(defun c:test (/ properties^ adoc values^ AcDbLayouts AcDbLayout Numerator Denominator)
(setq properties^ '("configName" "CanonicalMediaName" "centerPlot" "modelType" "name"
"paperUnits" "plotHidden" "plotOrigin" "plotRotation" "plotType"
"PlotViewportBorders" "PlotViewportsFirst" "PlotWithLineweights"
"PlotWithPlotStyles" "ScaleLineweights" "ShowPlotStyles" "StandardScale"
"StyleSheet" "TabOrder" "UseStandardScale" "ViewToPlot"))
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startUndoMark adoc)
(if (eq (vla-get-ActiveSpace adoc) acModelSpace)
(vla-put-ActiveSpace adoc acPaperSpace) ; move to layers
)
(vla-put-mSpace adoc :vlax-false) ; switch to pspace
(setq AcDbLayouts (vla-get-layouts adoc))
(setq AcDbLayout (vla-item AcDbLayouts "Layout1"))
(if (vlax-write-enabled-p AcDbLayout)
(progn
(setq values^ (read_layout_settings AcDbLayout properties^))
(vla-getCustomScale AcDbLayout 'Numerator 'Denominator)
; do your job
; ....
; ....
(restore_layout_settings AcDbLayout properties^ values^ Numerator Denominator)
(vla-regen adoc acActiveViewport) ; must regen layout after changes
); progn
(prompt "\nLayout object is not write enabled.")
); if
(vlax-release-object AcDbLayout)
(vlax-release-object AcDbLayouts)
(vla-endUndoMark adoc)
(vlax-release-object adoc)
(princ "\nDone.")
(princ)
)