Solved

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

Posted on 2010-11-15
3
2,920 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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