.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Swap titleblock between 2 drawings
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I have 2 files and I'd like to copy a titleblock from a template drawing and use it to replace an existing titleblock on an in progress drawing. The titleblock on the in progress drawing has attributes, and I'd like to keep them when I put in the new titleblock. The attribute tag names between the 2 titleblocks are the same.
I do not know the exact names of the titleblocks, only that they contain the words "title block" somewhere in their name.
I've developed for Inventor for a while now, but I'm completely new to AutoCAD. How might I go about this?
I believe the basic steps would be something like this:
1. Identify which object to copy from template sheet.
2. Save that object to memory
3. Identify object to replace in existing drawing
4. Copy attributes and get position of existing titleblock
5. Delete existing titleblock
6. Insert new titleblock and copy in attributes
I've taken the Autocad tutorials, and I've searched for relevant posts on ThroughTheInterface. Is there someplace else to look which might give a more in-depth example of what I'm trying to accomplish?
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000
Inventor 2013
ETO 6.1
Re: Swap titleblock between 2 drawings
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I suppose in my attempt to make a brief question, some might have assumed I wanted someone to write an entire program for me. I don't. I'll attempt to clarify which parts I need assistance with.
Right now I'm using this code to copy a titleblock from another drawing. Is there a way to get the new objectIds of the objects that I just inserted? Currently they are on a layer that doesn't exist. My goal is to get the new objectID of the item(s) I just copied, then use the setLayer property.
acCurDb.WblockCloneObjects(objColl, btr.ObjectId, iMap, DuplicateRecordCloning.Ignore, false);
I noticed that attributes doesn't have a set command. Is there a specific way I should copy items from an attributeCollection to a new attributeCollection?
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000
Inventor 2013
ETO 6.1
Re: Swap titleblock between 2 drawings
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
I've never tried it but I assume the IdMap gives you the facility to look up the new id from the original one..
IdMapping
IdMapping acIdMap = new IdMapping();
acCurDb.WblockCloneObjects(interferenceIdCol, acBlkTblRecNewDoc.ObjectId, acIdMap,
DuplicateRecordCloning.Ignore, false);
newId = acIdMap.Lookup(oldId);
Setting attributes you just loop through them and set the text string (maybe there is away to do the whole collection at once but I haven't managed it - hopefully someone with more time/experience than me can confirm if it can be done)...
foreach (ObjectId attId in attcol)
{
AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForWrite);
if (attRef.Tag.ToLower() == attName.ToLower())
{
if (attRef.TextString.ToLower() != attValue.ToLower())
{
attRef.TextString = attValue;
attUpdated += 1;
}
}
}I think I would be tempted to make a list of key value pairs containing the attribute tag and the text string from the old block, then loop through the new block setting the appropriate value.
Regards,
Graham
Mitek Industries
Re: Swap titleblock between 2 drawings
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Actually, my code doesn't do what i thought it did...which means my last question was no longer relevant. First, the code from adndevblog that I was using is wrong. It had me copying from and to the wrong databases. ThroughTheInterface has similar code from 2006 that is correct, so I'm using that now.
Apparently, this only copies the drawing definition:
var iMap = new IdMapping(); sourceDatabase.WblockCloneObjects(objColl, bt.ObjectId, iMap, DuplicateRecordCloning.Ignore, false);
Now that I have the definition, what do I need to do to actually insert this as a block in the drawing? (so i can see it)
This is what I have so far to insert a new block, but it obviously isn't complete. If I understand correctly, the above code creates a BlockTableRecord. For the code below, I don't know how to specify which BlockTableRecord(definition) I just inserted.
//Add a blockReference to the newly inserted blockTableRecord BlockTableRecord newbtr = ??????? newbtr.Name = blockToReplace.Name + "1"; ObjectId newbtrId = bt.Add(newbtr); tr.AddNewlyCreatedDBObject(newbtr, true);
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000
Inventor 2013
ETO 6.1
Re: Swap titleblock between 2 drawings
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Inserting a block is something like this (where [cassName] is the name of your block...
BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForWrite); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRec ord.ModelSpace], OpenMode.ForWrite); try { BlockTableRecord blk = (BlockTableRecord)trans.GetObject(bt[cassName], OpenMode.ForWrite); if (blk != null) { Autodesk.AutoCAD.DatabaseServices.BlockReference blkRec = new Autodesk.AutoCAD.DatabaseServices.BlockReference(i p, blk.ObjectId); blkRec.SetDatabaseDefaults(); blkRec.LayerId = layId; btr.AppendEntity(blkRec); trans.AddNewlyCreatedDBObject(blkRec, true); Extents3d ext3d = (Extents3d)blkRec.Bounds; ip = new Point3d(ext3d.MaxPoint.X + 300, ext3d.MaxPoint.Y, 0); } } catch { }
Ignore the last couple of lines relating the Extents3D.
You will then need to get the attributes collection and fill out the values similar to the previous code (i think you do this even if you want the default values).
