DITA and XMetaL Discussion
XMetaL Community Forum › DITA and XMetaL Discussion › Multiple Entry Tags Add Text
Tagged: How to interpret pareto chart
-
Boyd White March 11, 2019 at 9:47 pm
Multiple Entry Tags Add Text
March 11, 2019 at 9:47 pmParticipants 3Replies 4Last Activity 4 years agoI have been R&D'ing how to select multiple entry tags in a column then add a &tab; at the front of the content of each of those entry tags.
This has proved more difficult that I would have thought. How do you, in a macro, loop through the multiple Entry Tags selected and add text?
Thanks in advance!
Boyd White March 13, 2019 at 1:11 pm
Reply to: Multiple Entry Tags Add Text
March 13, 2019 at 1:11 pmThis will show me every entry's content in a column:
Set ttable = ActiveDocument.documentElement
Set tgrouplist = ttable.getelementsbytagname(“tgroup”)
Set tbodylist=tgrouplist.item(0).getelementsbytagname(“tbody”)
Set tentrylist=tbodylist.item(0).getelementsbytagname(“entry”)For j = 0 To tentrylist.length-1
selection.SelectNodeContents(tentrylist(j))
contents=selection.text
msgbox(“contents = ” + contents)
NextBut I don't need every entry's value…I need only those entry tags that have been selected in the column. I have to add a &tab; at the front of their content.
Anybody have some clues. This has turned out to be harder that I would have expected. In R&Ding I have not even been able to get the Range Start and Range End to maybe exclude those outside during the loop of “j” above.
Thanks in advance.
Derek Read March 14, 2019 at 9:10 pm
Reply to: Multiple Entry Tags Add Text
March 14, 2019 at 9:10 pmBecause users interact with tables in a unique way when compared to standard elements in a document (what the user is seeing doesn't line up 1:1 with the XML so things get complicated) you need to use special (new and as yet undocumented) APIs to get a user's selection when it might consist of selected cells in a table.
Here's something that does what I think your example code is trying to do.
You can paste these into a document to see them run:[code=VBScript]'XMetaL Script Language VBScript:
If Selection.IsMultiCellSelection Then
Set c = Selection.Cells
For j = 0 to c.length
Selection.SelectNodeContents(c(j))
Application.Alert(“content: ” & Selection.Text)
Next
End If[/code][code=JScript]//XMetaL Script Language JScript:
if(Selection.IsMultiCellSelection) {
var c = Selection.Cells;
for(j=0; jSelection.SelectNodeContents(c(j));
Application.Alert(“content: ” + Selection.Text);
}
}[/code]Boyd White March 27, 2019 at 10:25 pm
Reply to: Multiple Entry Tags Add Text
March 27, 2019 at 10:25 pmI have to admit…I am using the ancient Xmetal 2.1
I tried your recommendation Derek and I imagine it would work on newer versions; but not on 2.1
Your recommendation gave me some ideas gave me some ideas but none of them panned out…I just was not able to get the Start and Stop range or cell/entry count of what I selected in a Table Column.
I was able to create a workaround with a couple Input Boxes from the user for anyone interested:Dim iRows
Dim iIndent
Dim iCountRows
Dim strTabs
Dim iiRows = cint(inputbox(“How Many Cells Downward From The Current Cell Do You Want To Indent: “, “Data Input”))
iIndent = cint(inputbox(“How Many &tab; Entities To Apply In Each Cell: “, “Data Input”))
strTabs = “”
For i = 1 To iIndent
strTabs = strTabs & “&tab;”
NextFor iCountRows = 1 To iRows
Selection.TypeText(strTabs)
Selection.SelectContainerContents
Selection.MoveLeft
Selection.MoveDown
NextDerek Read March 28, 2019 at 10:36 pm
Reply to: Multiple Entry Tags Add Text
March 28, 2019 at 10:36 pmYes, the APIs Selection.IsMultiCellSelection and Selection.Cells do not exist in versions older than 13.
You are correct in coming to the conclusion that being able to get the information your script needed was impossible. The information is just not there (without these new APIs). So, prompting the user is as good as it is going to get.
-
AuthorPosts
- You must be logged in to reply to this topic.