Hi,
I am trying to iterate through all the Plot Devices (plotDeviceName) available to the user. I am new to vb.Net and I have no idea where to look, any advice or snippet would be greatly appreciated.
Thank you,
-Jay
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Look into Autodesk.AutoCAD.PlotServices.PlotConfigManager class. Some code:
public class MyCommands { [CommandMethod("PlotDevices", CommandFlags.Session)] public static void GetPlotDevices() { Document dwg = Application.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; using (PlotConfigInfoCollection configs = PlotConfigManager.Devices) { foreach (PlotConfigInfo config in configs) { ed.WriteMessage("\nDevice name: {0}", config.DeviceName); } } } }
The code prints out all devices' name that you get in the "Plot" dialog box's ploter/printer dropdown list.
Norman Yuan
Thank you very much Norman, it works like a charm. However, I am still puzzled as to why you used “Using” in you code.
I am trying to understand if there is any benefit to the why you have your code instead of just declaring a variable?
I am new to .net so I am still trying to wrap all of this around my head.
Thank you again Norman,
-Jay
Many classes in the Acad .NET API is derived from DisposableWrapper that implement IDisposable interface, which implies that an instance of this kind of class may need extra cleanup work done to free some resources ASAP. However, we as outside user of the API do nt exactly know what would be happening in the implemented Dispose() method. In many cases when doing Acad .NET API development, it is probably quite OK not bothering call xxxx.Dispose() or wrapping code in a using... {...} block.
In other hand, if you know something that should be explicitly disposed, such as a Transaction you started, an Entity you created but do not want to added into drawing database...then you either call Dispose() on it or use using... to wrap it when it is "newed".
In the case of my code sample, it may not be necessary to wrap thing is using... block. But since my code is clearly focused on getting a list of string values (device names), I do not want the PlotConfigInfoCollection to stay in memory longer than needed, thus the using block. Also, who knows if each PlotConfigInfo object results in extra resources related to plotting devices available to the running computer or not (very likely), release the possible resources ASAP would be better guess, especially in the case when the variable does not go out of scope soon enough.
Norman Yuan