.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
My routine inserts in modelspace different blocks with attributes in it with justification "Center".
After the blocks are inserted and the attributes are filled, it all looks good in Autocad.
Then I want to plot the DWG.
The problem is that the centered attributes in the plot are then justified to "Left" ????
When I run my routine the second time in the same drawing then it goes well.
Why is that? Am I missing something?
It looks like the attributes or blockreference isn't updated well in the database after insert?
Thanks,
Geert
Code:
public static BlockReference InsertBlockReference(Database database, string filename, string blockname, Point3d
{
using (DocumentLock documentLock = Active.Document.LockDocument())
{
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
ObjectId newBlockID = new ObjectId();
BlockTable blockTable = (BlockTable) database.BlockTableId.GetObject(OpenMode.ForRead); //Modelspace
using (BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject
{
if (blockTable.Has(blockname))
{
newBlockID = blockTable[blockname];
}
else
{
newBlockID = GetBlockIDFromReadDwgFile(database, filename, blockname);
}
BlockReference newBlockReference = new BlockReference(insertionpoint, newBlockID);
newBlockReference.ScaleFactors = scalefactor;
blockTableRecord.AppendEntity(newBlockReference);
transaction.AddNewlyCreatedDBObject(newBlockRefere
//Attributes in Block
BlockTableRecord newBlockTableRecord = GetBlockTableRecord(newBlockID, blockname); if (newBlockTableRecord.HasAttributeDefinitions)
{
AddAttributesToNewBlockReference(newBlockTableReco
}
transaction.Commit();
return newBlockReference;
}
}
}
}
private static void AddAttributesToNewBlockReference(BlockTableRecord blocktablerecord, BlockReference
{
using (Transaction transaction = blockreference.BlockId.Database.TransactionManager
{
foreach (ObjectId objectId in blocktablerecord)
{
Entity entity = (Entity) transaction.GetObject(objectId,OpenMode.ForRead);
if (entity is AttributeDefinition)
{
AttributeDefinition newAttributeDefinition = (AttributeDefinition)entity;
AttributeReference newAttributeReference = new AttributeReference();
newAttributeReference.SetAttributeFromBlock(newAtt
transaction.AddNewlyCreatedDBObject(newAttributeRe
}
}
transaction.Commit();
}
}
public static void UpdateAttributeValues(BlockReference blockreference, Dictionary<string, string> dictionary)
{
using (Transaction transaction = blockreference.BlockId.Database.TransactionManager
{
AttributeCollection attributeCollection = blockreference.AttributeCollection;
foreach (ObjectId attributeId in attributeCollection)
{
AttributeReference attributeReference = (AttributeReference)attributeId.GetObject(OpenMode
if (dictionary.ContainsKey(attributeReference.Tag))
{
attributeReference.TextString = dictionary[attributeReference.Tag];
}
}
transaction.Commit();
}
}
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
try the .AdjustAlignment option after adding an AttributeReference.
From the object browser:
Public Overridable Sub AdjustAlignment(alternateDatabaseToUse As Autodesk.AutoCAD.DatabaseServices.Database)
Good luck, - alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Alfred,
thanks for your reply.
I add -> newAttributeReference.AdjustAlignment(blockreferen
When I check the newAttributeReference.Justify in my code by defining them its "BaseCenter" which it has to be, so that's good.
I discovered when I (in code) insert the blocks with attributes and fill them and then I first save the drawing, with for example:
Active .WorkingDatabase.SaveAs(@"K:\" + articleNumber + ".dwg", DwgVersion.AC1021);
If I then plot the drawing it seems to be good.
But I don't want/needs to save the drawing. I just want to open the drawing, insert some blocks, fill the attributes, plot it and then close the drawing.
I must be something missing in saving / writing in a database of something, so the attributes doesn't have their right justification?????
regards,
Geert
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
The same happended to me last week for centered text entities if the textstyle is changed via program.
Both old and new text style used the same shx file and thus the text itself looks the same. But the location of the centered text changed. Redraw solved this issue for me and because it was a one time happening i didn't looked any further.
So probably any update function need to be called after changing the attributes.
Maybe any of the following may be helpful
attRef.AdjustAlignment(db);
blr.RecordGraphicsModified(true);
doc.TransactionManager.QueueForGraphicsFlush();
ed.Regen();
Application.Update;
Application.UpdateScreen();
pvp.UpdateDisplay();
db.UpdateExt(true);
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for your reply!
All your suggestions tried with no result, except -> pvp.UpdateDisplay();
I can't find a way to trigger this.
What's pvp? and how do I get this?
Geert
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
As I remember for proper alignment you need temporary switch working database to database in which you add blockreference (and attributes):
Database wdb = HostApplicationServices.WorkingDatabase; HostApplicationServices.WorkingDatabase = blockreference.BlockId.Database; ar.AdjustAlignment(blockreference.BlockId.Database); HostApplicationServices.WorkingDatabase = wdb;
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
pvp is a Paperspace Viewport.
Viewport pvp;
DBDictionary layoutDic = trx.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
foreach (DBDictionaryEntry entry in layoutDic)
{
Layout lay = trx.GetObject(entry.Value, OpenMode.ForRead) as Layout;
if (!lay.ModelType)...
BlockTableRecord tbr = (BlockTableRecord)trx.GetObject(lay.BlockTableReco
ObjectIdCollection vpIds = lay.GetViewports();
Viewport pvp = tr.GetObject(vpIds[1], OpenMode.ForWrite) as Viewport;
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Nope, this isn't the solution either.
Also Alexander thanks for your reply but that's not working either.
For now it leaves me nothing else then to SaveAs the drawing before I plot.
It's a pity because that takes time.
other suggestions?
Geert
Re: Plot dwg with centered attributes - problem
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content






