Skip to main content
1-Visitor
October 28, 2021
Question

Need help to Update Text in Drawing Note using DetailText settext

  • October 28, 2021
  • 4 replies
  • 3050 views

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")

 

4 replies

17-Peridot
November 1, 2021

Try to use

1. pfcDetail.DetailNoteItem.Erase
2. pfcDetail.DetailNoteItem.Modify

3. pfcDetail.DetailNoteItem.Show

18-Opal
November 26, 2021

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

15-Moonstone
December 2, 2021

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.

18-Opal
December 22, 2021

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

18-Opal
January 3, 2022

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

4-Participant
January 27, 2022

我提供一段批量替换的代码,供你参考

 

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();
}
}