WBlockCloneObjects into Paper Space overwrites paper space with the cloned object.

richardpangburn
Enthusiast
Enthusiast

WBlockCloneObjects into Paper Space overwrites paper space with the cloned object.

richardpangburn
Enthusiast
Enthusiast

I have a block in my source drawing and I want to use WBlockCloneObjects to transport it into the new drawing and create a reference in paper space of the new drawing.

 

The problem I have, is that when the reference is created, the entire layout space is replaced with the block. As in, the extents of my sheet become the extents of the block.

 

first I iterate through the sourceBlockTable to find the BlockTableRecord I want and I added it to my ObjectIdCollection:

foreach (ObjectId objectId in sourceBlockTable)
{
  //create a btr, do some checks to make sure it's right. I make sure it's 
    not a layout, not from an xref or overlay, etc. Then I make sure the 
    names match..
    BlockTableRecord blockToClone = sourceTrans.GetObject(objectId, OpenMode.
    ForRead) as BlockTableRecord;
    if(blockToClone.Name == blockName //i passed in blockName
  {
    objectIdCollection.Add(objectId);
  }
}

 

After I get the object added to my collection, I access the destinationDatabase in a using() statement to clone the record:

 

IdMapping map = new IdMapping();
sourceDatabase.WblockCloneObjects(objectIdCollection, destinationDatabase.BlockTableId, map, DuplicateRecordCloning.Replace, false);

 

Then I open an transaction and create a reference of the record in paperspace using the standard procedure. I get the paper space block table record I want (I let my users select which layout by TabOrder) and then I create the BlockReference like so:

 

//I make sure the destination block table has record from the cloning...
       blockReferenceId = destinationBlockTable[blockName];

using (BlockReference newBlockReference = new 
       BlockReference(newBlockInsertPoint, blockReferenceId))
       {
        blockTablePaperSpace.AppendEntity(newBlockReference)
        destinationTransaction.AddNewlyCreatedDBObject
        newBlockReference, true);
       }

 

But now my paper space on the layout is simply the block. There is no "sheet" and if I try to edit the page config it just makes the block look bigger but it actually measures the same size, so I'm clearly doing something wrong.

 

 

 

0 Likes
Reply
294 Views
2 Replies
Replies (2)

stefanveurink68AXD
Advocate
Advocate

Probably the problem is in you replacing the full layout by the block instead of inserting the block into the layout. Are you looping through the layouts before inserting the block? the fact you use blocktablepaperspace.appendentity makes me think that too (i don't know exactly what that does, haven't looked into it). So if not, you should. there's lots of codes for this to find on the internet. 

0 Likes

richardpangburn
Enthusiast
Enthusiast

Thanks for the comment Stefan. I had the exact same thought but after having a closer look, and examining this issue deeper in a second post that I made here, I realized that the problem was that when I inserted the block into a layout that had "none" for a page setup, and had never been accessed before (create a new drawing, save-as, close, never click on a paper space layout), inserting a block into that layout will change the plot area to extents and then scale the layout to "fit to paper". I was simply so caught up in the idea that I had done something wrong in code that I didn't realize my page setup was being overridden.

0 Likes