| View previous topic :: View next topic |
| Author |
Message |
roland65 General User

Joined: 13 Dec 2007 Posts: 22
|
Posted: Wed May 23, 2012 4:38 am Post subject: How to know if a graphic is in a table? |
|
|
Hi,
I've digged into this forum but couldn't find the answer to this simple question : how can I know if a graphic (image, drawing) is within a text table.
The solutions I found in this forum classically test if the view cursor contains a TextTable attribute, but this does'nt work with graphics because there is no view cursor associated with it.
I could of course deselect the graphic and test if the view cursor is in a table, but then I have to select again the graphic to work on it and it seems tricky...
Any help would be greatly appreciated,
RB |
|
| Back to top |
|
 |
lknoll General User

Joined: 19 Oct 2011 Posts: 32 Location: Harrisburg, Pa
|
Posted: Thu May 24, 2012 5:44 am Post subject: |
|
|
Would this work? I modified some existing code I had. I loop through all the TextFrame elements, then access the current frame with the view cursor. From here I check the Anchor to see if it is in a TextTable.
| Code: | sub test
oDoc = ThisComponent
oTextFrames = oDoc.TextFrames
oVC = oDoc.CurrentController.getViewCursor()
TextFrameNameArr = oTextFrames.ElementNames
For index = ubound(TextFrameNameArr) to 0 step -1
oFrame = oTextFrames.getByName(TextFrameNameArr(index))
oVC.goToRange(oFrame, false)
if TypeName(oVC.TextFrame.Anchor.TextTable) <> "Empty" then
msgbox "I am in a table"
end if
Next index
end sub
|
|
|
| Back to top |
|
 |
roland65 General User

Joined: 13 Dec 2007 Posts: 22
|
Posted: Thu May 24, 2012 8:35 am Post subject: |
|
|
Hi,
thanks for your answer.
I tested it but it seems it doesn't work : if I select a graphic object within a table, excuting your code does nothing. Seems that there is only one iteration and then it outputs...
However, I finally found a way to test if the selected graphic is in a table or frame. Here is the code :
Sub SelectedGraphicInATable
oDocCtrl = ThisComponent.getCurrentController()
' Get selected image anchor
oSelection = oDocCtrl.selection()
oAnchor = oSelection.getAnchor()
' We are in a table
If oAnchor.Text.ImplementationName = "SwXCell" Then
Print "Graphic is in a table"
' We are not
Else
Print "Graphic is NOT in a table"
End If
End Sub
It can also work to test if the selected graphic is in a frame (replace "SwXCell" with "SwTextFrame") or in a text paragraph (replace "SwXCell" with "SwXbodyText").
However, it does not work if the graphic object is anchored to page...
Cheers,
RB |
|
| Back to top |
|
 |
|