Author Topic: Copying plot settings  (Read 23067 times)

0 Members and 2 Guests are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #45 on: January 31, 2007, 12:26:20 AM »
Can you elaborate there Kerry - I might have a go at it and see what I come up with.

I've seen a C++ solution to copy a Layout which uses copyFrom.
I don't know if it's translatable to managed code.

Because the Layout class derives from the Plotsettings class I thought we may be able to use the same methodology.

Just a W.A.G. I thought I'd investigate

 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Copying plot settings
« Reply #46 on: January 31, 2007, 01:03:45 AM »
Good call Kerry - run this up the flagpole and see who salutes it:

Code: [Select]
[CommandMethod("CopyPlotSettings", CommandFlags.NoTileMode)]
static public void CopyPlotSettings( )
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

LayoutManager layoutMan = LayoutManager.Current;
ObjectId currentLayoutId = layoutMan.GetLayoutId(layoutMan.CurrentLayout);

using (Transaction tr = db.TransactionManager.StartTransaction())
{
Layout currentLayout = tr.GetObject(currentLayoutId, OpenMode.ForWrite, false) as Layout;
if (currentLayout == null)
return;

using (Database templateDb = new Database(false, true))
{
templateDb.ReadDwgFile(@"C:\Temp\Plot.dwt", System.IO.FileShare.ReadWrite, false, null);
using (Transaction dwtTr = templateDb.TransactionManager.StartTransaction())
{
DBDictionary plotsettingsDict = dwtTr.GetObject(templateDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary;
ObjectId plotsettingId = plotsettingsDict.GetAt("A1-A3 DWF");
PlotSettings pageSetup = dwtTr.GetObject(plotsettingId, OpenMode.ForRead) as PlotSettings;

// Copy it over as per Kerry's suggestion...
currentLayout.CopyFrom(pageSetup);
}
}

tr.Commit();
}

}

This is turning into an interesting thread.

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #47 on: January 31, 2007, 01:17:22 AM »
Good call Kerry - run this up the flagpole and see who salutes it:
..................
This is turning into an interesting thread.

Cheers,
Glenn.

That looks like a plan ... I'll have a play after dinner

... yes, this has turned into a fun thread .... and unusually it's almost stayed on topic.

Good stuff Glenn
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #48 on: January 31, 2007, 01:27:42 AM »
 :-) nice touch ..

Code: [Select]
CommandFlags.NoTileMode
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Copying plot settings
« Reply #49 on: January 31, 2007, 01:33:13 AM »
Thankyou :D

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copying plot settings
« Reply #50 on: January 31, 2007, 11:16:23 AM »
Though I only read over everything you two have posted (Kerry and Glenn) I will look more indepth when my brain is ready.  Thank you both for sharing your knowledge, this does sound like fun.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Copying plot settings
« Reply #51 on: January 31, 2007, 08:30:13 PM »
Us lot have a weird defintion of fun eh. ;)

I just found that one sentence in the ARX docs which confirms the behaviour exhibited when cloning dictionary entries:

Quote
AcDbDatabase::wblockCloneObjects Function Acad::ErrorStatus

wblockCloneObjects(

AcDbObjectIdArray& objectIds,

AcDbObjectId& owner,

AcDbIdMapping& idMap,

AcDb::DuplicateRecordCloning drc,

bool deferXlation = false);

objectIds Input array of objects to be deep cloned
owner Input object ID of object to be the owner of the clones
idMap Returns array of AcDbIdPair objects to be used for translating object ID relationships
drc Input action for duplicate records
deferXlation Input Boolean indicating whether or not ID translation should be done

Clones all objects in the objectIds array and appends them to the container object specified by owner. The objects can be from multiple source databases, and must match the type of owner supplied, but must be from a different database than the owner object.

owner can only be an AcDbBlockTableRecord, AcDbDictionary, or AcDbSymbolTable object. In multiple calls, the owners must be from the same destination database. If the owner is a dictionary, newly cloned entries are set as anonymous.
...
...

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #52 on: February 01, 2007, 10:30:27 PM »
.............. I just found that one sentence in the ARX docs which confirms the behaviour

Sometimes, that's all it takes I 'spose ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Copying plot settings
« Reply #53 on: February 01, 2007, 11:00:37 PM »
Hehehe...but it's finding it AGAIN when you know you've "seen it somewhere".

It seems like we're the only 2 interested in this Kerry. For the sake of completeness,
here is a cleaned up implementation that should be easier to follow:

