.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Iterating through all the Plot Devices

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
571 Views, 3 Replies

Iterating through all the Plot Devices

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

3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: Anonymous

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

Drive CAD With Code

EESignature

Message 3 of 4
Anonymous
in reply to: 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

Message 4 of 4
norman.yuan
in reply to: Anonymous

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

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost