.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi community,
my job is to make an editor for blocks in C#. There should be a WPF-window were the user can see a list of blocks. He selects one and than he should see an overview about block attributes like insertionpoint, basepoint, rotation and scaling and he should be able to edit these attributes in this form.
I know how i can populate a list of block names, but I fail at finding an opportunity to edit these attributes.
I get the blocktablerecords, but then?
I am very, very new to Autocad, and I've googled the last five hours unsuccessfully for a solution which is suitable for my problem.
Please help me, it is very urgent!
Kind regards,
Klaus
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> I get the blocktablerecords, but then?
Scan through the entities in the BlockTableRecord and find out which one is from type AttributeDefinition
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
The only thing i've found with "AttributeDefinition" was
blocktablerecord.HasAttributeDefinitions,
but nothing with type "AttributeDefinition". Maybe I've missunderstood you?
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
go through each DBObject in the BlockTableRecord
verify if the current checked object is an AttributeDefintion, if it is one you have one (of may be more) AttributeDefinitions, take them for your handling you need to do with them.
Dim tTrAct As DatabaseServices.Transaction = Nothing 'set your tTrAct
Dim tBlTabRec As DatabaseServices.BlockTableRecord = Nothing 'set your tBlTabRec
'now scan through the objects in the BTR
For Each tObjID As DatabaseServices.ObjectId In tBlTabRec
If (tObjID.IsValid) AndAlso (Not tObjID.IsErased) AndAlso (tObjID.ObjectClass.DxfName.ToUpper = "ATTDEF") Then
'ok object is valid and it's a AttributeDefinition
Dim tAttDef As DatabaseServices.AttributeDefinition = CType(tTrAct.GetObject(tObjID, DatabaseServices.OpenMode.ForRead), DatabaseServices.AttributeDefinition)
'here you have your access to the AttributeDefinition-object
End If
Next
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Okay, i try to translate this in C# and i hope I am successful with that. ![]()
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> i try to translate
If you don't know it: that may help >>>translate c# vb<<<
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
At
if ((tObjID.IsValid) && (tObjID.IsErased == false) && (tObjID.ObjectClass.DxfName.ToUpper = "ATTDEF"))
{
AttributeDefinition tAttDef = (AttributeDefinition)tTrAct.GetObject(tObjID, OpenMode.ForRead);
}
I get an error:
Cannot assign to 'ToUpper' because it is a 'method group'.
Do you know a workaround?
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
you can erase the .ToUpper as it should not be necessary in that case, AutoCAD reports "ATTDEF" already in uppercase IMHO.
But I think you have to set double "=" in that statement for comparision in C#? So one equal-sign is missing and then .ToUpper should work also!
tObjID.ObjectClass.DxfName.ToUpper == "ATTDEF"
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Yes, the second "=" helped, but it needed .ToUpper() to really work.
Okay I look how far i get with that and I will come back to this thread if I have any further problems.
Thank you very much!
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Further problems! ![]()
I've tried to print out some attributes but nothing happened... Now I've debugged this code:
if ((tObjID.IsValid) && (tObjID.IsErased == false) && (tObjID.ObjectClass.DxfName.ToUpper() == "ATTDEF"))
{
window.listBlockAttributes.Items.Add(tAttDef.Layer );
window.listBlockAttributes.Items.Add(tAttDef.Rotat ion.ToString());
}and i realized that something is wrong with the last if (tObjID.ObjectClass... and so on).
The Code passes the first two ifs but never the third one.
Can you help me again? ![]()
The whole code of this method:
[CommandMethod("loadbe")]
public static void LoadBe()
{
Window1 window = new Window1();
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
List<String> blocks = new List<string>();
using (tr)
{
window.listBlockAttributes.Items.Add("bin im using");
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
foreach (ObjectId objId in bt)
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(objId, OpenMode.ForRead);
foreach (ObjectId tObjID in btr)
{
if ((tObjID.IsValid) && (tObjID.IsErased == false) && (tObjID.ObjectClass.DxfName.ToUpper() == "ATTDEF"))
{
AttributeDefinition tAttDef = (AttributeDefinition)tr.GetObject(tObjID, OpenMode.ForRead);
window.listBlockAttributes.Items.Add(tAttDef.Layer );
window.listBlockAttributes.Items.Add(tAttDef.Rotat ion.ToString());
}
}
window.listBlocks.Items.Add(btr.Name);
}
}
Autodesk.AutoCAD.ApplicationServices.Application.S howModelessWindow(window);
}Yeah, i know this code is not very useful, but i only wanted to know if there are any attributes which i can print out and I throw them in a list for now.
Kind Regards
Klaus



