Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
I am trying to add a text file of notes to a drawing using JLink. I have tried using code shown by PTC Located here: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS206301&lang=en&source=snippet
but when I change the string to a line read it fails. Here is the code I am using:
DetailNoteItem note = null;
DetailTextLines allLines = DetailTextLines.create();
int number=0;
while(lineRead!=null) // example shows for 3 lines. However, this could be the actual number of lines present in your input text file on disk
{
String iLineText = "Test " + number; This works but if I change number to lineRead it fails.
DetailTexts iDetailTexts = DetailTexts.create();
iDetailTexts.insert(0, pfcDetail.DetailText_Create(iLineText));
allLines.insert(number, pfcDetail.DetailTextLine_Create(iDetailTexts));
lineRead = textList.readLine();
number++;
}
textList.close();
// Allocate a note description, and set its properties
DetailNoteInstructions instrs = pfcDetail.DetailNoteInstructions_Create(allLines);
instrs.SetLeader(allAttachments);
// Create the note
note = (DetailNoteItem) drawing.CreateDetailItem(instrs);
note.Show();
Where is the code that is opening and reading the text file?
What is lineRead?
What is the error message?
String textFile = "C:\\data\\Standards\\std-notes\\test.txt";
BufferedReader textList = new BufferedReader(new FileReader(textFile));
String lineRead = textList.readLine();
No error message.
I would prefer to just add the note from file but I am not sure how to do that and have not found any code to show how to do that either.
@ssuttle wrote:
String textFile = "C:\\data\\Standards\\std-notes\\test.txt";
BufferedReader textList = new BufferedReader(new FileReader(textFile));
String lineRead = textList.readLine();
No error message.
Ok then what line of code is it failing at?
String iLineText = "Test " + number; If I change this to the value from lineRead it fails.
After more testing it looks like it loops thru the lineRead fine and that allLines array size grows but it just never puts the note into the drawing.
And after more testing it looks like it is dying because the length of the line when I read a line from my file is to long. When I go into my file and shorten the lines it works.
@ssuttle wrote:
After more testing it looks like it loops thru the lineRead fine and that allLines array size grows but it just never puts the note into the drawing.
I just tried your code and it works for me. However I commented out the
instrs.SetLeader(allAttachments);
Because I don't know what "allAttachments" is. The note is put in at drawing coordinates 0,0 after commenting out this line.
Randy,
This allows you to locate the position of the text you are placing on the drawing.
Here is the rest of my code. This code I found on the web that PTC provided some where which I cannot find again:
Point3D drawing_loc = Point3D.create();
drawing_loc.set(0, 1.3);
drawing_loc.set(1, 19.60);
drawing_loc.set(2, 0);
// convert the input points from Drawing units to Screen Coordinates
int currentSheetNumber = drawing.GetCurrentSheetNumber();
Transform3D sheetTransform = drawing.GetSheetTransform(currentSheetNumber);
sheetTransform.Invert();
Point3D screen_Loc = sheetTransform.TransformPoint(drawing_loc);
DetailLeaders allAttachments = pfcDetail.DetailLeaders_Create();
FreeAttachment freePosition = pfcDetail.FreeAttachment_Create(screen_Loc);
// Set the attachment structure
allAttachments.SetItemAttachment(freePosition);
So more testing and it looks like the total line length cannot be more than 80 characters.
@ssuttle wrote:
So more testing and it looks like the total line length cannot be more than 80 characters.
Another one of those undocumented jlink string length limits...
One of these that bit me was the Session.UIReadStringMessage()
Notice there is no mention of the 80 character limit from the java docs:
UIReadStringMessage |
---|
/*optional*/ String | UIReadStringMessage | ( /*optional*/ Boolean HideInput) |
This method is enabled for Creo Direct. Reads a line of keyboard input and returns the contents as a wide string.Leading and trailing blanks are stripped from the string. Default values are displayed in the text box as input. Note that this value will not be returned if the user hits a carriage return; instead, the function will return constant string "use_default_string" and the application must interpret that the user intends to use the default.
Exceptions thrown (but not limited to): XToolkitMsgUserQuit - The user canceled input by typing <ESC>.
|
Now the trick is how to get around it. I have not found a way other than mapkey that will allow you to create note from file. If that was possible that would work but I see nothing like that in the documentation or online any where.
@ssuttle wrote:
Now the trick is how to get around it. I have not found a way other than mapkey that will allow you to create note from file. If that was possible that would work but I see nothing like that in the documentation or online any where.
You can create a macro with jlink and then run the macro from jlink. I have done that many times using session.runMacro(). This actually works good. Sometimes the macro has to be redone for a Creo Parametric update. You can get the macro string needed by recording and saving a macro or also by looking in the trail file.