TheSwamp

Code Red => VB(A) => Topic started by: Joro-- on May 11, 2008, 12:44:53 PM

Title: plot in .jpg
Post by: Joro-- on May 11, 2008, 12:44:53 PM
Hi,

I'm not sure whether this is possible with VBA, but what I need is to be able to plot to .jpg custom region of a drawing and save the file on c:\. If possible it would be good if I could specify the resolution and plotstyle (for colour or black and white).....

Anyone can help?
Title: Re: plot in .jpg
Post by: David Hall on May 11, 2008, 12:50:00 PM
I have that code, but its at the office.  Tomorrow I'll post it
Title: Re: plot in .jpg
Post by: Joro-- on May 12, 2008, 06:23:42 AM
OK, thanks!
Title: Re: plot in .jpg
Post by: David Hall on May 12, 2008, 02:23:19 PM
Here is the code
Code: [Select]
Public Sub PrintToJPG()
      Dim Layout As AcadLayout
      On Error GoTo Err_Control
      Set Layout = ThisDrawing.ActiveLayout
      Layout.RefreshPlotDeviceInfo
      Layout.ConfigName = "JPG.pc3"  ' You need to call your PC3 you created to print to jpg here
      Layout.PlotType = acExtents
      Layout.PlotRotation = ac0degrees
      Layout.StyleSheet = "CTB.ctb"  ' Add your ctb or stb file here
      Layout.PlotWithPlotStyles = True
      Layout.PlotViewportBorders = False
      Layout.PlotViewportsFirst = True
       Layout.CanonicalMediaName = "UserDefinedRaster (10800.00 x 7200.00Pixels)"  '  Set your paper size here
      Layout.PaperUnits = acPixels
      Layout.SetCustomScale 300, 1  '  Add your scale factor based on the sheet size and resolution here
      Layout.ShowPlotStyles = False
      ThisDrawing.Plot.NumberOfCopies = 1
      Layout.CenterPlot = True
      Layout.ScaleLineweights = False
      ThisDrawing.Regen acAllViewports
      ZoomExtents
      strDrawingName = (Left(ThisDrawing.Name, (Len(ThisDrawing.Name) - 4)))
      Set Layout = Nothing
      ThisDrawing.Plot.PlotToFile  strDrawingName
Exit_Here:
      Exit Sub
Err_Control:
End Sub
Title: Re: plot in .jpg
Post by: Joro-- on May 13, 2008, 09:25:57 AM
Hi CmdrDuh,

I tried the code and it worked :-) Thanks a lot.

But how can I control which part of the layout am I plotting? How can I set the plotted region to be with a given PtLowLeft(2) and PtHighRight(2) so that I can perform several diferent plots at once?
Title: Re: plot in .jpg
Post by: David Hall on May 13, 2008, 10:06:17 AM
you will need to pick the 2 points you want, and then change to acWindow.  I'll see if I have a snippet showing that
Title: Re: plot in .jpg
Post by: David Hall on May 13, 2008, 10:15:45 AM
from the help file
Quote
Sub Example_SetWindowToPlot()
    ' This example allows the user to define an area in the current layout
    ' and displays a plot preview of the defined area.
    '
    ' * Note: You have to exit the
    ' plot preview before the VBA example will stop and control will be returned
   
    Dim point1 As Variant, point2 As Variant
   
    ' Get first point in window
    point1 = ThisDrawing.Utility.GetPoint(, "Click the lower-left of the window to plot.")
    ReDim Preserve point1(0 To 1)   ' Change this to a 2D array by removing the Z position
   
    ' Get second point in window
    point2 = ThisDrawing.Utility.GetPoint(, "Click the upper-right of the window to plot.")
    ReDim Preserve point2(0 To 1)   ' Change this to a 2D array by removing the Z position
   
    ' Send information about window to current layout
    ThisDrawing.ActiveLayout.SetWindowToPlot point1, point2
   
    ' Read back window information
    ThisDrawing.ActiveLayout.GetWindowToPlot point1, point2
   
    MsgBox "Press any key to plot the following window:" & vbCrLf & vbCrLf & _
           "Lower Left: " & point1(0) & ", " & point1(1) & vbCrLf & _
           "Upper Right: " & point2(0) & ", " & point2(1)
   
    ' Be sure to plot a view, not some other plot style
    ThisDrawing.ActiveLayout.PlotType = acWindow
   
    ' Send Plot To Window
    ThisDrawing.Plot.DisplayPlotPreview acFullPreview
End Sub