.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> something is wrong with the last if (tObjID.ObjectClass... and so on).
>> The Code passes the first two ifs but never the third one.
What AutoCAD-version do you have? And have you set LateBinding as allowed in your C#-project-settings?
The .DxfName did not exist from the beginning of AutoCAD & dotNET, it was added with AutoCAD 2010 I think (but I'm not sure about that, maybe a version earlier).
Anyway, if the property would not exist in your AutoCAD-version you should get an exception then ... do you see such when debugging?
>> listBlockAttributes
What type is this variable?
- alfred -
PS: "bin im using" deutet auf D oder A oder CH hin???
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
Autocad-version 2012
Visual Studio 2010
Latebinding doesn't mean anything to me. ![]()
And at debugging, i get no exception(?).
listBlockAttributes is a ListBox.
PS: Österreich ![]()
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
without error-handling (and some checks like check for proxy, for xref, ...) this works with my drawings (having blocks with attributes) and AutoCAD 2010, 2011, 2012, 32bit and 64bit:
[Autodesk.AutoCAD.Runtime.CommandMethod("ADESK_Lis tBlockAttdefs")]
public void ADESK_ListBlockAttdefs()
{
string ResultStr = "";
Document tAcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument;
using (Transaction tTrAct = tAcadDoc.TransactionManager.StartTransaction())
{
BlockTable tBlTab = tTrAct.GetObject(tAcadDoc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
IEnumerator tBlTabEnum = tBlTab.GetEnumerator();
while (tBlTabEnum.MoveNext())
{
BlockTableRecord tBlTabRec =tTrAct.GetObject((ObjectId) tBlTabEnum.Current ,OpenMode.ForRead) as BlockTableRecord;
IEnumerator tBlTabRecEnum = tBlTabRec.GetEnumerator();
while (tBlTabRecEnum.MoveNext())
{
ObjectId tObjID = (ObjectId)tBlTabRecEnum.Current;
if ((tObjID.IsValid == true) && (tObjID.IsErased == false) && (tObjID.ObjectClass.DxfName.ToUpper() == "ATTDEF"))
{
AttributeDefinition tAttDef = tTrAct.GetObject(tObjID,OpenMode.ForRead) as AttributeDefinition;
ResultStr += "Block: " + tBlTabRec.Name + "... Att: " + tAttDef.Tag + "\n\r";
}
}
}
}
//here you have the result of all your Blockdefinitions and their Attributedefinitions
}
- 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've tried your solutioin a bit, but the compiler isn't able to get in this third if:
if(tObjID.ObjectClass.DxfName.ToUpper() == "ATTDEF")
{
...
}The value of tObjID.ObjectClass.DxfName.ToUpper() is always something like "LINE", "LWPOLYLINE", etc. but never "ATTDEF".
Hmmm, and now?
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
can you upload a drawing that you work on for testing the code?
- 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
Oh.. they are very simple! ![]()
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 don't have Attribtutes (not -definitions and no -references) in your drawing. So the scan will never find one as there are none. ![]()
Try my attachment, a traffic-sign with a lot of attributes.
- 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
Thanks for that, my Autocad-experiences belong to a 15min introduction. ![]()
Okay, I've tried it and now I see a lot more than 10 minutes ago! ![]()
Next step: editting these attributes... We will see... ![]()
Re: Edit a Block via C#
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> Next step: editting these attributes
Be careful, you should understand some AutoCAD-internals to be able to develop based on it.
In this example you have to differenciate between AttributeDefinition and AttributeReference! If you want to modify the definition of the block, then you have to do this with BlockTableRecord and AttribtueDefinition, if you want to modify the speed-limit of my traffic-sign you have to use BlockReference and AttributeCollection and AttributeReference.
The example-code above handles the definitions.
- 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
It should be generally able to edit these attributes:
- Layer
- Insertionpoint
- Basepoint
- Rotation
- Scaling X
- Scaling Y
- Scaling Z
- Sampling fraction (Auswahlsatz in Englisch?
)
But this is the next problem, I see many attributes like kmh, beleuchtet, mast_id, etc. but non of those, I've mentioned.
How can i reach them?



