Donnerstag, 26. Juli 2012 15:52
Hi, I am using Visual Studio 2008 targeting Office 2007, our company standards. I am trying to do this with c# as an application addin to Word. I can make addins and do all of the ribbon, dialog and insert/edit text stuff, it's the more complicated stuff I need ideas for.
What we are trying to do is: our clients make their sequential procedures now as manual procedures using word and we are adding computer based procedures (CBP) to their control systems. The current procedures are steps like check the light for this channel is off and there is no annunciation for the channel. We can easily do this with our CBP by feeding the system an xml file with the proper steps and logic.
The idea is that the people who currently make these procedures do it in Word and we want to make Word also create the CBP files while also creating the manual procedure file as documentation, a way to manually do the procedure if they want to and as a way to follow along with the control system as the CBP is run.
The trick is how do I get this info into a word document while still leaving the document to look like the versions they have now but also contain the information required to create the xml file for the control system to use. I am thinking that i can add our own custom xml file to the docx but linking the various entries in that file to the entries in the word document.xml file upon creation, while editing, when saving and when reloading the docx from disk in subsequent sessions.
So the doc file would have a heading like this:
3.1.1 If Channel D tripped Stop (cannot continue if channel D tripped)
Check that there is no annunciation for channel D tripped and the channel D trip indicator light is off. 
The XML for this is sort of (Still in progress of defining the xml and dtd.)
<Step name="If Channel D tripped Stop" comment="cannot continue if channel D tripped" id="3.1.1">
These steps and actions are not the only thing in the document, there are 2 sections of introduction, signoff and warnings above the procedure and figure tables and certification below the procedure so just using every heading and making it a step are not going to work.
Making a set of ribbon buttons for the user add the various objects (a step, condition, the expressions within those etc.) and the methods for inserting them into the document and then placing the corresponding xml code into a tree structure are not the problem. Determining that the user has changed something like selecting a step and deleting it or editing the text, inserting other headings and paragraphs thus changing IDs and the like are what I am looking for. I can't assume anything about the user beyond that they can use word and will follow a procedure for making these documents. They won't know xml so automated creation, editing and maintenance of the xml based on the doc text is required.
Also we have a lot of legacy procedures we want to convert into the new cbp format and being able to select text and click a button to make the corresponding xml construct is also desired.
I would like to know if anyone has done anything like this before, do people think it can even be done and be maintainable both in the document and the application/addin.
Freitag, 27. Juli 2012 07:04Moderator
Thanks for posting in the MSDN Forum.
I will involve some experts into your issue to see whether they can help you out. There might be some time delay, appreciate for you patience.
Have a good day,
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
Freitag, 27. Juli 2012 07:59Moderator
<<The trick is how do I get this info into a word document while still leaving the document to look like the versions they have now but also contain the information required to create the xml file for the control system to use. >>
From what I can tell from your description, I'd say use Content Controls on the document surface. Link them to a Custom XML Part inside the document. One reservation: this can only be done if the content control is "plain text" (cannot contain individual character formatting). From the example you give, I wouldn't expect this to be an issue?
<<Determining that the user has changed something like selecting a step and deleting it or editing the text, inserting other headings and paragraphs thus changing IDs and the like are what I am looking for. >>
A content control, especially one linked to a CXP, gives you a number of events. There are events for entering/leaving content controls; for changing the data as it updates in the CXP; for deletion.
More difficult could be inserting headings and paragraphs, as there are no events you can use directly for that kind of thing. However, if each heading + description is, as in your sample, a single paragraph, then you can get fairly good control. Plain text content controls can be set to not allow insertion of new paragraphs; and these controls can be embedded into a rich text content control that does not allow editing (meaning the user can only work in the plain text fields). In this way, you should be able to block the user being able to create new paragraphs without a little "help" from your program.
So, the user can have a button to click to insert a new section above/below a selected one. Your program temporarily removes the edting restriction, creates the control with a link to the CXP and does whatever other house-keeping required and reinstates the editing restriction.
Cindy Meister, VSTO/Word MVP
Freitag, 27. Juli 2012 15:15
This is all experimental at the moment so I'm still trying to find out what restrictions I can put on the document authors. There will have to be some no matter what we do. And then there are the legacy procedures to deal with.
Content controls are interesting and i was looking at them but I'm not sure if it will handle the nesting. My example was a simple check and stop step. The design of the sequential control is a bit more complicated. Steps can be a Step, A Node or an IfNode. Node and IfNode can have child steps as well as conditions and expressions, where Step can only have Conditions and Expressions.
(If is If False or not, so a node does the action if true, IfNode does the action if false.)
What happens to children of a object if someone deletes the control. I would have to detect that and ask the user i guess.
So someone adds a node. Then adds a condition I would have to detect the parent in the document then add the child. Or they would have to select the parent and add the child to it.
reordering would also be interesting. Drag and drop reordering of the controls is possible I guess.
Can I extend Plain text content control?
And then there are the things that are just different because one is in manual mode and the other is a computer. Where the manual instructions will say write down the value and the computer will either store it to a variable for later use or send to annunciation and logging. I guess both will be put into the document now with one being a comment for the computer and the other a comment for the human.
You will note that I work in a Nuclear laboratory. We do research into all civilian things that nuclear touches from smoke detectors to nuclear medicine. Our lab makes 40% of the worlds supply of medical isotopes. The group i am in does control systems research, I do tools and this is my current "research" although I am going to need to have something working by end of March. As a parallel to all of my tools development i also build tools to verify the outputs before putting them onto a production control system. With this one I am making the verification tool also able to generate the required xml by more standard means just in case, but I will at some point make something work from within Word in one way or another.
Samstag, 28. Juli 2012 13:16Moderator
The thing about using Word is that it was designed as a word processor and remains a word processor. You can make it jump through flaming hoops, but getting absolute control of what Word does in all situations is not possible; getting close involves you jumping through flaming hoops. Just so we're clear :-)
Over a decade ago, I wrote a book on working with Word as a document professional together with someone who had worked in an area similar to what you describe. A lot of the necessary mind-set (getting it right the first time and everytime) flowed into his discussions in that book...
<<Content controls are interesting and i was looking at them but I'm not sure if it will handle the nesting. >>
In and of themselves, content controls can handle nesting. The only "iffy" part would be if the project design would require linking the "parent" (containing) content control(s) to the XML part. From what I understand, it appears that wouldn't be the case.
A content control has a Parent property that will let you access the next outer level directly.
<<reordering would also be interesting. Drag and drop reordering of the controls is possible I guess.>>
Not in the design scenario I described, no. But there's no reason you couldn't put a "tree view" of the current point in a task pane next to the text (make it context sensitive, even). The user could do the re-ordering in that and your code take care of removing protection, moving the controls on the document surface, doing any background maintenance (re-numbering in the XML), and re-instate protection.
<<Can I extend Plain text content control?>>
Not in the way I think you mean the question. All Office object model classes are sealed - can't be extended.
My gut feeling is that Word may not be the best tool for the task. I suspect you might be better off in InfoPath, with an option to print the information out to Word if you need it in that form.
Cindy Meister, VSTO/Word MVP
- Als Antwort markiert Tom_Xu_WXModerator Mittwoch, 1. August 2012 01:59
Dienstag, 31. Juli 2012 15:20
I should check back here more often.
Thank you Cindy your insight is very helpful. I fully expect to be the one doing the hoop jumping, as I put in the title, using word for things it was not intended.
While this project may not be a good fit I am learning things about word I never expected to and may be able to use in other efforts. I will take your insight and combine with what i have learned trying to prototype some of this and see what I come up with.
Can I ask what the book was and for the ISBN? I know that this is not the place for you to promote yourself but I am asking so it should be OK. :-)