Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hello Everybody,
Right now I am trying to update existing text from Drawing note with another text using following hierarchy. But the text is not getting updated.
Can someone help me on this.
DetailNote
-> DetailTextLines
-> DetailTextLine
-> DetailTexts
-> DetailText
-> SetText("Text")
Try to use
1. pfcDetail.DetailNoteItem.Erase
2. pfcDetail.DetailNoteItem.Modify
3. pfcDetail.DetailNoteItem.Show
Hello @swapnildhengle,
What @YaroslavSin suggested should get you the expected result. Could you please try and confirm how it works for you ?
Try to use
1. pfcDetail.DetailNoteItem.Erase
2. pfcDetail.DetailNoteItem.Modify
3. pfcDetail.DetailNoteItem.Show
Thanks,
Seshu
You have to modify DetailNote object, so the point is to set DetailTextLines. This is working for me:
Drawing drw = (Drawing) session.GetCurrentModel();
DetailItems items = drw.ListDetailItems(DetailType.DETAIL_NOTE, 1);
DetailNoteItem note = (DetailNoteItem) items.get(0);
DetailTextLines lines = note.GetTextLines(DetailTextDisplayOption.DISPMODE_NUMERIC);
DetailTexts texts = DetailTexts.create();
DetailText text = pfcDetail.DetailText_Create("Hello world");
texts.append(text);
lines.get(0).SetTexts(texts);
note.SetTextLines(lines);
Make sure you update the sheet to see changes.
Hi Swapnildhengle,
Did the previous suggestions help ? Please let us know your current status on this Community thread, so we can continue to support.
Thanks,
Seshu
Hi Swapnildhengle,
Could you please confirm if this issue is resolved or still pending ? if still pending we could engage further and work for a solution. Could you please update ?
Thanks,
Seshu
我提供一段批量替换的代码,供你参考
public void test23332(Session session){
try {
Drawing wd = (Drawing) session.GetCurrentModel();
DetailItems items = wd.ListDetailItems(DetailType.DETAIL_NOTE, 1);
for(int i = 0;i<items.getarraysize();i++){
WDetailNoteItem note = (WDetailNoteItem) items.get(i);
DetailNoteInstructions inst = note.GetInstructions(true);
DetailLeaders leaders = inst.GetLeader();
if(null != leaders.GetLeaders()) continue;//排除引用
DetailTextLines ss = inst.GetTextLines();
String strValue = "";
for(int j=0;j<ss.getarraysize();j++){
DetailTexts texts = ss.get(j).GetTexts();
for(int k = 0;k<texts.getarraysize();k++){
String value = texts.get(k).GetText();
strValue += value;
}
strValue += "\n";
}
String strInfo = i+ "\n" + ss.getarraysize() + "\n"
+strValue.trim();
JOptionPane.showMessageDialog(null, strInfo);
strValue = strValue.replaceAll("(?i)&cname", "&CMAT");
// strValue = strValue.replaceAll("&cname", "&CMAT");
// DetailTextLines textLines = PlaceNote.createDetailTextLines(wd,"wjt276\n产品名称: &cname".split("\n"),false,null);
DetailTextLines textLines = PlaceNote.createDetailTextLines(wd,strValue.split("\n"),false,null);
try {
note.SetTextLines(textLines);
} catch (Exception e) {
// JOptionPane.showMessageDialog(null, "出错:" + modelSub.GetFullName());
Wjt276UI.logError(e);
}
if(null != session.GetModelWindow(wd)){
wd.Regenerate();
}
}
wd.Save();
} catch (jxthrowable e) {
e.printStackTrace();
}
}