OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to know if a graphic is in a table?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
roland65
General User
General User


Joined: 13 Dec 2007
Posts: 22

PostPosted: Wed May 23, 2012 4:38 am    Post subject: How to know if a graphic is in a table? Reply with quote

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
View user's profile Send private message
lknoll
General User
General User


Joined: 19 Oct 2011
Posts: 32
Location: Harrisburg, Pa

PostPosted: Thu May 24, 2012 5:44 am    Post subject: Reply with quote

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
View user's profile Send private message
roland65
General User
General User


Joined: 13 Dec 2007
Posts: 22

PostPosted: Thu May 24, 2012 8:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group