I use vla-PlotToFile to plot dwg to pdf with acWindow plottype, but pdf is offse

I use vla-PlotToFile to plot dwg to pdf with acWindow plottype, but pdf is offse

zhanghouli
Explorer Explorer
3,813 Views
9 Replies
Message 1 of 10

I use vla-PlotToFile to plot dwg to pdf with acWindow plottype, but pdf is offse

zhanghouli
Explorer
Explorer

I use vla-PlotToFile to plot dwg to pdf with acWindow plottype, but pdf is offset. please help, thanks

(defun c:myplot ( / )
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  ;(setvar "LAYOUTREGENCTL" 1)

  (setq lyout (vla-get-activelayout adoc))
  (setq styleSheet "monochrome.ctb")
  (setq cfgName "AutoCAD PDF (High Quality Print).pc3")
  (vla-RefreshPlotDeviceInfo lyout)
  (vla-put-ConfigName lyout CfgName)
  (vla-put-PaperUnits lyout acMillimeters)
  (vla-put-plotrotation lyout ac0degrees)
  (vla-put-PlotType lyout acWindow)
  (vla-put-CanonicalMediaName lyout "ISO_full_bleed_A3_(420.00_x_297.00_mm)")
  (vla-put-PlotWithLineweights lyout :vlax-false)
  (vla-put-PlotWithPlotStyles lyout :vlax-true)
  (vla-put-StyleSheet lyout styleSheet)
  (vla-put-CenterPlot lyout :vlax-true)
  (vla-put-plotrotation lyout ac0degrees)
  
  (vla-put-activelayout adoc lyout)
  

  
  (setq ss (ssget "X" '((0 . "INSERT") (2 . "bztk") (67 . 0))))

  (setq i -1)
  (repeat (sslength ss)
    (setq i (1+ i))
    (setq tk_ent (ssname ss i))
    (vla-GetBoundingBox (vlax-ename->vla-object tk_ent) 'minpoint 'maxpoint)
    (setq pointTemp1 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-put-element pointTemp1 0 (vlax-safearray-get-element  minpoint 0))
    (vlax-safearray-put-element pointTemp1 1 (vlax-safearray-get-element  minpoint 1))

    (setq pointTemp2 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-put-element pointTemp2 0 (vlax-safearray-get-element maxpoint 0))
    (vlax-safearray-put-element pointTemp2 1 (vlax-safearray-get-element maxpoint 1))
    (vla-SetWindowToPlot lyout pointTemp1 pointTemp2)
    (vla-put-activelayout adoc lyout)
    (vla-PlotToFile (vla-get-Plot adoc) (strcat (getvar 'dwgprefix) "draw" (itoa i)))

  )

  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 231 )
  (setvar "CMDECHO" 1)
)
0 Likes
Accepted solutions (2)
3,814 Views
9 Replies
Replies (9)
Message 2 of 10

Ajilal.Vijayan
Advisor
Advisor

The code needs a small change by moving vla-plottype after SetWindowToPlot  as mentioned in here

"The ViewToPlot property or SetWindowToPlot method must be called before you can set the PlotType to acView or acWindow."

 

Also the drawing you send has some problems, which does not set the new plot window coordinates.

So copy the block to a new drawing and run the code again.

 

(defun c:myplot ( / )
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  ;(setvar "LAYOUTREGENCTL" 1)

  (setq lyout (vla-get-activelayout adoc))
  (setq styleSheet "monochrome.ctb")
  (setq cfgName "AutoCAD PDF (High Quality Print).pc3")
  (vla-RefreshPlotDeviceInfo lyout)
  (vla-put-ConfigName lyout CfgName)
  (vla-put-PaperUnits lyout acMillimeters)
  (vla-put-plotrotation lyout ac0degrees)
  ;;(vla-put-PlotType lyout acWindow)
  (vla-put-CanonicalMediaName lyout "ISO_full_bleed_A3_(420.00_x_297.00_mm)")
  (vla-put-PlotWithLineweights lyout :vlax-false)
  (vla-put-PlotWithPlotStyles lyout :vlax-true)
  (vla-put-StyleSheet lyout styleSheet)
  (vla-put-CenterPlot lyout :vlax-true)
  (vla-put-plotrotation lyout ac0degrees)
  
  (vla-put-activelayout adoc lyout)
  

  
  (setq ss (ssget "X" '((0 . "INSERT") (2 . "bztk") (67 . 0))))

  (setq i -1)
  (repeat (sslength ss)
    (setq i (1+ i))
    (setq tk_ent (ssname ss i))
    (vla-GetBoundingBox (vlax-ename->vla-object tk_ent) 'minpoint 'maxpoint)
    (setq pointTemp1 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-put-element pointTemp1 0 (vlax-safearray-get-element  minpoint 0))
    (vlax-safearray-put-element pointTemp1 1 (vlax-safearray-get-element  minpoint 1))

    (setq pointTemp2 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-put-element pointTemp2 0 (vlax-safearray-get-element maxpoint 0))
    (vlax-safearray-put-element pointTemp2 1 (vlax-safearray-get-element maxpoint 1))
    (vla-SetWindowToPlot lyout pointTemp1 pointTemp2)
(vla-put-PlotType lyout acWindow) (vla-put-activelayout adoc lyout) (vla-PlotToFile (vla-get-Plot adoc) (strcat (getvar 'dwgprefix) "draw" (itoa i))) ) (setvar "BLIPMODE" 0) (setvar "OSMODE" 231 ) (setvar "CMDECHO" 1) )

 

Message 3 of 10

zhanghouli
Explorer
Explorer

thanks for your help. no error reporting when I set plottype to acwindow after using your code.

 

copying blocks to new drawing file is a solution for offset

but i have  a lot of drawing files with this block reference, some is ok, others have the same problems.

Is there some solutions which can find and repair the problems by coding.

0 Likes
Message 4 of 10

maratovich
Advisor
Advisor

@zhanghouli wrote:

Is there some solutions which can find and repair the problems by coding.


Maybe this will help you: Revers - Automatic batch printing 

 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 5 of 10

Ajilal.Vijayan
Advisor
Advisor
"Is there some solutions which can find and repair the problems by coding."

I am not sure exactly what causing the problem.

Another solution is  to use the command version of plot as shown below

 

;(vla-SetWindowToPlot lyout pointTemp1 pointTemp2)
;(vla-put-PlotType lyout acWindow)
;(vla-put-activelayout adoc lyout)
;(vla-PlotToFile (vla-get-Plot adoc) (strcat (getvar 'dwgprefix) "draw" (itoa i)))
;;Replace the above lines with the below lines and try
(setq p1 (vlax-safearray->list pointTemp1))
(setq p2 (vlax-safearray->list pointTemp2))
(command "-plot" "y" "" "" "" "" "" "" "W" p1 p2 "" "" "" "" "" "" (strcat (getvar 'dwgprefix) "draw" (itoa i)) "Y" "")

 

 

0 Likes
Message 6 of 10

phanaem
Collaborator
Collaborator
Accepted solution

Get "Target" point of the active Viewport and subtract it from WindowToPlot points. I see you are plotting from ModelSpace, so there is always an active ViewPort.

You might want to look into Layout's PlotOrigin as well. Usually it is 0.0,0.0 but it doesn't hurt to account this setting too.

(defun c:myplot ( / )
  (vl-load-com)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (setvar "CMDECHO" 0)
  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 0)
  ;(setvar "LAYOUTREGENCTL" 1)

  (setq lyout (vla-get-activelayout adoc))

  (mapcar 'set '(x y) (vlax-get (vla-get-activeviewport adoc) 'Target))

 
  (setq styleSheet "monochrome.ctb")
  (setq cfgName "AutoCAD PDF (High Quality Print).pc3")
  (vla-RefreshPlotDeviceInfo lyout)
  (vla-put-ConfigName lyout CfgName)
  (vla-put-PaperUnits lyout acMillimeters)
  (vla-put-plotrotation lyout ac0degrees)
  
  (vlax-invoke  lyout 'SetWindowToPlot '(0.0 0.0) '(420.0 297.0));initializing window to plot
  (vla-put-PlotType lyout acWindow)

  (vla-put-CanonicalMediaName lyout "ISO_full_bleed_A3_(420.00_x_297.00_mm)")
  (vla-put-PlotWithLineweights lyout :vlax-false)
  (vla-put-PlotWithPlotStyles lyout :vlax-true)
  (vla-put-StyleSheet lyout styleSheet)
  (vla-put-CenterPlot lyout :vlax-true)
  (vla-put-plotrotation lyout ac0degrees)
  
  (vla-put-activelayout adoc lyout)
  

  
  (setq ss (ssget "X" '((0 . "INSERT") (2 . "bztk") (67 . 0))))

  (setq i -1)
  (repeat (sslength ss)
    (setq i (1+ i))
    (setq tk_ent (ssname ss i))
    (vla-GetBoundingBox (vlax-ename->vla-object tk_ent) 'minpoint 'maxpoint)
    (setq pointTemp1 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-put-element pointTemp1 0 (- (vlax-safearray-get-element  minpoint 0) x))
    (vlax-safearray-put-element pointTemp1 1 (- (vlax-safearray-get-element  minpoint 1) y))

    (setq pointTemp2 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
    (vlax-safearray-put-element pointTemp2 0 (- (vlax-safearray-get-element maxpoint 0) x))
    (vlax-safearray-put-element pointTemp2 1 (- (vlax-safearray-get-element maxpoint 1) y))
    (vla-SetWindowToPlot lyout pointTemp1 pointTemp2)
    (vla-put-activelayout adoc lyout)
    (vla-PlotToFile (vla-get-Plot adoc) (strcat (getvar 'dwgprefix) "draw" (itoa i)))

  )

  (setvar "BLIPMODE" 0)
  (setvar "OSMODE" 231 )
  (setvar "CMDECHO" 1)
)
Message 7 of 10

zhanghouli
Explorer
Explorer

It works following your code.  thanks you so much 👍👍@phanaem 

I will learn this code

0 Likes
Message 8 of 10

zhanghouli
Explorer
Explorer

Sorry @phanaem 

After studying your code, there is a  doubt:

if I put the following code before "(mapcar 'set '(x y) (vlax-get (vla-get-activeviewport adoc) 'Target))", the old problem will occur again. 

 

(setq vp (vla-get-activeviewport adoc))

(vla-put-target vp (vlax-3d-point 0 0 0))

0 Likes
Message 9 of 10

phanaem
Collaborator
Collaborator
Accepted solution

It seems viewport's target works just by chance, the variable that affect window plotting is in fact (getvar 'target). In your sample it just happens that the 2 are equal.

Please replace (mapcar 'set '(x y) (vlax-get (vla-get-activeviewport adoc) 'Target)) with  (mapcar 'set '(x y) (getvar 'target)) and don't change any viewport setting.

 

 

 

0 Likes
Message 10 of 10

nguyennhattanpt
Contributor
Contributor

I also encountered the same error as you.
I detect plot progress unfinished so plot offset error.
So need to show BatchPlotProgress
(vlax-put-property (vla-get-plot adoc) 'BatchPlotProgress 1)