Is it possible to put WordTextWriters in some kind of a loop? Inventor gives an error about my code now, probably because I'm trying to put Child elements inside of a rule. I'm open to alternative suggestions.(I dont need the rule, but it was the only way to define the counter element) But when it prints it must pint in the order:
stationheader1
assumptiontext1
pagebreak
stationheader2
assumptiontext2
pagebreak
etc...
Rule Evaluation As Number Dim counter As Integer = 0 While counter < NumberOfStations counter = counter+1 Child PageBreak1 As :WordBreakWriter, Quantity = 1 Bookmark = "StationHeader" Placement = :After BreakType = :Page End Child Child AssumptionText As :WordTextWriter, Quantity = 1 Bookmark = "StationHeader" Placement = :After Text = nth(counter,Root.TKSE_System_1.StationAssumptionsList) End Child Child MachineHeader As :WordTextWriter, Quantity = 1 Bookmark = "StationHeader" Placement = :After style = "Heading 2" Text = nth(counter,Root.TKSE_System_1.BOMHeaderData) End Child End While End Rule
The only relevant part of my template is that I have a bookmark called "StationHeader".
Solved! Go to Solution.
Solved by csuffell. Go to Solution.
You may want to try using the MakePart function.
So make the rule Evaluation return a List (of parts) (So we can set the Children correctly)
In the loop, replace the Child.....End Child with a MakePart, eg
Rule Evaluation As List
Dim counter As Integer = 0
While counter < NumberOfStations
counter = counter+1
dim p1 as part = MakePart({:Design, :WordBreakWriter,:Bookmark,"StationHeader",:Placement,:After,BreakType,:Page})
dim p2 as part = MaklePart...................
Return {P1,P2,................}
end rule
Then 'con' the Child list...
Rule Children as list = Children() + Evaluation
Depending on how you want the Loop to opperate you may need to aggregate up the lists of part so that Evaluation returns the right thing.
I'm guiessiong here, so I might have missed something 🙂
Thank you, this seems like it should work, but whenever I try to save it, it says unhandled exception occurred. It claims I'm attempting to write to protected memory.
The problem is with the very last line. If I comment it out, the code saves, but of course, nothing is put into the Word document. (for the moment I'm leaving out the page break part because that also has some issue)
Do you have any ideas where I may have gone wrong?
My updated code is below.
Rule Evaluation As List Dim counter As Integer = 0 While counter < NumberOfStations counter = counter+1 Dim p2 As Part = MakePart({:Design, :WordTextWriter,:Bookmark,"StationHeader",:Placement,:After,Text = nth(counter,Root.TKSE_System_1.StationAssumptionsList)}) Dim p3 As Part = MakePart({:Design, :WordTextWriter,:Bookmark,"StationHeader",:Placement,:After,style = "Heading 2",Text = nth(counter,Root.TKSE_System_1.BOMHeaderData)}) End While Return {p2,p3} End Rule Rule Children As List = Children() + Evaluation
Evaluation needs to be a flat list of all the parts that you have made, so you need to collect the parts up within the while. Something like:
Rule Evaluation As List
Dim counter As Integer = 0
dim kids as list {}
While counter < NumberOfStations
counter = counter+1
Dim p2 As Part = MakePart({esign, :WordTextWriter,:Bookmark,"StationHeader",lacement,:After,Text = nth(counter,Root.TKSE_System_1.StationAssumptionsList)})
Dim p3 As Part = MakePart({esign, :WordTextWriter,:Bookmark,"StationHeader",lacement,:After,style = "Heading 2",Text = nth(counter,Root.TKSE_System_1.BOMHeaderData)})
kids = kids + {p2,p3}
End While
'Return {p2,p3}
Return kids
End Rule
Rule Children As List = Children() + Evaluation
I have it so it properly stores the parts in the list, but how do I make it actually output them to the word document? Right now, it doesn't add anything to the bookmark like I thought it would.
I took out this line because all it was doing was making a duplicate list of parts.
Rule Children As List = Children() + Evaluation
My new code:
Rule Evaluation As List Dim counter As Integer = 0 Dim kids As List = {} While counter < NumberofStations counter = counter+1 Dim p1 As Part = MakePart({:Design, :WordBreakWriter,:Bookmark,"StationHeader1",:Placement,:After,:BreakType,:Page}) Dim p2 As Part = MakePart({:Design, :WordTextWriter,:Bookmark,"StationHeader1",:Placement,:After,:Text,nth(counter,Root.TKSE_System_1.StationAssumptionsList)}) Dim p3 As Part = MakePart({:Design, :WordTextWriter,:Bookmark,"StationHeader1",:Placement,:After,:Text,nth(counter,Root.TKSE_System_1.BOMHeaderData)}) kids = kids + {p1,p2,p3} End While Return kids End Rule
I have attached a 'hacked version' of a very old demo (I think it was done originally in a 2009 beta for Intent-inventor) It sort of illustrates what I was trying to get at. You can play games with the naming of the children (from makepart) to make it look better in the assemly tree (if you want). The key here is that the 'Children' list in the quotation are built from the makeparts (up to you how you actually form that list) but so long as that part(has WordDoc mixed in) has a list of children that contain the 'writer' parts you should get a populated word doc (when you demand the report)
Hope this helps
That made it work perfect. Thank you. I only had to change one line from what I had before.