Hello all
Beginner question about plotting a window with VBA:
I am using an exact copy of this sample subroutine:
When doing this the plot area is the correct size and shape, but it offset quite far to the lower right, meaning the preview is always empty. I don't know what is causing this offset, I thought it might have something to do with coordinate systems or dynamic input, but playing around with these doesn't yield any better results.
The problem appears to be drawing related (as I've tested it succesfully with another drawing), but I don't know what is causing it. Does anyone have an idea where I went wrong with my drawing?
Thanks in advance
Kasper Wuyts
PS:
Judging from the title of the page, this might be a solution, but I only have access to google and Autodesk.com at work, so unfortunately I am unable to watch this.
Solved! Go to Solution.
Solved by RICVBA. Go to Solution.
plotting-windowplot manually you get it right. but there appears an "original" window plot area that's offset some (+190000,-67000) before you force it to the one you select manually. and that offset is quite the one you suffer
maybe this drawing has to do with a wcs-ucs issue. but it's just a guess
A quick search through the web only confirmed that odd and unpredictable behaviour for the SetToWindow method in conjunction with acWindow PlotType property
so it seems to me a workaround is the only way out
since acView PlotType property works properly, you can first zoom to the chosen window and then plot the current display, as follows (I marked code lines added and/or revised by me)
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 AppActivate ThisDrawing.Application.Caption 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) '---------------------------------------- ' added by RICVBA Dim point1w(0 To 2) As Double Dim point2w(0 To 2) As Double point1w(0) = point1(0): point1w(1) = point1(1): point1w(2) = 0 point2w(0) = point2(0): point2w(1) = point2(1): point2w(2) = 0 ZoomWindow point1w, point2w ' make the current display fit the "window to plot" '---------------------------------------- ' Plot the current display ThisDrawing.ActiveLayout.ConfigName = "DWG to PDF.pc3" ThisDrawing.ActiveLayout.PlotType = acDisplay ' <--- revised by RICVBA ThisDrawing.ActiveLayout.CenterPlot = True ' <--- added by RICVBA ThisDrawing.ActiveLayout.StandardScale = acScaleToFit ' <--- added by RICVBA ThisDrawing.Plot.DisplayPlotPreview acFullPreview ZoomPrevious ' restore the previous zoom (optional) ' <--- added by RICVBA End Sub
where I also added some layout plotting configurations to make sure the chosen window entirely fits the paper size and centered into it
hope this can help you
bye
This does seem to work. So I'm accepting it as a solution, although I should modify it for correct scaling. Also, I wonder if the screen hopping performs decently when used to plot 30 drawings from one file simultaneously. I'm going to try some stuff out this weekend.
Thanks!
you could try and set
Application.Visible = False
before starting the plotting labour, and then setting back
Application.Visible = True
after it's done
this should be effective
Hi RICVBA, what piece of code will I need to input to save the file on the plotpreview with same name as file name in pdf format. Do you mind writing it?
"Above answer are not what I want,because (1)I want to us acWindow an (2)I don't want to get point by hand since I already get those by VBA"
If you think as I did,try my answer,it work for me.
=============================================
Edit TARGET system
https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/sfdcarticles/sfdcarticles/Plot-o...
I didn't find a way that using VBA to edit DVIEW (which controls TARGET system),so I use SendCommad
ThisDrawing.SendCommand "DVIEW" & vbCr & "ALL" & vbCr & vbCr & "POINT" & vbCr & "0,0,0" & vbCr & "0,0,1" & vbCr & vbCr