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

Removing a module in the actual document

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


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Wed Jun 14, 2006 12:08 am    Post subject: Removing a module in the actual document Reply with quote

Hello,

in order to remove a module in the actual document I use the following code:
Code:
sub DeleteDocModule (sLibrary as string, sModule as string)
dim oDocLib as object

   oDocLib = ThisComponent.LibraryContainer.getByName(sLibrary).getModuleContainer()
   if oDocLib.HasByName( sModule ) then
      oDocLib.removeByName( sModule )
   end if   
end sub

All seems to be ok, the module that has to be deleted is found and the "removeByName" is executed. Unfortunately the module isn't removed at all.

Regards
Harry
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Wed Jun 14, 2006 4:09 pm    Post subject: Reply with quote

If I remember correctly, the IDE-view won't be updated. You can call routines of the deleted module?
Call the caller of sub DeleteDocModule (params) without IDE. Then start the IDE and you should not find the module.
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Jun 14, 2006 5:54 pm    Post subject: Reply with quote

Your call removes the module from disk. What happens if you close the IDE and then open the IDE again? It should show that the module is gone.

I demonstrate an advanced technique where I am actively adding and removing modules in my AndrewBase document on my web site (if you wanted to see an example). If you want to see it, read the section titled "Dynamically call object methods". I create library modules and then call routines that I create. I use this to inspect objects by calling methods.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Thu Jun 15, 2006 4:33 pm    Post subject: Reply with quote

Thank you for your help, but the problem still exists. The deleted module can not be found after it has been removed, but even if I close all OOo application windows and reopen the Writer-file or restart the computer, again the deleted module appears. I can not call a routine in this document because the code is running from outside the document in "My macros & dialogs".

What I want to achieve, more precisely said, is to remove a module named "Main" in the "Standard" lib of an opened 1.1.4 sxw-file, that has a button to start an export process. This button and its macro is not needed anymore because the export in the upcoming version is invoked via an Addon-Menu. In order to "upgrade" existing documents to the new version, the button and the module that have become obsolete should be deleted. As a positive effect the file can then be opened without macro-warning.

Regards
Harry
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Thu Jun 15, 2006 5:57 pm    Post subject: Reply with quote

That changes things a bit. I would need to check my book, but I think that you can NOT manipulate a library or module in a document that is not current (meaning it is not the same as "ThisComponent").
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Fri Jun 16, 2006 5:22 am    Post subject: Reply with quote

As far as I know, it is not possible to call a routine that is placed in a document from within a GlobalScope-Library, even if the called routine is placed the actual document (ThisComponent).

Just if I did not explain it well: It IS a module of the active document (ThisComponent) that should be deleted. The calling routine however is placed in a GlobalScope lib. It would be nice, Andrew, if you could take a look at your documents. I will also try to find a solution in the meantime.

Regards
Harry
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Jun 16, 2006 11:07 am    Post subject: Reply with quote

harrybo wrote:
As far as I know, it is not possible to call a routine that is placed in a document from within a GlobalScope-Library, even if the called routine is placed the actual document (ThisComponent).


This is wrong. I added a new section to my free macro document that demonstrates EXACTLY how to do this. A technique that is not even in the German translation of my book...

[/quote]It IS a module of the active document (ThisComponent) that should be deleted. The calling routine however is placed in a GlobalScope lib. It would be nice, Andrew, if you could take a look at your documents. I will also try to find a solution in the meantime.
/quote]

I tried some code such as that shown below, but the empty module was still there...

Code:
  Dim oLibs
  Dim oLib
  Dim oModules
  oLibs = ThisComponent.getLibraryContainer()
  oModules = oLibs.getByName("Standard").getModuleContainer()
  oModules.removeByName("Module1")
  oLibs.removeByname("Standard")

_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Fri Jun 16, 2006 11:13 am    Post subject: Reply with quote

pitonyak wrote:

Code:
  oLibs.removeByname("Standard")

I believe "Standard" is unremovable. At least in the GUI.
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Fri Jun 16, 2006 2:54 pm    Post subject: Reply with quote

Since the Standard lib is not responsable for the macro-warning, I would be happy enough to realize the removing of just a module (I called it "Main"). There might also be other user defined modules that I do not want to touch. But in case this is the only module, the document will be free of macro code when I get the removing of the module to work.

So when I check the macros with the macro organizer after having removed a module this way, the module is still existant, but there are no more routines listed in that module. Closing and reopening the document however will reanimate the module and all its routines.

I will now try to find a way to make the changes permanent. As a workaround one could internally open a new document, transfering the complete document into that new one (except the macros ;-), closing the actual doc and overwrite it with the new document ... hm.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Fri Jun 16, 2006 3:19 pm    Post subject: Reply with quote

Code:
sub rmMod
thisComponent.BasicLibraries.removeLibrary("testLib")
thisComponent.setModified(true)
End Sub

Removing the testLib, removes all modules of testLib rather than the library itself.
Additionally this won't change the modified state of the document, so you can close it without beeing prompted for saving.
The second line sets the modified state to true.
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Fri Jun 16, 2006 5:10 pm    Post subject: Reply with quote

Quote:
Additionally this won't change the modified state of the document, so you can close it without beeing prompted for saving.

I was not aware of that...
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Fri Jun 16, 2006 5:23 pm    Post subject: Reply with quote

pitonyak wrote:
Quote:
Additionally this won't change the modified state of the document, so you can close it without beeing prompted for saving.

I was not aware of that...

I saved the document before running the first line and stumbled across the disabled floppy-button on the main toolbar.
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Sat Jun 17, 2006 2:07 am    Post subject: Reply with quote

Thank you Andrew and Villeroy for beeing engaged in this matter. I also realized that the modified state is not set, so I manually inserted a space and saved the document. Unfortunately the problem remains. I can't get the module removed.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Sat Jun 17, 2006 2:31 am    Post subject: Reply with quote

These are the steps I have done successfully:
Create new doc of any kind.
Insert module in it's "Standard" container (code below)
Insert new library (default name "Library1")
Insert some new modules in "Library1".
Save the document.
Run documentContainer.Standard.Main
Code:

Sub Main
  THisComponent.BasicLibraries.removeLibrary("Library1")
  thisComponent.store
End Sub

Notice empty Library1
Reload document
Notice empty Library1
[/code]
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Thu Jun 29, 2006 4:10 pm    Post subject: Reply with quote

Thank you Villeroy. After some further unsuccessful tries in removing a named module, I now delete the complete library of the document as you proposed (after an appropriate warning and a user-confirmation):
Code:
   oLibs = ThisComponent.getLibraryContainer()
   if oLibs.hasByName("Standard") then
      'trying to remove a module by use of getLibraryContainer object unsuccessful
      'so remove the complete library via BasicLibraries
      thisComponent.BasicLibraries.removeLibrary("Standard")
      thisComponent.setModified(true)
   end if

It is not the solution I prefer, because it will also remove other user-defined modules that might exist in the document - even this is a very unlikely case.

Regards
Harry
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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