.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

importing layouts

4 REPLIES 4
Reply
Message 1 of 5
abryanb
528 Views, 4 Replies

importing layouts

Im trying to create a function that will behave similar to the Import Layouts from Template command. It should open an external drawing database, and copy all of the layouts into the current drawing, and it works perfectly. The problem is if the command is run again and I try to switch tabs, I get the error attached to this post, any help would be appreciated. A good bit of this code is borrowed from another post, i will try to find it to give credit where credit is due

{code}
DocumentLock oLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
Database dbSource = new Database(false, false);
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = dbSource.TransactionManager.StartTransaction();
try
{
dbSource.ReadDwgFile(fileName, System.IO.FileShare.Read,true, null);
ObjectId idDbdSource = dbSource.LayoutDictionaryId;
DBDictionary dbdLayout = (DBDictionary)trans.GetObject(idDbdSource, OpenMode.ForRead, false, false);
ObjectId idLayout;


ObjectIdCollection idc = new ObjectIdCollection();
foreach (DictionaryEntry deLayout in dbdLayout)
{


if ( deLayout.Key.ToString().ToUpper() != "MODEL")
{

idLayout = (ObjectId) deLayout.Value;
if (!idLayout.IsErased)
{
idc.Add(idLayout);
}
}


}
IdMapping im = new IdMapping();
db.WblockCloneObjects(idc, db.LayoutDictionaryId,im,DuplicateRecordCloning.Ignore,false);


}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (System.Exception ex)
{

MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
trans.Commit();
dbSource.Dispose();
oLock.Dispose();
}
{code} Edited by: abryanb on Jan 26, 2009 12:16 PM
4 REPLIES 4
Message 2 of 5
Hallex
in reply to: abryanb

I used Using for transaction and also I have replaced
trans.Commit();
in front of the first 'catch' expression
This worked nice for me
Hth

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 5
abryanb
in reply to: abryanb

just so i understand this is the code you are now using
{code}
public static void importLayouts(string fileName)
{
DocumentLock oLock = Application.DocumentManager.MdiActiveDocument.LockDocument();


Database dbSource = new Database(false, false);
Database db = HostApplicationServices.WorkingDatabase;

try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
dbSource.ReadDwgFile(fileName, System.IO.FileShare.Read, true, null);
ObjectId idDbdSource = dbSource.LayoutDictionaryId;
DBDictionary dbdLayout = (DBDictionary) trans.GetObject(idDbdSource, OpenMode.ForRead, false, false);
ObjectId idLayout;


ObjectIdCollection idc = new ObjectIdCollection();
foreach (DictionaryEntry deLayout in dbdLayout)
{


if (deLayout.Key.ToString().ToUpper() != "MODEL" )
{

idLayout = (ObjectId) deLayout.Value;
if (!idLayout.IsErased)
{
idc.Add(idLayout);
}
}


}
IdMapping im = new IdMapping();
db.WblockCloneObjects(idc, db.LayoutDictionaryId, im, DuplicateRecordCloning.Ignore, false);
trans.Commit();
}

}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (System.Exception ex)
{

MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{

dbSource.Dispose();
oLock.Dispose();
}
}
{code}

This is producing the exact same results for me. I run in once and it works beautifully. If i run it again and import tabs from the exact same file I still receive the same results. And I am using brand new files that i jsut added a brand new file that I jsut added a coupld of tabs too. I am using Civil 3d 2009 sp2, although i get the same results in 2008
Message 4 of 5
dlundgren
in reply to: abryanb

I'm curious, did you ever get your layout import code working?

-Dale
Message 5 of 5
abryanb
in reply to: abryanb

Kind of. I couldn't get these problems worked out so I decided to just use the layout command with SendStringToExecute.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost