Author Topic: Place blocks in template  (Read 1367 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
Place blocks in template
« on: January 05, 2012, 05:19:43 PM »
I am trying to place a block into its own drawing file, the drawing file I want it to go into is a standard template our company uses. The block is to be placed in model space. This code correctly creates the new drawing and places the block on the correct coordinates, however the block is not placed into the template I have specified in my code. Is this possible to do with a wblock command? I know it places it correctly in the desired template when I use wblockcloneobjects but I want to stay away from that command for this if possible. Here is the code I am trying to do this with. Any help greatly appreciated, Thanks.

Ted

Code: [Select]
Dim db1 As Database = New Database(False, False)

   db1.ReadDwgFile("Y:\CAD STANDARDS\Blocks\Templates\PART DRAWING 2012 EPICOR.dwt", FileShare.ReadWrite, False, "")
    Using trx3 As Transaction = db1.TransactionManager.StartTransaction()

    Dim bt As BlockTable = TryCast(trx3.GetObject(db1.BlockTableId, OpenMode.ForRead), BlockTable)
    Dim IDMap As New IdMapping()

    db1 = database.Wblock(oidc2, blkRef.Position)
    db1.SaveAs(strSaveDir & "\" & strFileDir & " - parts\" & strBlockName & ".dwg", DwgVersion.Newest)
    db1.Dispose()
    ok = True
End Using

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Place blocks in template
« Reply #1 on: January 06, 2012, 03:03:02 AM »
Hi,

Try this (not tested)

Code: [Select]
        private void WblockToTemplate(ObjectIdCollection oidc, Point3d pt, Database source, string templateName, string filename)
        {
            using (Database target = new Database())
            {
                target.ReadDwgFile(templateName, FileShare.ReadWrite, false, "");
                source.Wblock(target, oidc, pt, DuplicateRecordCloning.Replace);
                target.SaveAs(filename, DwgVersion.Current);
            }
        }
Speaking English as a French Frog

TJK44

  • Guest
Re: Place blocks in template
« Reply #2 on: January 06, 2012, 10:26:06 AM »
Thank you gile! That fixed the problem I was having. I was trying to do it similar to the way you showed like this, but wasn't working. I see what I was missing now.

Code: [Select]
Using target As Database = database.Wblock(oidc2, blkRef.Position)
    target.readdwgfile(templateName, FileShare.ReadWrite, false, "")
    target = source.wblock(oidc, pt)
    target.saveas(filename, dwgversion.current)
End Using