Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Mastercam VBS with Open Office


Recommended Posts

Managment has asked me if I could convert my VBS setup sheet to run with open office ("becauses its free!") instead of Word that I wrote it for. From what I have been able to determine, OO doesn't use VBS.

I'd like to hear from anyone else more experienced with programming scripts to confirm or deny this.

Anyone?

 

John

Link to comment
Share on other sites

Sorry about that John. After re-reading your question and my post, I realized that I read it waaay wrong. Maybe it was too early in the AM, but I thought you were asking about OpenOffice's equivalent to Microsoft Office's VBA. My bad bonk.gif

 

Yes, you can automate OOo from Mastercam using COM much like you would with MS Office. The syntax and some other things aren't the same, but it's very similar. Here's a quick snippet that I whipped up that hopefully will get you started. All it does is write some text in a Writer document and save it with the sane name and dir as your current MC9 file (Ex: C:Stuff1234.mc9 -> C:Stuff1234.sxw):

 

code:

'///////////////////////////////////////////////////////////////////////////////

'//

'// Author: Chris Bellini [email protected]

'// Copyright © 2005 In-House Solutions Inc.

'// Date: 06/03/2005 11:10 AM

'// File Name: mcam_OOo.vbs

'// Description: an example of automating OpenOffice.org Writer from Mastercam

'//

'// Comments:

'// - 06/03/2005 <cvb>: initial version

'//

'//

'// ----------------------------------------------------------------------------

'// This library is free software; you can redistribute it and/or

'// modify it under the terms of the GNU Lesser General Public

'// License as published by the Free Software Foundation; either

'// version 2.1 of the License, or (at your option) any later version.

'//

'// This library is distributed in the hope that it will be useful,

'// but WITHOUT ANY WARRANTY; without even the implied warranty of

'// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

'// Lesser General Public License for more details.

'//

'// You should have received a copy of the GNU Lesser General Public

'// License along with this library; if not, visit

'//
or write to the Free Software

'// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,

'// MA 02110-1301, USA

'///////////////////////////////////////////////////////////////////////////////

 

' ////////// CONSTANTS ////////////////

Const DEF_SXW_EXT = ".sxw" ' OOo Writer file extension

 

' Call the main subroutine

Call Main()

 

' Purpose: The main subroutine

Sub Main()

Dim args() ' empty arguments

Dim objOODesktop ' OOo Desktop object

Dim objOODocument ' OOo Document object

Dim objOOText ' OOo Text object

Dim objOOCursor ' OOo Cursor object

Dim strCurrPath ' current path to our MC9 file

Dim strBName ' the base of the filename of our MC9 file

Dim strSXWFileName : strSXWFileName = "C:FromMC.sxw" ' assembled SXW filename

 

 

' The service manager is always the starting point

' If there is no office running then an office is started up

Set objServiceManager = CreateObject("com.sun.star.ServiceManager")

 

' Create the Desktop

Set objOODesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")

 

' Open a new empty Writer document

Set objOODocument = objOODesktop.loadComponentFromURL("private:factory/swriter",_

"_blank", 0, args)

 

' Create a text object

Set objOOText = objOODocument.getText

 

' Create a cursor object

Set objOOCursor = objOOText.createTextCursor

 

' Insert some text

objOOText.insertString objOOCursor, "Greetings from Mastercam VBS!" & vbLf, False

 

' If we have a valid MC9 file loaded, let's use its directory and name

' as the base for the filename of our SXW file. Otherwise, just use our

' default of FromMC.sxw.

If (IsDrawing()) Then

' get the current path

strCurrPath = objFSO.GetParentFolderName(GetCurrentFileName())

 

' get the base

strBName = objFSO.GetBaseName(GetCurrentFileName()

 

' assemble the filename of our SXW file

strSXWFileName = strCurrPath & "" & strBName & DEF_SXW_EXT

End If

 

' Save the file

Call objOODocument.storeAsURL (ConvertToURL(strSXWFileName), args)

 

' All done

ShowString ("Saved the file to: " & strSXWFileName)

End Sub

 

 

' Purpose: Convert a standard Windows path to a OOo file URL

' I: Windows file path

' O: OpenOffice file URL

Function ConvertToUrl(strFile)

strFile = Replace(strFile, "", "/")

strFile = Replace(strFile, ":", "|")

strFile = Replace(strFile, " ", "%20")

strFile = "file:///" + strFile

 

ConvertToUrl = strFile

End Function

 

 

' Purpose: Determine if something with geo is open in MC.

' I: (none)

' O: True=has geo, False=empty file

Function IsDrawing()

Dim bRet ' return value

 

 

' try to find an alive entity

bRet = StartDBSearch(mc_alive, -1)

 

' return

IsDrawing = bRet

End Function

HTH

Link to comment
Share on other sites

I guess I'm just looking for a easy fix to convert my VBS file from Word output to OO, but I guess it'll be more work than I really want to put into it. It took me several weeks to do, mostly cause I had to learn scripting and had lots of help from some great folks on this forum.

FWIW, the VBS file I wrote is in the FTP, setupsheet.vbs I believe.

 

 

John

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...