Solved

AutoCAD 2008 c# .net API: SendStringToExecute not being executed until to late.

Posted on 2010-11-15
3
2,878 Views
Last Modified: 2013-12-04
Hello

I'm trying to set the plotstamp up and then convert it to a pdf... unfortunately even tho I'm calling the plotstamp commands from a SendStringToExecute early in the program it's not executing until after the plot to pdf...

Any way to cause the SendStringToExecute to be executed immediately?

Using C# on the .Net 2.0 Framework.

Thanks.

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.PlottingServices;

namespace PlottingApplication
{
    public class PlottingCommands
    {
        [CommandMethod("simplot")]
        static public void SimplePlot()
        {
            Document doc =
              Application.DocumentManager.MdiActiveDocument;

            string cmd = "-PlotStamp On Fields Yes No Yes No No No No /n";
            doc.SendStringToExecute(cmd, true, false, false);

            //Retreive the Drawings File Path
            HostApplicationServices hs =
                HostApplicationServices.Current;
            string path =
              hs.FindFile(
                doc.Name,
                doc.Database,
                FindFileHint.Default
              );

            Editor ed = doc.Editor;
            Database db = doc.Database;
            Transaction tr =
              db.TransactionManager.StartTransaction();
            using (tr)
            {
                // We'll be plotting the current layout
                BlockTableRecord btr =
                  (BlockTableRecord)tr.GetObject(
                    db.CurrentSpaceId,
                    OpenMode.ForRead
                  );
                Layout lo =
                  (Layout)tr.GetObject(
                    btr.LayoutId,
                    OpenMode.ForRead
                  );

                // We need a PlotInfo object
                // linked to the layout
                PlotInfo pi = new PlotInfo();
                pi.Layout = btr.LayoutId;

                // We need a PlotSettings object
                // based on the layout settings
                // which we then customize
                PlotSettings ps =
                  new PlotSettings(lo.ModelType);
                ps.CopyFrom(lo);

                // The PlotSettingsValidator helps
                // create a valid PlotSettings object
                PlotSettingsValidator psv =
                  PlotSettingsValidator.Current;

                // We'll plot the extents, centered and
                // scaled to fit
                psv.SetPlotType( ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
                psv.SetUseStandardScale(ps, true);
                psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                psv.SetPlotCentered(ps, true);

                // We'll use the standard DWF PC3, as
                // for today we're just plotting to file
                psv.SetPlotConfigurationName(ps, "DWG to PDF.pc3", "ANSI_A_(11.00_x_8.50_Inches)");

                // We need to link the PlotInfo to the
                // PlotSettings and then validate it
                pi.OverrideSettings = ps;
                PlotInfoValidator piv =
                  new PlotInfoValidator();
                piv.MediaMatchingPolicy =
                  MatchingPolicy.MatchEnabled;
                piv.Validate(pi);

                // A PlotEngine does the actual plotting
                // (can also create one for Preview)
                if (PlotFactory.ProcessPlotState ==
                    ProcessPlotState.NotPlotting)
                {
                    PlotEngine pe =
                      PlotFactory.CreatePublishEngine();
                    using (pe)
                    {
                        // Create a Progress Dialog to provide info
                        // and allow thej user to cancel
                        PlotProgressDialog ppd =
                          new PlotProgressDialog(false, 1, true);
                        using (ppd)
                        {
                            ppd.set_PlotMsgString(
                              PlotMessageIndex.DialogTitle,
                              "Custom Plot Progress"
                            );

                            ppd.set_PlotMsgString(
                              PlotMessageIndex.CancelJobButtonMessage,
                              "Cancel Job"
                            );

                            ppd.set_PlotMsgString(
                              PlotMessageIndex.CancelSheetButtonMessage,
                              "Cancel Sheet"
                            );

                            ppd.set_PlotMsgString(
                              PlotMessageIndex.SheetSetProgressCaption,
                              "Sheet Set Progress"
                            );
                            ppd.set_PlotMsgString(
                              PlotMessageIndex.SheetProgressCaption,
                              "Sheet Progress"
                            );
                            ppd.LowerPlotProgressRange = 0;
                            ppd.UpperPlotProgressRange = 100;
                            ppd.PlotProgressPos = 0;

                            // Let's start the plot, at last
                            ppd.OnBeginPlot();
                            ppd.IsVisible = true;
                            pe.BeginPlot(ppd, null);

                            // We'll be plotting a single document
                            pe.BeginDocument(
                              pi,
                              doc.Name,
                              null,
                              1,
                              true, // Let's plot to file
                              path + ".pdf"
                            );

                            // Which contains a single sheet
                            ppd.OnBeginSheet();
                            ppd.LowerSheetProgressRange = 0;
                            ppd.UpperSheetProgressRange = 100;
                            ppd.SheetProgressPos = 0;
                            PlotPageInfo ppi = new PlotPageInfo();
                            pe.BeginPage(
                              ppi,
                              pi,
                              true,
                              null
                            );
                            pe.BeginGenerateGraphics(null);
                            pe.EndGenerateGraphics(null);

                            // Finish the sheet
                            pe.EndPage(null);
                            ppd.SheetProgressPos = 100;
                            ppd.OnEndSheet();

                            // Finish the document
                            pe.EndDocument(null);

                            // And finish the plot
                            ppd.PlotProgressPos = 100;
                            ppd.OnEndPlot();
                            pe.EndPlot(null);
                        }
                    }
                } else {
                    ed.WriteMessage("\nAnother plot is in progress.");
                }
            }
        }
    }
}

Open in new window


Original code taken from http://through-the-interface.typepad.com/
0
Comment
Question by:eXMytheral
  • 2
3 Comments
 
LVL 10

Expert Comment

by:borgunit
ID: 34147591
I believe this needs to be set in the registry first. Once enabled in AutoCAD, it will place a plotstamp automatically.

This may help..

http://forums.autodesk.com/t5/AutoCAD-Architecture/Plot-Stamp-Help/m-p/489331
0
 

Author Comment

by:eXMytheral
ID: 34147737
Granted that does turn the plotstamp on but it doesn't allow any of the options to be set... It seems a bit odd to me that they would almost wall off the plot stamp to code.
0
 
LVL 10

Accepted Solution

by:
borgunit earned 500 total points
ID: 34148261
We do not really use them but I have seen others use FIELDS in their drawings for this.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now