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:

Recommended Posts

Here's something that's short 'n' sweet:

 

code:

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

'//

'// Author: Chris Bellini [email protected]

'// Date: 04/06/2005 12:03 PM

'// File Name: IncrementAllLevels.vbs

'//

'// Description: Moves entities to a new level based on a user-supplied

'// increment value.

'//

'// Comments: Mastercam currently supports a maximum of 255 unique

'// levels. Mastercam X will support many more
;)

'//

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

 

' Call the main subroutine

Call Main()

 

 

' Purpose: The main subroutine

Sub Main()

Dim bSuccf ' success flag

Dim iNewLevel ' new level number

Dim iIncrement : iIncrement = 100 ' user-supplied increment value

 

 

' Prompt the user for an increment value between 1 and 254. If

' the user doesn't enter a value, exit the script.

If Not (askNumber("Increment value (1-254):", 1, 254, iIncrement)) Then

ShowString "Error: An increment value wasn't entered. Aborting..."

Exit Sub

End If

 

' Loop through the entire database of entities and move each entity to

' a new level. The new level is the sum of the existing level and a

' user-supplied increment value. Because Mastercam currently

' supports 255 unique levels, any newly summed level number that

' exceeds 255 will not be allowed to contain entities; the user will

' see a nice little error message instead
;)

bSuccf = StartDBSearch(mc_alive, -1)

 

If bSuccf Then

Do

iNewLevel = GetEntityLevel() + iIncrement

 

If (iNewLevel <= 255) Then

Call SetEntityLevel(iNewLevel)

Else

ShowString "Error: Unable to move entity from level " & _

GetEntityLevel() & " to level " & iNewLevel & _

". Mastercam V9.x supports a maximum of 255 levels."

End If

 

bSuccf = NextDBSearch()

Loop While bSuccf

End If

 

' All done

ShowString "Done!"

End Sub

It'll prompt the user for an increment value and add that to the existing level number of each entity. And if the user enters a value like 220 and an entity is currently on level 70 (220+70=290), the script will warn the user that it can't move the entity to that level since it's greater than 255.

 

I'll see about ranges.

 

HTH.

Link to comment
Share on other sites

Ok, a bit of a quick hack 'cause I'm lazy but...

 

code:

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

'//

'// Author: Chris Bellini [email protected]

'// Date: 04/06/2005 1:16 PM

'// File Name: IncrementAllLevelsWithRange.vbs

'//

'// Description: Moves entities to a new level based on a user-supplied

'// increment value, within a range of user-supplied levels.

'//

'// Comments: Mastercam currently supports a maximum of 255 unique

'// levels. Mastercam X will support many more
;)

'//

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

 

' Call the main subroutine

Call Main()

 

 

' Purpose: The main subroutine

Sub Main()

Dim bSuccf ' success flag

Dim iCurrLevel ' current level of an entity

Dim iNewLevel ' new level of an entity

Dim iIncrement : iIncrement = 100 ' user-supplied increment value

Dim iRangeStart : iRangeStart = 1 ' range start

Dim iRangeEnd : iRangeEnd = 254 ' range end

 

 

' Prompt the user for an range start value between 1 and 254. If

' the user doesn't enter a value, exit the script.

If Not (askNumber("Range Start:", 1, 254, iRangeStart)) Then

ShowString "Error: A range start value wasn't entered. Aborting..."

Exit Sub

End If

 

' Prompt the user for an range end value between iRangeStart+1 and 254. If

' the user doesn't enter a value, exit the script.

If Not (askNumber("Range End:", iRangeStart + 1, 254, iRangeEnd)) Then

ShowString "Error: A range end value wasn't entered. Aborting..."

Exit Sub

End If

 

' Prompt the user for an increment value between 1 and 254. If

' the user doesn't enter a value, exit the script.

If Not (askNumber("Increment value (1-254):", 1, 254, iIncrement)) Then

ShowString "Error: An increment value wasn't entered. Aborting..."

Exit Sub

End If

 

' Loop through the entire database of entities, looking only at entities

' on levels in the user-supplied range, and move each entity to

' a new level. The new level is the sum of the existing level and a

' user-supplied increment value. Because Mastercam currently

' supports 255 unique levels, any newly summed level number that

' exceeds 255 will not be allowed to contain entities; the user will

' see a nice little error message instead
;)

bSuccf = StartDBSearch(mc_alive, -1)

 

If bSuccf Then

Do

iCurrLevel = GetEntityLevel()

 

If (iCurrLevel >= iRangeStart) And (iCurrLevel <= iRangeEnd) Then

iNewLevel = iCurrLevel + iIncrement

 

If (iNewLevel <= 255) Then

Call SetEntityLevel(iNewLevel)

Else

ShowString "Error: Unable to move entity from level " & _

GetEntityLevel() & " to level " & iNewLevel & _

". Mastercam V9.x supports a maximum of 255 levels."

End If

End If

bSuccf = NextDBSearch()

Loop While bSuccf

End If

 

' All done

ShowString "Done!"

End Sub

This will prompt for a range of existing levels to move. So if, for example, you want to only move levels 5 through 9 to levels 105 through 109, use this version of the script.

 

HTH

Link to comment
Share on other sites

It will appear for every entity that you tried to move beyond level 255. For example, if you set your increment to be 100 and some of your entities are currently on level 180, they won't be moved and you'll receive an error. This is because Mastercam supports 255 levels and the script tried to move the entity to level 280 (180+100=280). And of course, 280 > 255. Fun eh? wink.gif

 

If worse comes to worse, you can comment out that ShowString() or even toast that ELSE statement entirely; it still won't move the "offending" entity but it won't yell at you either wink.gif

Link to comment
Share on other sites
  • 2 weeks later...

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