All,
I am importing a revised pagesetup into a drawing that has a pagesetup with the same name (essentially overwriting the pagesetup with a newer version. All of the settings appear to be importing properly except the CTB file (it is still pointing to the previous ctb file). Unfortunately, the CTB file is the main thing that has been changed and in need of updating!
This issue is mentioned here: https://forums.autodesk.com/t5/printing-and-plotting/page-setups-not-importing-ctb/td-p/290624 but no solution given.
Suggestions?
Chris
Please use the Accept as Solution or Kudo buttons when appropriate
Chris Lindner
CAD Technology Consultant @ onebuttoncad.com
AUGI Board of Directors
Solved! Go to Solution.
Solved by Ed.Jobe. Go to Solution.
Hi Chris,
Have you tried deleting the page setup before reimporting?
Hi clindner,
I am trying to repro in Acad 2016, but this seems to work as expected. Which version are you with ?
Also have you try to delete the Named Page Setup before reimporting the one with same name ?
Cheers, Nicolas
Thanks for the reply eljobe.
Deleting it manually first works.
The reason I say "manually" is because I've automated our pagesetup importing. It turns out that the problem is with the function being used to delete the pagesetup (DelPageSetup) is not working as expected. Oddly, It deletes the pagesetup from the list of available pagesetups, but any layout tabs that referenced it still shows it as current. See below.
Before running DelPageSetup
After running DelPageSetup.
So, this is a whole 'nuther issue! 🙂 If you have any more reliable code for deleting page setups, LMK.
Thanks!
Chris
Please use the Accept as Solution or Kudo buttons when appropriate
Chris Lindner
CAD Technology Consultant @ onebuttoncad.com
AUGI Board of Directors
Here's my code. It is made up of 2 commands. The first command configures the second and you only have to run it once. This reduces importing to a single click.
using acApp = Autodesk.AutoCAD.ApplicationServices.Application; using acWin = Autodesk.AutoCAD.Windows; // ImportPageSetupsConfig /// <summary> /// Configures setup for the ImportPageSetupsND command. /// </summary> [CommandMethod("TID", "ImportPageSetupsConfig", "ImportPageSetupsConfig", CommandFlags.Modal)] public void ImportPageSetupsConfig() { acWin.OpenFileDialog fb = new acWin.OpenFileDialog("Select a File to import page setups from.", "", "dwg;dwt", "ImportPS", acWin.OpenFileDialog.OpenFileDialogFlags.NoFtpSites | acWin.OpenFileDialog.OpenFileDialogFlags.NoUrls ); System.Windows.Forms.DialogResult dr = fb.ShowDialog(); try { if (dr != DialogResult.Cancel) { // Store the dwg path. Properties.Settings.Default.PlotSettingPath = fb.Filename; Properties.Settings.Default.Save(); // Read the DWG into a side database Database sourceDb = new Database(false, true); sourceDb.ReadDwgFile(fb.Filename, System.IO.FileShare.Read, true, ""); // Get the page setups. try { string[] plotSettingsMS = new string[] { "**none**" }; string[] plotSettingsPS = new string[] { "**none**" }; using (Transaction trans = sourceDb.TransactionManager.StartTransaction()) { DBDictionary sourceDict = trans.GetObject(sourceDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary; foreach (DictionaryEntry de in sourceDict) { PlotSettings plotSettings = trans.GetObject((ObjectId)(de.Value), OpenMode.ForRead) as PlotSettings; // Separate MS page setups from PS page setups. if (plotSettings.ModelType == true) { Array.Resize(ref plotSettingsMS, plotSettingsMS.Length + 1); plotSettingsMS.SetValue(plotSettings.PlotSettingsName, plotSettingsMS.Length - 1); } else { Array.Resize(ref plotSettingsPS, plotSettingsPS.Length + 1); plotSettingsPS.SetValue(plotSettings.PlotSettingsName, plotSettingsPS.Length - 1); } } trans.Commit(); } // Show Dialog with page setup names // Have the user select a MS config. TID_.Forms.PageSetups frmPageSetups = new TID_.Forms.PageSetups(); frmPageSetups.SetListItems = plotSettingsMS; frmPageSetups.SetPrompt = "Select MS page setup."; dr = acApp.ShowModalDialog(frmPageSetups); string msPageSetup = frmPageSetups.Selected; if (dr == DialogResult.OK) { Properties.Settings.Default.PlotSettingMS = frmPageSetups.Selected; Properties.Settings.Default.Save(); } else { return; // User cancelled. } // Have the user select a PS config. frmPageSetups.SetListItems = plotSettingsPS; frmPageSetups.SetPrompt = "Select PS page setup."; dr = acApp.ShowModalDialog(frmPageSetups); string psPageSetup = frmPageSetups.Selected; if (dr == DialogResult.OK) { Properties.Settings.Default.PlotSettingPS = frmPageSetups.Selected; Properties.Settings.Default.Save(); } else { return; // User cancelled. } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { //Throw Exception or ignore if user cancelled command. if (ex.ErrorStatus != ErrorStatus.NullObjectId) { MessageBox.Show("Error Occured in ImportPageSetupsConfig command. " + ex.Message + ", " + ex.HelpLink, "ImportPageSetupsConfig Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }; } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { MessageBox.Show("Error Occured in ImportPageSetupsConfig command. " + ex.Message + ", " + ex.HelpLink, "ImportPageSetupsConfig Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }; } // ImportPageSetupsND /// <summary> /// Using settings captured by the ImportPageSetupsConfig command, imports page setups /// from another drawing into the current drawing. ND suffix indicates that No Dialog /// is used in this command. Besides importing page setups, named views needed for plotting /// are also imported. /// </summary> [CommandMethod("TID", "ImportPageSetupsND", "ImportPageSetupsND", CommandFlags.Modal)] public void ImportPageSetupsND() { try { if (Properties.Settings.Default.PlotSettingPath != "") { // Read the DWG into a side database Database sourceDb = new Database(false, true); sourceDb.ReadDwgFile(Properties.Settings.Default.PlotSettingPath, System.IO.FileShare.Read, true, ""); // get the active db. Database destDb = Active.Database; using (Transaction destTrans = destDb.TransactionManager.StartTransaction()) { // delete existing page setups DBDictionary destDict = destTrans.GetObject(destDb.PlotSettingsDictionaryId, OpenMode.ForWrite) as DBDictionary; foreach (DictionaryEntry de in destDict) { PlotSettings plotSettings = destTrans.GetObject((ObjectId)(de.Value), OpenMode.ForWrite) as PlotSettings; plotSettings.Erase(); } // rename existing plot views first in case a layout refers to one // delete them after importing and setting layout.ViewToPlot to new view ViewTable destVT = destTrans.GetObject(destDb.ViewTableId, OpenMode.ForWrite) as ViewTable; foreach (ObjectId dId in destVT) { ViewTableRecord dVTR = destTrans.GetObject(dId, OpenMode.ForWrite) as ViewTableRecord; if (Regex.IsMatch(dVTR.Name, "PLOT")) { dVTR.Name = "x" + dVTR.Name; } } using (Transaction sourceTrans = sourceDb.TransactionManager.StartTransaction()) { // import template page setups // Importing page setups also brings in referenced views. DBDictionary sourceDict = sourceTrans.GetObject(sourceDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary; foreach (DictionaryEntry de in sourceDict) { PlotSettings SourcePlotSettings = sourceTrans.GetObject((ObjectId)(de.Value), OpenMode.ForRead) as PlotSettings; PlotSettings tempPlotSettings = new PlotSettings(SourcePlotSettings.ModelType); tempPlotSettings.CopyFrom(SourcePlotSettings); tempPlotSettings.AddToPlotSettingsDictionary(destDb); destTrans.AddNewlyCreatedDBObject(tempPlotSettings, true); } sourceTrans.Commit(); } // iterate layouts and set a page setup DBDictionary LayoutsDict = destTrans.GetObject(destDb.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary; foreach (DBDictionaryEntry entry in LayoutsDict) { DBDictionary plsDict = destTrans.GetObject(destDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary; ObjectId lid = entry.Value; Layout lay = destTrans.GetObject(lid, OpenMode.ForWrite) as Layout; if (lay.ModelType == false) // false = PaperSpace { PlotSettings pls = plsDict.GetAt(Properties.Settings.Default.PlotSettingPS).GetObject(OpenMode.ForRead) as PlotSettings; lay.CopyFrom(pls); } else { PlotSettings pls = plsDict.GetAt(Properties.Settings.Default.PlotSettingMS).GetObject(OpenMode.ForRead) as PlotSettings; lay.CopyFrom(pls); } } // delete existing plot views foreach (ObjectId dId in destVT) { ViewTableRecord dVTR = destTrans.GetObject(dId, OpenMode.ForWrite) as ViewTableRecord; if (Regex.IsMatch(dVTR.Name, "xPLOT")) { dVTR.Erase(); } } destTrans.Commit(); Active.Editor.WriteMessage("\nPage setups imported successfully."); } } else { MessageBox.Show("You must first run the ImportPageSetupsConfig command.", "ImportPageSetupsND", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { MessageBox.Show("Error Occured in ImportPageSetupsND command. " + ex.Message + ", " + ex.HelpLink, "ImportPageSetupsND Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }; }
Ed,
<mind blown> Thanks for code! Woah! Kinda makes me love AutoLisp. 🙂 But lisp has in simplicity, it obviously lacks in functionality! Need to spend more time with .NET.
I love the "one-click" simplicity of this, but my current approach (albeit flawed at the moment) is "no-click". It is part of our ACADDOC.lsp to keep the pagesetups current.
I haven't dove into your code yet to see how I can integrate it into our existing environment or if I can hack it to auto-execute (i.e. no-clck).
Thanks, again!
Chris
Please use the Accept as Solution or Kudo buttons when appropriate
Chris Lindner
CAD Technology Consultant @ onebuttoncad.com
AUGI Board of Directors
Can't find what you're looking for? Ask the community or share your knowledge.