Code: [Select]
[CommandMethod("IPS", CommandFlags.NoTileMode)]
static public void ImportPageSetupCommand( )
{
Database dwtDb = null;

// Get a pointer to the current doc's dbase...
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

Transaction dwtDbTr = null;

// Objectid collection to hold the pagesetups we're going to clone...
ObjectIdCollection psIds = new ObjectIdCollection();
IdMapping psIdMap = null;

try
{
dwtDb = new Database(false, true);
dwtDb.ReadDwgFile(@"C:\Temp\Plot.dwt", System.IO.FileShare.ReadWrite, false, null);

// Kick off the transaction on the template dbase...
dwtDbTr = dwtDb.TransactionManager.StartTransaction();

DBDictionary dwtDbPsDict = dwtDbTr.GetObject(dwtDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary;

foreach (System.Collections.DictionaryEntry psDbPs in dwtDbPsDict)
psIds.Add((ObjectId)psDbPs.Value);

if (psIds.Count == 0)
return;

dwtDbTr.Commit();

// Got id's, so clone 'em
psIdMap = db.WblockCloneObjects(psIds, db.PlotSettingsDictionaryId, DuplicateRecordCloning.Ignore, false);

RenameAnonymousPageSetups(psIdMap);

}
finally
{
if (dwtDbTr != null)
dwtDbTr.Dispose();

if (dwtDb != null)
dwtDb.Dispose();

}

return;
}

static void RenameAnonymousPageSetups(IdMapping plotSettingsIdMap)
{
Database db = plotSettingsIdMap.DestinationDatabase;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary psDict = tr.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForWrite, false) as DBDictionary;
if (psDict == null)
return;

foreach (IdPair psIdPair in plotSettingsIdMap)
{
ObjectId id = psIdPair.Value;
PlotSettings ps = tr.GetObject(id, OpenMode.ForWrite, false) as PlotSettings;

if (ps == null)
continue;

if (psDict.Contains(ps.PlotSettingsName))
{
ObjectId existingPsId = psDict.GetAt(ps.PlotSettingsName);
if (existingPsId != ObjectId.Null)
psDict.Remove(existingPsId);
}

string anonymousName = psDict.NameAt(id);

psDict.SetName(anonymousName, ps.PlotSettingsName);

}

tr.Commit();
}
}

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #54 on: February 01, 2007, 11:23:15 PM »
That looks pretty Glenn .. I'll give it a run tomorrow.

I've given up worrying about who's demonstrating interest right now .. I count on 'someone' getting the confidence to post their own stuff down the road a little so we can all continue this learning process.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Copying plot settings
« Reply #55 on: February 01, 2007, 11:43:28 PM »
It's certainly prettier than the first, but essentially the same concept.

I'm fast giving up as well - the thing that annoys me no end...people who don't even say thankyou, or "I figured it out, here it is..."
I was going to continue this on in the plotting thread that was started and show how to do it with pagesetups...oh well...

Rant off (having a bad day)
« Last Edit: February 01, 2007, 11:46:04 PM by Glenn R »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #56 on: February 02, 2007, 02:07:26 AM »
... I was going to continue this on in the plotting thread that was started and show how to do it with pagesetups...oh well...

..

go for it !!!
That thread deals with layouts too, so the same principle could be applied .. < perhaps>
... one thing I have found is that posting code or answers helps me to clarify <somewhat> my thinking, so I post for purely selfish reasons ... :-D
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Copying plot settings
« Reply #57 on: February 02, 2007, 04:11:22 PM »
I'm here for you.

Judging by the number of plotting questions and the lack of documentation or good answers I would say people are watching this thread. I know I am. And if they aren't watching it now they will certainly be reading it when they try to write a plotting program.

My current solution for batch plotting involves using Page Setups. The setups are stored in what I call a "control" drawing. I import them for plotting by using the Publish mechanism. I don't know if it copies the setup into the drawing or just uses the settings.

I ended up creating a DSD file (sDsdFile). Then I plot my files using "Application.Publisher.PublishDsd(sDsdFile, prog);" (prog is a PlotProgressDialog)
The format of the dsd file wasn't too difficult. One of the lines that is in every sheet description is in the format SetupName|PathToFileContainingSetup:
Setup=mySetupName|\\Full\path\to\my\control\drawing.dwg

