[api-dev] How to remove a shape from a Draw Page

2007-04-03 Thread Andrew Douglas Pitonyak

Michael,

This is a very interesting question and I spent an hour or so and was 
not able to solve the problem.


I am copying the dev mailing list to see if there are any clues there:

The problem:

Assume a draw document with a single shape selected.
I want to delete the single shape.
The code shown below obtains a reference to the selected shape from the 
current controller (because it is selected).


So, if I have a reference to a shape that is inserted into a draw page, 
how can I delete it?

I tried oShape.Dispose(), which crashed OOo.
I tried oShape.getParent().Remove(oShape), which crashed OOo.


Original code:

Sub Main

   Dim oShapeName as String
   Dim oDoc As Object

   oDoc = ThisComponent

   oDocCtrl = oDoc.getCurrentController()

   ' See what is currently selected.
   oSelection = oDocCtrl.getSelection()
   If IsEmpty( oSelection ) Then
   MsgBox( "Zum Löschen muss eine Grafik makiert sein" )
   Exit Sub
   EndIf
   If oSelection.getCount() > 1 Then
   MsgBox( "Bitte nur eine Grafik zum löschen auswählen" )
   Exit Sub
   EndIf

   oOrigShape = oSelection.getByIndex( 0 )
   oShapeName = oOrigShape.getName()

   print oShapeName

  REM The Delete Function doesn't work
  'oDoc.Remove(oOrigShape)

End Sub



Nice to hear from you again

I am overly busy (nothing new there), but I will take a quick look.

Michael Simader wrote:

Hi Andrew!

How are you? Hope you are find.
I think you know me, because you helped me with my macro for inserting 
a costum shape. It is working great and i updated the macro with a 
database and i am so proud of it. But now to the problem: If i insert 
a graphic in the draw document i make a entry in my database, but the 
problem is, if i delete a shape, i cant remove the database row. So i 
wrote a macro, where i can select a single shape and get the name of 
the shape (for deleting the database row), but the problem is, i can't 
remove the shape from the document. Do you know the methode for 
removing graphics?
Remove a graphic from a Draw document. Did you know that I cover this in 
my published book? Did you know that the Draw and Impress chapter are 
available as a free download from the publisher?

here is the macro which i want to use for deleting:

Sub Main

Dim oShapeName as String
Dim oDoc As Object

oDoc = ThisComponent

oDocCtrl = oDoc.getCurrentController()

' See what is currently selected.
oSelection = oDocCtrl.getSelection()
If IsEmpty( oSelection ) Then
MsgBox( "Zum Löschen muss eine Grafik makiert sein" )
Exit Sub
EndIf
If oSelection.getCount() > 1 Then
MsgBox( "Bitte nur eine Grafik zum löschen auswählen" )
Exit Sub
EndIf

oOrigShape = oSelection.getByIndex( 0 )
oShapeName = oOrigShape.getName()

print oShapeName

   REM The Delete Function doesn't work
   oDoc.Remove(oOrigShape)

End Sub

Yeah, I do not expect you to be able to remove a shape this way.


best regards!
Your Michael

_
Sie möchten Teil der Evolution der Kommunikation werden? 
http://www.communicationevolved.com/de-at/




--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] How to remove a shape from a Draw Page

2007-04-03 Thread David Coulette
if i remember well you have to get a reference to the Page and call its
remove method.

ThePage.remove(TheShape)

be sure to test the presence of shape, or ooo will crash.
> 






___ 
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son 
interface révolutionnaire.
http://fr.mail.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] How to remove a shape from a Draw Page

2007-04-04 Thread Frank Schönheit - Sun Microsystems Germa ny
Hi Andrew,

not having an answer to your question, but ...

> Assume a draw document with a single shape selected.
> I want to delete the single shape.
> The code shown below obtains a reference to the selected shape from the 
> current controller (because it is selected).
> 
> So, if I have a reference to a shape that is inserted into a draw page, 
> how can I delete it?
> I tried oShape.Dispose(), which crashed OOo.
> I tried oShape.getParent().Remove(oShape), which crashed OOo.

... for both of the crashes I would like to see issues in IssueZilla, if
possible :)

Ciao
Frank

-- 
- Frank Schönheit, Software Engineer [EMAIL PROTECTED] -
- Sun Microsystems  http://www.sun.com/staroffice -
- OpenOffice.org Base   http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] How to remove a shape from a Draw Page

2007-04-04 Thread Andrew Douglas Pitonyak

Frank Schönheit - Sun Microsystems Germany wrote:

Hi Andrew,

not having an answer to your question, but ...

  

Assume a draw document with a single shape selected.
I want to delete the single shape.
The code shown below obtains a reference to the selected shape from the 
current controller (because it is selected).


So, if I have a reference to a shape that is inserted into a draw page, 
how can I delete it?

I tried oShape.Dispose(), which crashed OOo.
I tried oShape.getParent().Remove(oShape), which crashed OOo.



... for both of the crashes I would like to see issues in IssueZilla, if
possible :)

Ciao
Frank
  

No Problem. I will enter an issue for both.

http://www.openoffice.org/issues/show_bug.cgi?id=76084

I will also assume that this is how I should remove a graphic.

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] How to remove a shape from a Draw Page

2007-04-04 Thread Frank Schönheit - Sun Microsystems Germa ny
Hi Andrew,

> No Problem. I will enter an issue for both.
> 
> http://www.openoffice.org/issues/show_bug.cgi?id=76084

Thanks.

> I will also assume that this is how I should remove a graphic.

I'd say "yes" ...

Ciao
Frank

-- 
- Frank Schönheit, Software Engineer [EMAIL PROTECTED] -
- Sun Microsystems  http://www.sun.com/staroffice -
- OpenOffice.org Base   http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]