Author Topic: plot in .jpg  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

Joro--

  • Guest
plot in .jpg
« 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?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: plot in .jpg
« Reply #1 on: May 11, 2008, 12:50:00 PM »
I have that code, but its at the office.  Tomorrow I'll post it
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Joro--

  • Guest
Re: plot in .jpg
« Reply #2 on: May 12, 2008, 06:23:42 AM »
OK, thanks!

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: plot in .jpg
« Reply #3 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Joro--

  • Guest
Re: plot in .jpg
« Reply #4 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?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: plot in .jpg
« Reply #5 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: plot in .jpg
« Reply #6 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)