Code: [Select]
        public void BatchPlot(ArrayList fullPathList, SourceOfPlot source, PaperSize paper, string DeviceName)
        {
            // Page Setup will be pulled from control dwg file plotControlDWG
            if (fullPathList.Count < 1) return;
            // Page Setup will be pulled from control dwg file plotControlDWG
           
            string pgSetupName = ""; // SOURCE + "-" + PAPER + "-" + DEVICE
            pgSetupName = BuildPageSetupName(source, paper, DeviceName);
            if (FileHasPageSetup(plotControlDWG, pgSetupName) == false)
            {
                // throw error here
                return;
            }
            string fullName = "";
            string shortName = "";
            StringBuilder sbDSD = new StringBuilder();
            // dsd file HEADER
            sbDSD.AppendLine("[DWF6Version]");
            sbDSD.AppendLine("Ver=1");
            sbDSD.AppendLine("[DWF6MinorVersion]");
            sbDSD.AppendLine("MinorVer=1");
            // dsd file LOOP
            for (int i = 0; i < fullPathList.Count; i++)
            {
                fullName = fullPathList[i].ToString();
                shortName = GetShortFileName(fullName);
                sbDSD.AppendLine("[DWF6Sheet:" + shortName.Substring(0, shortName.Length -4) + "]");
                sbDSD.AppendLine("DWG=" + fullName);
                sbDSD.AppendLine("Layout=Model");
                sbDSD.AppendLine("Setup=" + pgSetupName + "|" + plotControlDWG);
                sbDSD.AppendLine("OriginalSheetPath=" + fullName);
                sbDSD.AppendLine("Has Plot Port=0");
                sbDSD.AppendLine("Has3DDWF=0");
            }                       

            // dsd file CLOSER
            sbDSD.AppendLine("[Target]");
            sbDSD.AppendLine("Type=" + PubTypeString(MyPubType));
            if (File.Exists(MyDWFFile)) File.Delete(MyDWFFile);
            sbDSD.AppendLine("DWF=" + MyDWFFile);
            sbDSD.AppendLine("OUT=" + MyPLTPath);
            sbDSD.AppendLine("PWD=");
            sbDSD.AppendLine("[AutoCAD Block Data]");
            sbDSD.AppendLine("IncludeBlockInfo=0");
            sbDSD.AppendLine("BlockTmplFilePath=");
            sbDSD.AppendLine("[SheetSet Properties]");
            sbDSD.AppendLine("IsSheetSet=FALSE");
            sbDSD.AppendLine("IsHomogeneous=FALSE");
            sbDSD.AppendLine("SheetSet Name=");
            sbDSD.AppendLine("NoOfCopies=1");
            sbDSD.AppendLine("PlotStampOn=FALSE");
            sbDSD.AppendLine("JobID=0");
            sbDSD.AppendLine("SelectionSetName=");
            sbDSD.AppendLine("AcadProfile=<<VANILLA>>");
            sbDSD.AppendLine("CategoryName=");
            sbDSD.AppendLine("LogFilePath=");
            sbDSD.AppendLine("IncludeLayer=FALSE");
            sbDSD.AppendLine("PromptForDwfName=TRUE");
            sbDSD.AppendLine("PwdProtectPublishedDWF=FALSE");
            sbDSD.AppendLine("PromptForPwd=FALSE");
            sbDSD.AppendLine("RepublishingMarkups=FALSE");
            sbDSD.AppendLine("PublishSheetSetMetadata=FALSE");
            sbDSD.AppendLine("PublishSheetMetadata=FALSE");
            sbDSD.AppendLine("3DDWFOptions=0 0");
           
            string sDsdFile = @"C:\dsdfile.dsd";
            File.Delete(sDsdFile);
            File.WriteAllText(sDsdFile,sbDSD.ToString());
           
            PlotProgressDialog prog = new PlotProgressDialog(false, fullPathList.Count , true);
            try
            {
                if (Application.DocumentManager.Count == 1)
                {
                    if (Application.DocumentManager.MdiActiveDocument.Name.ToUpper().Contains("DRAWING"))
                    {
                        Application.DocumentManager.Add(blankTemplateFile);
                    }
                }
                if (Application.DocumentManager.Count < 1)
                {
                    Application.DocumentManager.Add(blankTemplateFile);
                    Application.DocumentManager.Add(blankTemplateFile);
                }

                string backGround = Application.GetSystemVariable("BackgroundPlot").ToString();
                Application.SetSystemVariable("BackgroundPlot", 0);
               
                Application.Publisher.PublishDsd(sDsdFile, prog);
               
                Application.SetSystemVariable("BackgroundPlot", Convert.ToInt32(backGround));
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("An error occured in the BatchPlot function of cMyPlot class.\n" +
                    ex.Message + "\nReport this error to Mark", "Batch plot error");
                // throw;
            }
            finally
            {
                prog.Destroy();
                prog.Dispose();
            }
        }

I am still working out a few issues. I may end going with what you posted.
« Last Edit: February 02, 2007, 04:16:54 PM by mohnston »
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Chuck Gabriel

  • Guest
Re: Copying plot settings
« Reply #58 on: February 02, 2007, 06:29:05 PM »
lack_of_posting != lack_of_interest

My interest is, however, somewhat limited by the fact that AutoCAD 2000i doesn't have a .NET API.  :D

I still like to keep up, though, due to natural curiosity and the possibility that I may not be working in the same place forever.

Glenn R

  • Guest
Re: Copying plot settings
« Reply #59 on: February 02, 2007, 10:18:14 PM »
This is pretty much a direct translation from the ARX docs - "Using the Plot API"
« Last Edit: February 28, 2007, 06:13:52 PM by Glenn R »