これはユーザー選択ごとにブロックを選択し、mtextを使用してブロック内の属性を印刷するコードですが、mtextはここで動作しません。前もって感謝します。ブロックの属性がmtext経由で印刷されない
[CommandMethod("NALATT")]
public void ListAttributes()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db =HostApplicationServices.WorkingDatabase;
Transaction tr = db.TransactionManager.StartTransaction();
// Start the transaction
try
{
// Build a filter list so that only
// block references are selected
TypedValue[] filList = new TypedValue[1] {new TypedValue((int)DxfCode.Start, "INSERT")};
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("");
//get the coordinates from user
ppo.Message = "\n Select the place for print output:";
ppr = acDoc.Editor.GetPoint(ppo);
Point3d ptstart = ppr.Value;
ppo.UseBasePoint = true;
ppo.BasePoint = ptstart;
if (ppr.Status == PromptStatus.Cancel) return;
double x = ptstart.X;
double y = ptstart.Y;
double z = 1;
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);
btr.Dispose();
AttributeCollection attCol = blkRef.AttributeCollection;
foreach (ObjectId attId in attCol)
{
//この部分は正常に動作していない
MText mtext = new MText();
//mtext.SetDatabaseDefaults();
mtext.Width = 2;
mtext.Location = new Point3d(x, y = y - 1, z);
AttributeReference attRef =
(AttributeReference)tr.GetObject(attId、OpenMode.ForRead)。
string str =("\n" + attRef.TextString);
mtext.Contents = "\n" + str;
ed.WriteMessage(str);
btr.AppendEntity(mtext);
tr.AddNewlyCreatedDBObject(mtext, true);
}
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(("Exception: " + ex.Message));
}
finally
{
tr.Dispose();
}
}
}
}
投稿をコードすることが可能と閉じたとして は、私はテキストが –
私のDWGファイルに正確に何をして「正常に動作していない」であることを印刷することを試みましたか? 'MText'はクラッシュを引き起こしているのですか、それともエディタに表示されていませんか?あなたが望む助けを得るためには、もっと正確にする必要があります。 –
Mtextが表示されない –