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:

Bullines

Verified Members
  • Posts

    3,094
  • Joined

  • Last visited

Everything posted by Bullines

  1. Make the script look exactly like this: code: '//////////////////////////////////////////////////////////////////////////////// '// '// Author: Mick George [email protected] '// Date: 28/08/2002 02:29 PM '// File Name: SAVEBACKUP.VBS '// '// Description: Example of backing up current drawing. '// '// Comments: Original example by Mick George '// Modified by bryan (_at_) steeplechasetool (_dot_) com '// Modified by Mick George 7/11/2003 8:30:24 PM '// '//////////////////////////////////////////////////////////////////////////////// '///////////////// My Constants ///////////////// Public Const fsoDRIVE_UNKNOWN = 0 Public Const fsoDRIVE_REMOVABLE = 1 Public Const fsoDRIVE_FIXED = 2 Public Const fsoDRIVE_NETWORK = 3 Public Const fsoDRIVE_CDROM = 4 Public Const fsoDRIVE_RAM_DISK = 5 Public Const DEF_CENTERED = " " Public Const DEF_ERRLOG = "C:McScriptErr.log" Public Const DEF_BACKUP_DIR = "C:mcamxmcxMillback up" ' -- Edit to your taste ' -- Start Script Call Main() ' //////////////////// ' Sub Declaration ' //////////////////// Sub Main() On Error Resume Next Dim strBackupPath Dim strOriginalPath Dim FSO Dim strYear Dim strMonth Dim strDay Dim strHour Dim strMin Set FSO = CreateObject("Scripting.FileSystemObject") ' -- Make sure theres a disk in the floppy drive '// If CBool(CheckDrive("A:")) Then ' -- Check to make sure backup folder is valid If FSO.FolderExists(DEF_BACKUP_DIR) Then ' -- Make sure we have a drawing to save If Not IsDrawing Then ShowString "No current drawing" & DEF_CENTERED ' -- Bail Exit Sub End If ' -- Store current drawings name strOriginalPath = GetCurrentFileName '' '' ' -- Assign a new Mc filename '' '//strBackupPath = "A:Backup.MC9" '' strBackupPath = "C:TEMP" '' ' -- Format a time and date stamp and strip illegal chars strYear = Replace(FormatDateTime(Date, vbShortDate), "/", "") strHour = Replace(FormatDateTime(Time, vbShortTime), ":", "") '' strYear = CStr( DatePart( "yyyy", Date ) ) '' '' strMonth = CStr( DatePart( "m", Date ) ) '' '' If Len(strMonth) < 2 Then strMonth = "0" & strMonth '' '' strDay = CStr( DatePart( "d", Date ) ) '' '' If Len(strDay) < 2 Then strDay = "0" & strDay '' '' strHour = CStr( DatePart( "h", Now ) ) '' '' If Len(strHour) < 2 Then strHour = "0" & strHour '' '' strMin = CStr( DatePart( "n", Now ) ) '' '' If Len(strMin) < 2 Then strMin = "0" & strMin '' ' -- Build fullpath ''strBackupPath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & "." & strYear & strMonth & strDay & "_" & strHour & strMin & "." & FSO.GetExtensionName(strOriginalPath) strBackupPath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & "." & strYear & "_" & strHour & "." & FSO.GetExtensionName(strOriginalPath) Call ClearMenuAndPrompts ' -- Display current file in prompt area Call WriteString("Backing up file, please wait...") If SaveMCAs(strBackupPath, False) Then '//ShowString "File backup to floppy drive successful" & DEF_CENTERED ShowString "Backup to " & DEF_BACKUP_DIR & " complete" & DEF_CENTERED Else ShowString "Could not backup file to " & DEF_BACKUP_DIR & DEF_CENTERED End If ' -- Switch back to original file 'Call SaveMCAs(strOriginalPath, False) Call SaveMCAs(strOriginalPath, True) Call ClearMenuAndPrompts Call RepaintScreen (True) Else ''ShowString "Please insert a disk into drive A:" & DEF_CENTERED ShowString "Folder " & DEF_BACKUP_DIR & " does not exist!" & DEF_CENTERED Exit Sub End If If Err Then Call TrapError("Sub::Main", Err, True) Set FSO = Nothing End Sub ' //////////////////// ' Sub Declaration ' //////////////////// Sub TrapError(sSource, objErr, bLogIt) Dim sMSG Dim sLogError Dim FSO sMSG = "Following error occurred in this script:" & DEF_CENTERED & vbCrLf & vbCrLf sMSG = sMSG & objErr.Description & DEF_CENTERED & vbCrLf sMSG = sMSG & "Number: " & objErr.Number & DEF_CENTERED & vbCrLf sMSG = sMSG & "Source: " & DEF_CENTERED & sSource ShowString sMSG If bLogIt Then sLogError = "Error " & objErr.Number & " in " & sSource & ":" & vbCrLf & objErr.Description Call WriteLog(sLogError) End If objErr.Clear Set objErr = Nothing End Sub ' //////////////////// ' Sub Declaration ' //////////////////// Sub WriteLog(sLogMessage) On Error Resume Next Dim FSO Dim fsoStream Set FSO = CreateObject("Scripting.FileSystemObject") Set fsoStream = FSO.CreateTextFile(DEF_ERRLOG, True) fsoStream.WriteLine String(78, "-") fsoStream.WriteLine "---" & FormatDateTime(Now, vbGeneralDate) & "---" fsoStream.WriteLine sLogMessage fsoStream.WriteLine GetScriptEngineInfo fsoStream.Close ' -- Clean up Set fsoStream = Nothing Set FSO = Nothing If Err Then Call TrapError("Sub::WriteLog", Err, False) End Sub ' //////////////////// ' Function Declaration ' //////////////////// Function GetScriptEngineInfo() On Error Resume Next Dim s s = "" ' Build string with necessary info. s = ScriptEngine & " Version " s = s & ScriptEngineMajorVersion & "." s = s & ScriptEngineMinorVersion & "." s = s & ScriptEngineBuildVersion GetScriptEngineInfo = s ' Return the results. If Err Then Call TrapError("GetScriptEngineInfo", Err, True) End Function ' //////////////////// ' Function Declaration ' //////////////////// Function CheckDrive(sPath) On Error Resume Next Dim FSO Dim fsoDrive Set FSO = CreateObject("Scripting.FileSystemObject") ' -- Get the "A" drive Set fsoDrive = FSO.GetDrive(sPath) Select Case fsoDrive.DriveType ' -- Only interested in a Floppy drive... Case fsoDRIVE_REMOVABLE: CheckDrive = fsoDrive.IsReady Case Else ' -- Force failure CheckDrive = False End Select ' -- Clean up Set FSO = Nothing Set fsoDrive = Nothing If Err Then Call TrapError("Function::CheckDrive", Err, True) End Function ' //////////////////// ' Function Declaration ' //////////////////// Function AddBackSlash(sPath) If Right(sPath, 1) <> "" Then sPath = sPath & "" AddBackSlash = sPath End Function ' //////////////////// ' Function Declaration ' //////////////////// Function IsDrawing() Dim Ret Ret = StartDBSearch(mc_alive, -1) IsDrawing = Ret End Function I'm also assuming that you have the rights to create files in C:mcamxmcxMillback up and in the root of C (C:).
  2. If you enter a function that uses the ribbon bar (Ex: create rectangle), does the Ribbon Bar reappear?
  3. g huns, what is the path of the folder that you want to put the backups in?
  4. quote: might be case sensitive.? VBScript is not case-sensitive and neither are Windows paths. In vb script: code: Dim strMyVar is the same as: code: Dim STRMYVAR This is not a problem: code: Dim iSomeNumber iSOMenuMBeR = 2 + 2 And C:Windows is the same as C:WINDowS.
  5. quote: I "assume" that this has not been done over for X yet and it only runs in V9? The script runs fine on my computer in X SP1 Update 3 without any modifications. Like Code_Breaker mentioned, the only line you should ever need to modify is the constant at the top that looks like this: code: Public Const DEF_BACKUP_DIR = "C:Backup" ' -- Edit to your taste It's the directory of where the backup will be stored. You could make it looks like this: code: Public Const DEF_BACKUP_DIR = "C:My Stuff" ' -- Edit to your taste or this: code: Public Const DEF_BACKUP_DIR = "D:StuffJunk" ' -- Edit to your taste or this: code: Public Const DEF_BACKUP_DIR = "A:" ' -- Edit to your taste Or any other valid path. quote: I don't have that line. I do have this... strBackupPath = "C:TEMP" so I changed it to "C:mcamxmcxMillback up" and it does something, you see the little saving nci box blink really fast, but when I open up the back up folder it's still empty. Ok I found it, it is just getting dumped in the mill folder. How do I get it into the back up folder? Don't modify the contents of the strBackupPath variable in the Main() subroutine. The script stores the full path to the backed up file based on the concatination of the aforementioned DEF_BACKUP_DIR constant (which contains the backup directory of your choosing), the filename of the MCX file you have open, and a date/time stamp.
  6. Primoz, I'm unable to reply to your email because it bounces back with a "Disc quota exceeded" error.
  7. That's odd, because the code works fine on my computer. Which version of Mastercam are you running?
  8. quote: Is is possible to initiate the "Get Library From Text" function from a VB Script? No quote: Can this function be initiated in a C-hook? I'm looking but I don't see anything yet If worse comes to worse, you'd have to write your own "importer" to parse your TXT file and then create new tools using the data from the TXT file. In the case of VBScript, in the past, I just pulled the data out of the TXT file and used it in my operations. From looking at the Nethook API, we are now able to create a new tool and get/set tool data.
  9. I don't think a C-Hook exists, per se. But it is possible. From experience, it can be done via VBScript or .NET APIs. You can parse out the tool information from the TXT file (look in the comments to find out which values represent what). Then you can create a new tool in your library programatically using functions like MakeContour(), MakePocket(), etc in VBScript using the tool parameters from the TXT file (you can't create a tool in VBScript). From the Nethook API, you could use the get/set methods of an instance of a CToolRef object such as cornerRadius, toolDiameter, toolComment, etc to access the members. There's probably similar ways in the C-Hook API but I avoid it whenever possible and use it as a last resort.
  10. Hmmm Not sure I recall that thread. However, I do know of a device that Belkin makes aimed at gamers - specifically first-person shooters. Nostromo SpeedPad n52 Nostromo SpeedPad n50 All buttons are programmable. So you can have multiple keystrokes asigned to a button. I've never used one, but read a bit about them. Then there's 3D Connexion product line of SpaceBalls and whatnot. Although I'm not sure if multiple keystrokes can be assigned to the buttons. Microsoft also made a few gaming devices, like the Strategic Commander and Game Voice, that are along the same lines as those Nostromo SpeedPads. But I think they've killed off that product line.
  11. Try this out: code: Sub Brisanje() Dim iRet, iLevel UnselectAll() iRet = StartDBSearch(mc_alive, mc_linetype) If iRet Then Do While iRet iLevel = GetEntityLevel() iRet = GetEntityEptr() If iLevel = 10501 Then If Not (DeleteEntity(iRet)) Then ShowString "Unable to delete entity: " & iRet End If End If iRet = NextDBSearch Loop Else ShowString("There are no elements on the screen!") End If Call RepaintScreen(False) End Sub HTH
  12. File-locking is built into Win32 API functions like OpenFile(), which would make implementation swift. quote: If you guys would send user files to the "My Documentsmcxmill..." folders. Agreed. I know I've said it before and since it's been brought up, I'll say it again Exploiting a Windows feature (and in term a time-tested UNIX feature) of each user having their own location that they have full rights to would solve a whack-load of problems. I'm a bit creeped that we're nearing 2006 and all data is off the root of the drive. ALL users, regardless of their access level, have full privileges to anything in C:Documents and Settings[their_username]. Good places for files and config files are: C:Documents and Settings[their_username]Application Data C:Documents and Settings[their_username]Local SettingsApplication Data C:Documents and Settings[their_username]My Documents Common stuff could go in: C:Documents and SettingsAll Users quote: I would like some kind of Vault system where you "check out" your file. Sounds like a versioning system like CVS, Subversion or Visual SourceSafe. [ 12-20-2005, 07:39 AM: Message edited by: Bullines ]
  13. I guess in X it's being treated like an input prompt without the input. Wonder if it's even possible to write to the status bar from the X SDK
  14. In V9/8/7/etc, write_str() wrote a string to the prompt area and write_str_nl() did the same but added a 'n'. There were also write_int(), write_real() and write_long().
  15. Yeah, that would definitely come in handy. I would send those requests to QC.
  16. Which types of op group info are you looking for?
  17. Perhaps when you do a switch 'n' snap (patent pending ), you should use the Nap() function to give Mastercam a chance to catch up: code: ' this should probably go in a function or sub of its own ' start SetGViewNumber(mcVIEW_FRONT) Call RepaintScreen(True) Call Nap(5) Call RunMastercamCommand("ToClipboard") Call Nap(8) strCnvtImage = strPathToConv + " /clippaste /resample=(1000,800) /convert=" + strimage2 + ".png" objWSHShell.Run strCnvtImage, 0, True Call Nap(8) ' next SetGViewNumber(mcVIEW_FRONT) ' ... Also, though it may not be a big issue, is that your Nap() function (which might as well be a Sub since it doesn't return anything) will not behave as expected should an Internet connection not exist. In the case of no connection, Nap() will at most stop for 4 "seconds" when PING fails to reach a host. A better implementation would be: code: ' Purpose: Alternative to WSH Shell Sleep() for Mastercam VBScript that ' pings the localhost a given number of times (read: seconds). ' I: number of "seconds" to nap ' O (none) Sub Nap(iSeconds) Const DEF_HOST = "127.0.0.1" ' localhost Dim objShell ' WSH Shell object Set objShell = CreateObject("WScript.Shell") ' need to add 1 to get it approx. correct iSeconds = iSeconds + 1 objShell.Run "ping -n " & iSeconds & " " & DEF_HOST , 0, True Set objShell = Nothing End Sub HTH
  18. Glad to hear that it works. Good thing you didn't have to resort to WMI. It's powerful, but ugly. Here's what a WMI version of the same script might look like: code: ' Kick off the script Call Main() ' Purpose: the main subroutine Sub Main() Dim strComputer ' computer name to query Dim ojbWMI ' WMI object Dim colResult ' results from the query Dim strUserName ' current user name ' This computer. strComputer = "." ' Retrieve the username of the person currently logged into the ' computer. Greet the person with their username. Set objWMI = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" _ & strComputer & "rootcimv2") Set colResult = objWMI.ExecQuery("Select * from Win32_ComputerSystem") ' There _should_ only be one. For Each objComputer in colResult strUserName = objComputer.UserName Next ShowString "Hi there! You're logged in as " & strUserName & "." ' Cleanup Set objWMI = Nothing Set colResult = Nothing End Sub Nasty, eh? The only benefit is that it'll display the workgroup/domain associated with the username.
  19. Oops, I forgot that this is running inside of Mastercam. My bad Change: code: Set objNetwork = WScript.CreateObject("WScript.Network") to: code: Set objNetwork = CreateObject("WScript.Network") That should do it.
  20. quote: Is it possible to get the logged on user's name with VBS? Yes, consider something like this: code: ' Kick off the script Call Main() ' Purpose: the main subroutine Sub Main() Dim objNetwork ' Network object Dim strUserName ' current user name ' Retrieve the username of the person currently logged into the ' computer. Greet the person with their username. Set objNetwork = WScript.CreateObject("WScript.Network") strUserName = objNetwork.UserName ShowString "Hi there! You're logged in as " & strUserName ' Cleanup Set objNetwork = Nothing End Sub It uses the Network functions available to the Windows Scripting Host. You could use WMI instead, but people not running WinXP would have to install WMI in order for it to work. Using the Network WSH stuff is almost guaranteed to work on all Windows versions. HTH
  21. What's in the Directory value in the following Registry keys? HKCUSoftwareCNC Software, Inc.Mastercam X HKLMSOFTWARECNC Software, Inc.Mastercam X

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...