The vla-RefreshPlotDeviceInfo function modifies the layout settings

The vla-RefreshPlotDeviceInfo function modifies the layout settings

cbujor
Participant Participant
1,898 Views
24 Replies
Message 1 of 25

The vla-RefreshPlotDeviceInfo function modifies the layout settings

cbujor
Participant
Participant

For some plots, probably those that have the insertion units in inches or others other than metric, when the units of measurement of the plot settings are in millimeters and the vla-RefreshPlotDeviceInfo function is applied these units are changed to inches and the layout is changed.

Normally, the vla-RefreshPlotDeviceInfo function should not make any changes to the layout for which it is being refreshed.

I solved the problem by copying the active layout into a temporary layout, then I applied this function, after which I deleted the temporary layout. I'm not sure if this works, that is, if the vla-RefreshPlotDeviceInfo function took the information from the temporary layout and these are used in the active layout.

0 Likes
Accepted solutions (1)
1,899 Views
24 Replies
Replies (24)
Message 21 of 25

Moshe-A
Mentor
Mentor

@cbujor ,

 


@cbujor wrote:

Perhaps a simpler description of this problem would be for the vla-RefreshPlotDeviceInfo function to be rewritten so that the layout to which it is applied to remains unchanged.


the goal  of (vla-RefreshPlotDeviceInfo) is to make sure the data is update before you access the layout object.

what is the reason you want to preserve the layout setting, does it change accidentally, without your control?

 

Moshe

 

0 Likes
Message 22 of 25

cbujor
Participant
Participant

Yes, in certain situations (vla-RefreshPlotDeviceInfo) it changes the layout settings from millimeters to inches, I think this is a bug of this function.

 

I have attached a dwg file for you to test this too. Use the following commands in the command line:

(setq layobj (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))))

(vla-RefreshPlotDeviceInfo layobj)

Now the current layout settings have been changed from millimeters to inches.

 

0 Likes
Message 23 of 25

Moshe-A
Mentor
Mentor

@cbujor ,

 

ok, i am taking this as my home work , stay tuned here 😀 

0 Likes
Message 24 of 25

paullimapa
Mentor
Mentor
Accepted solution

do this setting first:

(setvar"measurement"1)

now the following would not change the units from mm to inches:

(vla-RefreshPlotDeviceInfo layobj)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 25 of 25

Moshe-A
Mentor
Mentor

@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)
)

 

 

 

 

 

 

0 Likes