-KarL- Posted July 3, 2008 Posted July 3, 2008 I have created a batch program in VBA that opens drawings from a list and does an bunch of stuff to the drawing to get it ready to be issued. The last thing I want it to do is print an 11X17 copy of the drawing for our binders but I can not figure out how to do this in VBA. Any help would be greatly appreciated! Quote
ML0940 Posted July 7, 2008 Posted July 7, 2008 Karl Have you looked into Plot Configurations in VBA? I don't really have a good example but if you go to VBA Help and type that in, there will likely be an example that will get you going ML Quote
ML0940 Posted July 7, 2008 Posted July 7, 2008 OK, I just checked the help in VBA You will likely need to add a plotconfig or possibly just apply this method to an existing plotconfig This code is from The VBA Help Screen Sub Example_GetPaperSize() 'This example gets the width and height of the default paper size for 'your system. Dim PaperWidth As Double, PaperHeight As Double ThisDrawing.ActiveLayout.GetPaperSize PaperWidth, PaperHeight MsgBox "The default paper size is " & vbCrLf & _ "Width: " & PaperWidth & vbCrLf & _ "Height: " & PaperHeight End Sub ML Quote
-KarL- Posted July 7, 2008 Author Posted July 7, 2008 The help menu I have does not list AutoCAD commands, only basic VBA commands. I am looking for a way to create a new plot configuration and then print the drawing using that configuration rather than one already in the drawing but I haven't been able to figure that part out. Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 this should get you started. Are you wanting to hard code your paper size or pass it as an argument? Public Sub SetupAndPlot(ByRef Plotter As String, CTB As String, SIZE As String, PSCALE As String, ROT As String) Dim Layout As AcadLayout On Error GoTo Err_Control Set Layout = ThisDrawing.ActiveLayout Layout.RefreshPlotDeviceInfo Layout.ConfigName = Plotter ' CALL PLOTTER Layout.PlotType = acExtents Layout.PlotRotation = ROT ' CALL ROTATION Layout.StyleSheet = CTB ' CALL CTB FILE Layout.PlotWithPlotStyles = True Layout.PlotViewportBorders = False Layout.PlotViewportsFirst = True Layout.CanonicalMediaName = SIZE ' CALL SIZE Layout.PaperUnits = acInches Layout.StandardScale = PSCALE 'CALL PSCALE Layout.ShowPlotStyles = False ThisDrawing.Plot.NumberOfCopies = 1 Layout.CenterPlot = True If SIZE = "ARCH_expand_C_(24.00_x_18.00_Inches)" Then Layout.ScaleLineweights = True End If ThisDrawing.Regen acAllViewports ZoomExtents Set Layout = Nothing ThisDrawing.Save Exit_Here: Exit Sub Err_Control: Select Case Err.Number Case "-2145320861" MsgBox "Unable to Save Drawing- " & Err.Description Case "-2145386493" MsgBox "Drawing is setup for Named Plot Styles." & (Chr(13)) & (Chr(13)) & "Run CONVERTPSTYLES command", vbCritical, "Change Plot Style" Case Else MsgBox "Unknown Error " & Err.Number End Select End Sub Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 I am passing paper size, ctb, rotation, pc3 etc to this function which sets up and plots. this is the function that pass the info Public Sub Vendor1117() Call SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees) ThisDrawing.Plot.PlotToDevice ThisDrawing.Close (True) End Sub Quote
-KarL- Posted July 7, 2008 Author Posted July 7, 2008 CmdrDuh That looks about like what I need, just a few questions though: 1. Does it need a .pc3 file or can it be a network printer name? 2. Will it print all layouts in the drawing or only the active layout? Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 It can be the network printer name, and as written, only the active layout. However, it can be modified to print all layouts, BUT, you have to know that all the layouts are good. What I mean by that is the default template (at least on my machine) has 2 layout tabs when I start a new drawing. I usually don't use the second layout, and I delete it. HOWEVER, if you were to print all layouts, you might get a blank page sent to the printer Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 If you look at this picture, you can see I highlighted a network printer. I turned on the Locals window to see the current configuration as I step through the code. Can I attach a PNG file? Quote
ML0940 Posted July 7, 2008 Posted July 7, 2008 Hey CmdrDuh, Good to see you again. Karl, in The VBA Editor help, there is a button for Object browser; after you click that, there will be a text box. In there, type plotconfig, that is you will see the code examples and methods. I am not saying that every thing you will need is there but it would def. get you started in the right direction; not only for this but many other things as well. Cool, I think I will be able to use this later on as well. Cmd, if you were going to use the function, in what part of the first sub would you call it from? Cmd, didn't you have code for setting the default printer? Could that also be used with this? To expound on Karl's question; Karl CMD is using the active layout in his code, do you have a specific layout name? If so, this code could be set to that layout, specifically. I think that may be what you are looking for? ML Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 it actually gets called from the second shorter piece of code I have code to set the default printer, but its for windows not acad. As for calling the layout name, you could test for any layout NOT "layout*" and print that, assuming you name your layouts Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 I have a LISP routine I use to call printing from keyboard, or macro from button. Quote
-KarL- Posted July 7, 2008 Author Posted July 7, 2008 It can be the network printer name, and as written, only the active layout. However, it can be modified to print all layouts, BUT, you have to know that all the layouts are good. What I mean by that is the default template (at least on my machine) has 2 layout tabs when I start a new drawing. I usually don't use the second layout, and I delete it. HOWEVER, if you were to print all layouts, you might get a blank page sent to the printer Our templates are setup with only one layout tab so if there are more layout tabs in the drawings they will also need to be printed. Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 OK, so we could change it to be for all layouts NOT named Model, print Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 Do you think you can tweak it from here or do you need help? Quote
ML0940 Posted July 7, 2008 Posted July 7, 2008 CMD Please correct me if I am wrong; that is interesting. It looks like you are calling the first sub up from the second sub. So, would you actually run the Public Sub Vendor1117 Sub first then? I suppose I can do a test drawing and try it, I was just curious after looking at it Thanks ML Quote
CmdrDuh Posted July 7, 2008 Posted July 7, 2008 yes, the CALL statement calls the second sub and passes the arguments to the second sub. That way I have 1 routine to print any number of ways. I have like 12 of the short versions, which all call the main sub and pass the settings I want. Quote
-KarL- Posted July 7, 2008 Author Posted July 7, 2008 I give the code a try a see if I can get it to work, otherwise I will be back. Thanks a lot for all your help! Quote
ML0940 Posted July 7, 2008 Posted July 7, 2008 That is a cool approach CMD with the function part OK, so we could change it to be for all layouts NOT named Model, print Yes, that is what I would do as well. If the layouts are named, then one gets deleted, "I think" a new one called Layout1 will be recreated. So, filtering out the name Layout may not be the best way to approach it. Filtering out Model and looping through all layouts (in my opinion) would probably be the best attack, if you truly want to print all layouts. If the layouts are named, I would set a reference to the specific layout(s) name. ML Quote
-KarL- Posted July 7, 2008 Author Posted July 7, 2008 I got it to work, here is how I got around the multiple layouts For x = 0 To Drawing.Layouts.Count - 1 Set Layout = Drawing.Layouts(x) Layout.RefreshPlotDeviceInfo Layout.ConfigName = Plotter ' CALL PLOTTER Layout.PlotType = acExtents Layout.PlotRotation = ROT ' CALL ROTATION Layout.StyleSheet = CTB ' CALL CTB FILE Layout.PlotWithPlotStyles = True Layout.PlotViewportBorders = False Layout.PlotViewportsFirst = True Layout.CanonicalMediaName = SIZE ' CALL SIZE Layout.PaperUnits = acInches Layout.StandardScale = PSCALE ' CALL PSCALE Layout.ShowPlotStyles = False Layout.ScaleLineweights = True Layout.CenterPlot = True Drawing.ActiveLayout = Layout Drawing.Plot.NumberOfCopies = 1 Drawing.Regen acAllViewports Drawing.Plot.PlotToDevice Next x Set Layout = Nothing Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.