.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello I can help defense.
How can I add an attribute to a block without the other attributes to move from their position.
With the ATTSYNC belongs unfortunately not because the old attributes moved back to the original places that I will not.
Please help
(Attribut zu Block ohne die alten ATT zu verschieben)
Hallo kann mir wehr Helfen.
Wie kann ich ein Attribut zu einem Block hinzufügen ohne die anderen Attribute von ihrer Position zu verschieben.
Mit ATTSync gehrt das leider nicht da werden die alten Attribute wieder auf die Originalplätze verschoben das will ich aber nicht.
Bitte um Hilfe
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Can not Help
pity
Kann keiner Helfen
Schade
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
After adding the attribute definition to the block definition, you have to add the new attribute refrence to all block refrences in the database (i.e. synchronize only the new attribute).
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for reply
Unfortunately, I have no idea about. Net
I hoped that such a defense program has been.
Thank you
Danke für Antwort
Leider habe ich keine Ahnung von .net
ich habe gehofft das wehr so ein Programm schon hat.
Danke
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try this code, just you have to change block name,
new tag, prompt and default attribute value:
//using Autodesk.AutoCAD.Interop.Common;
//using Autodesk.AutoCAD.Interop;
// Add new attribute and synchronize all blockreferences
[CommandMethod("nea")]
public static void AddNewAtt()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
if (!bt.Has("PART"))
{
ed.WriteMessage("\nBlock definition TEST does not exist");
return;
}
List<AttributeDefinition> attColl = new List<AttributeDefinition>();
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt["PART"], OpenMode.ForRead, false);
foreach (ObjectId adefId in btr)
{
DBObject attObj = (DBObject)tr.GetObject(adefId, OpenMode.ForRead, false);
if (attObj.GetRXClass().Name == "AcDbAttributeDefinition")
{
AttributeDefinition attObjDef = attObj as AttributeDefinition;
if (attObjDef != null)
{
attColl.Add(attObjDef);
}
}
}
AttributeDefinition[] atts = new AttributeDefinition[] { };
atts = attColl.ToArray();
//sort attribute location by X then by Y
Array.Sort(atts, (AttributeDefinition x, AttributeDefinition y) =>
((x.Position.Y.CompareTo(y.Position.Y)) +
(y.Position.X.CompareTo(x.Position.X))));
// get a location of the last AttributeDefinition in the
// block definition
AttributeDefinition lastAtt = atts[0];
Point3d Oldloc = lastAtt.Position;
double attTxtHeight = lastAtt.Height;
ed.WriteMessage("\n{0:f3}", attTxtHeight);
// calculate location of the new AttributeDefinition in the
// block definition
Point3d ptNewloc = new Point3d(Oldloc.X, Oldloc.Y - attTxtHeight * 1.97, 0) + btr.Origin.GetAsVector();
//// create a AttributeDefinition
// specify the text,tag and prompt
string strValue = "[ Enter a new value here ]";
string strTag = "[ Enter a new tag here ]";
string strPrompt = "[ Enter a new prompt here ]";
// used text style of the last attribute definition
AttributeDefinition attDef = new AttributeDefinition(ptNewloc, strValue, strTag, strPrompt, lastAtt.TextStyleId);
attDef.Height = 0.12;
attDef.Layer = "0";
attDef.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Color Method.ByAci, 0);
attDef.LinetypeId = lastAtt.LinetypeId;
attDef.Height = lastAtt.Height;
attDef.TextStyleId = lastAtt.TextStyleId;
attDef.Annotative = lastAtt.Annotative;
attDef.Preset = lastAtt.Preset;
attDef.Invisible = lastAtt.Invisible;
attDef.Constant = lastAtt.Constant;
attDef.Justify = lastAtt.Justify;
attDef.AlignmentPoint = ptNewloc;
attDef.LockPositionInBlock = lastAtt.LockPositionInBlock;
attDef.AdjustAlignment(db);
// append the AttributeDefinition to the definition
btr.UpgradeOpen();
btr.AppendEntity(attDef);
tr.AddNewlyCreatedDBObject(attDef, true);
btr.DowngradeOpen();
tr.Commit();
Autodesk.AutoCAD.Interop.AcadDocument acdoc = (Autodesk.AutoCAD.Interop.AcadDocument)doc.AcadDoc ument;
AcadBlock acBlk = btr.AcadObject as AcadBlock;
acdoc.SendCommand("_.ATTSYNC _N " + acBlk.Name + "\n");
}
}Tested on A2010 only
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for the help only times
Unfortunately it can not start
Get error message
Kann es leider nicht starten
Bekommen Fehlermeldung
Fehler 1 Klasse, Delegat, Enumeration, Schnittstelle oder Struktur erwartet.
Fehler 3 Bezeichner erwartet
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try add namespace
using System.Linq;
Or use your own method to calculate position
of last attribute wthin the block definition
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Will not run for
these are my settings
Thank you
Bekomme das nicht zum laufen
das sind meine einstellungen
Danke
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Interop;
using System.Linq;
Add new attribute and synchronize all blockreferences
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Just a question
What is your Acad version, because I'm using a A2010 only?
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Attribute to move to block without the old ATT
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello
Autocad 2013
Hallo
Autocad 2013


