First my apologies for getting back to you so late.
What I'm looking for is a way to supply a parameter or system variable or something at the time of dwf publishing from AutoCAD. Something I can add to my publishing code which toggles the password protection and defines the password for the ensuing multi-sheet dwf.
There is no API that prompts user for password however there is a work around to get it done all you need to do is edit the dsd file[ ASCII file] find for this strings "PwdProtectPublishedDWF=FALSE and PromptForPwd=FALSE" turn them true if they are false.
Here is full sample , and test sample is available at publishing-model-views-to-a-multi-sheet-dwf
[CommandMethod("PublishViews2MultiSheet")]
static public void PublishViews2MultiSheet()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
StringCollection viewsToPlot = new StringCollection();
viewsToPlot.Add("Test1");
viewsToPlot.Add("Test2");
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
ObjectId layoutId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout);
Layout layout = Tx.GetObject(layoutId, OpenMode.ForWrite) as Layout;
foreach (String viewName in viewsToPlot)
{
PlotSettings plotSettings = new PlotSettings(layout.ModelType);
plotSettings.CopyFrom(layout);
PlotSettingsValidator psv = PlotSettingsValidator.Current;
psv.SetPlotConfigurationName(plotSettings, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
psv.RefreshLists(plotSettings);
psv.SetPlotViewName(plotSettings, viewName);
psv.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.View);
psv.SetUseStandardScale(plotSettings, true);
psv.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
psv.SetPlotCentered(plotSettings, true);
psv.SetPlotRotation(plotSettings, PlotRotation.Degrees000);
psv.SetPlotPaperUnits(plotSettings, PlotPaperUnit.Inches);
plotSettings.PlotSettingsName = String.Format("{0}{1}", viewName, "PS");
plotSettings.PrintLineweights = true;
plotSettings.AddToPlotSettingsDictionary(db);
Tx.AddNewlyCreatedDBObject(plotSettings, true);
psv.RefreshLists(plotSettings);
layout.CopyFrom(plotSettings);
}
Tx.Commit();
}
short bgPlot = (short)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("BACKGROUNDPLOT");
Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
string dwgFileName = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("DWGNAME") as string;
string dwgPath = Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("DWGPREFIX") as string;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
DsdEntryCollection collection = new DsdEntryCollection();
ObjectId activeLayoutId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout);
foreach (String viewName in viewsToPlot)
{
Layout layout = Tx.GetObject(activeLayoutId, OpenMode.ForRead) as Layout;
DsdEntry entry = new DsdEntry();
entry.DwgName = dwgPath + dwgFileName;
entry.Layout = layout.LayoutName;
entry.Title = viewName;
entry.NpsSourceDwg = entry.DwgName;
entry.Nps = String.Format("{0}{1}", viewName, "PS");
collection.Add(entry);
}
dwgFileName = dwgFileName.Substring(0, dwgFileName.Length - 4);
DsdData dsdData = new DsdData();
dsdData.SheetType = SheetType.MultiDwf;
dsdData.ProjectPath = dwgPath;
dsdData.DestinationName = dsdData.ProjectPath + dwgFileName + ".dwf";
if (System.IO.File.Exists(dsdData.DestinationName)) System.IO.File.Delete(dsdData.DestinationName);
dsdData.SetDsdEntryCollection(collection);
string dsdFile = dsdData.ProjectPath + dwgFileName + ".dsd";
dsdData.WriteDsd(dsdFile);
System.IO.StreamReader sr = new System.IO.StreamReader(dsdFile);
string str = sr.ReadToEnd();
sr.Close();
str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE");
/*Prompts User to Enter Password and Reconfirms*/
str = str.Replace("PromptForPwd=FALSE", "PromptForPwd=TRUE");
str = str.Replace("PwdProtectPublishedDWF=FALSE", "PwdProtectPublishedDWF=TRUE");
int occ = 0;
int index = str.IndexOf("Setup=");
int startIndex = 0;
StringBuilder dsdText = new StringBuilder();
while (index != -1)
{
String str1 = str.Substring(startIndex, index + 6 - startIndex);
dsdText.Append(str1);
dsdText.Append(String.Format("{0}{1}", viewsToPlot[occ], "PS"));
startIndex = index + 6;
index = str.IndexOf("Setup=", index + 6);
if (index == -1)
{
dsdText.Append(str.Substring(startIndex, str.Length - startIndex));
}
occ++;
}
System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile);
sw.Write(dsdText.ToString());
sw.Close();
dsdData.ReadDsd(dsdFile);
System.IO.File.Delete(dsdFile);
PlotConfig plotConfig = PlotConfigManager.SetCurrentConfig("DWF6 ePlot.pc3");
Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher;
publisher.PublishExecute(dsdData, plotConfig);
Tx.Commit();
}
Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);
}
Hope this solves your problem.