Das ist mein Programm, in der i-Attribut im dwg file
drucken kann, aber das Problem ist, dass mtext
Druck des Wert wie: Projekt: 534Phase: 1ZONE: A (0530) Projekt: 534Phase : 1Zone: A (0520) und so weiter, aber ich möchte Ausgabe wie Projekt: 534 Phase: 1 Zone: A (0530) (0520).Erstellen Sie zwei verschiedene mtext in einem einzigen Programm
[CommandMethod("ATT")]
public void ListAttributes()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = acDoc.Editor;
Database db = acDoc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Start the transaction
try
{
// Build a filter list so that only
// block references with attributes are selected
TypedValue[] filList = new TypedValue[2] { new TypedValue((int)DxfCode.Start, "INSERT"), new TypedValue((int)DxfCode.HasSubentities, 1) };
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionOptions opts = new PromptSelectionOptions();
opts.MessageForAdding = "Select block references: ";
PromptSelectionResult res = ed.GetSelection(opts, filter);
// Do nothing if selection is unsuccessful
if (res.Status != PromptStatus.OK)
return;
SelectionSet selSet = res.Value;
ObjectId[] idArray = selSet.GetObjectIds();
PromptPointResult ppr;
PromptPointOptions ppo = new PromptPointOptions("");
ppo.Message = "\n Select the place for print output:";
//get the coordinates from user
ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
return;
Point3d startPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
Vector3d disp = new Vector3d(0.0, -2.0 * db.Textsize, 0.0);
HashSet<string> attValues = new HashSet<string>();
foreach (ObjectId blkId in idArray)
{
BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite);
//ed.WriteMessage("\nBlock: " + btr.Name);
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
AttributeCollection attCol = blkRef.AttributeCollection;
foreach (ObjectId attId in attCol)
{
AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);
string str = (attRef.TextString);
//ed.WriteMessage("\n" + str);
if (attValues.Contains(str))
continue;
if (btr.Name == "NAL-SCRTAG")
{
MText mtext = new MText();
mtext.Location = startPoint;
string file = acDoc.Name;
string str1 = Path.GetFileNameWithoutExtension(file);
Match match = Regex.Match(str1, @"^(\w+-[CSDWM]\d+[A-Z]-.)$");
var split = str1.Split('-');
string code = split.First();
string phase = new string(split.ElementAt(1).Skip(1).Take(1).ToArray());
string zone = new string(split.ElementAt(1).Skip(2).Take(1).ToArray());
mtext.Contents = ("Project:" + code + "Phase:" + phase + "Zone:" + zone + "(" + str + ")");
//ed.WriteMessage(text);
curSpace.AppendEntity(mtext);
tr.AddNewlyCreatedDBObject(mtext, true);
db.TransactionManager.QueueForGraphicsFlush();
attValues.Add(str);
startPoint += disp;
}
}
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(("Exception: " + ex.Message));
}
}
}