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

Ive typed following script:

 

code:

 

 

Do

LevelsManager.SetLevelName(i+1, "")

LevelsManager.SetLevelVisible(i+1, False)

 

...

 

i += 1

Loop While i < 5

 


With VB Design Ive made a ComboBox to select these 5 Levels "seperatly".

 

code:

   

If LevelBox.Items.contains("Level 1") Then

For x = 1 To 5

LevelsManager.SetLevelVisible(x, False)

Next x

LevelsManager.SetLevelVisible(1, True)

Next

Of course instead of "if-Next" there will be a Case-script for all 5 Levels.

 

But I dont know why this doesnt work. Has anybody used the LevelsManager before?

Link to comment
Share on other sites

code:

  

Do

LevelsManager.SetLevelName(i+1, "")

LevelsManager.SetLevelVisible(i+1, False)

 

...

 

i += 1

Loop While i < 5

 

 

 

If LevelBox.Items.contains("Level 1") Then

For x = 1 To 5

LevelsManager.SetLevelVisible(x, False)

Next x

LevelsManager.SetLevelVisible(1, True)

Next

Link to comment
Share on other sites

Pokemon,

 

I'm happy to try and help - let's see if we can't figure out what's going on here.

 

First off, I'm a little confused by what you're trying to do here. The first chunk of code you've got there is going to set all of the level names for levels 1 through 5 to an empty string and make them all invisible, correct? But then the second chunk of code goes through the items in a Combo Box (I think... ?) looking for the string "Level 1", and if found makes levels 1-5 invisible and level 1 visible again. The two bits of code don't quite seem to make sense together... could you maybe explain what you're trying to do in greater detail? If we could better see the end goal, we might be able to see where the code's gone wrong for you.

Link to comment
Share on other sites

Hey Mike,

 

The very first step of my program is the "transformation" of a 3D object in Mastercam to several 2D levels by hitting a button... Ive posted this before in this forum and im still trying to realize it!

In my example now there would be 5 of these levels. And now you have to imagine that I was thinking of making these levels invisible except of one particular one by using a ComboBox, e.g. after hitting the button these levels would be created and my ComboBox would display sth like "Level 1" which means that only my first level would be visible.

I thought that seperating these two codes would be the better choice.

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

Hey Mike,

 

It would be really great if you could do this! Iva tried myself but still I cant figure it out how do script this by myself...

At the moment I am doing this part by recreating each level new... its not really useful because you always create a new file. Having the original idea would be real nice!

Link to comment
Share on other sites

Pokemon,

 

Okay, so I threw together a little level switching application for you. It's a little bit more complicated than what you were looking for, as it always for five customized levels as opposed to the hard-coded five levels you were thinking of using, but doing it this way served as a better example. This was built to target the X2 MR1 NetHook 2.0 API, so you would need to build it against that version and run it yourself - be sure to add your references to the solution appropriately.

 

Link to the project:

Level Switching Tester App

 

The application's Run method is fairly simple - it just creates the windows form and displays it modelessly. Here's the main application class code:

 

code:

 

Imports Mastercam.App

Imports Mastercam.App.Types

 

 

Public Class Class1

Inherits NetHook2App

 

Public Overrides Function Run(ByVal param As Integer) As Mastercam.App.Types.MCamReturn

 

' Create the form object

Dim MyForm As Form1 = New Form1()

 

' Display the form modelessly

MyForm.Show()

 

End Function

 

End Class

Now, the meat of the code is actually in the message handlers of the form itself. I set up the whole app to be button driven, so all of these methods are run by the clicking of a button. You could do it via the switching of items in a combo box or whenever the focus is lost in one of those controls, but this just seemed easier for the purposes of example. The code is pretty straightforward.

 

code:

Imports Mastercam

Imports Mastercam.IO

Imports Mastercam.Database

Imports Mastercam.Database.Types

Imports Mastercam.Support

 

 

Public Class Form1

 

Private Sub TurnAllLevelsVisibleBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TurnAllLevelsVisibleBtn.Click

 

' Make all the levels visible

TurnAllLevelsVisible()

 

' Make sure to do a regenerate of the display list when we're done

' so that we can see the changes

GraphicsManager.Repaint(True)

 

End Sub

 

Private Sub SetVisibleLevelBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

' If the first level option is set...

If ComboBox1.SelectedIndex = 0 Then

 

' Get the value from that level option numeric control

Dim Value As Integer = NumericUpDown1.Value

 

' Render all of the levels invisible

TurnAllLevelsInvisible()

 

' Then make only that level option's value visible

LevelsManager.SetLevelVisible(Value, True)

 

' Finish it off with a regen of the display list

GraphicsManager.Repaint(True)

 

ElseIf ComboBox1.SelectedIndex = 1 Then

 

Dim Value As Integer = NumericUpDown2.Value

TurnAllLevelsInvisible()

LevelsManager.SetLevelVisible(Value, True)

 

GraphicsManager.Repaint(True)

 

ElseIf ComboBox1.SelectedIndex = 2 Then

 

Dim Value As Integer = NumericUpDown3.Value

TurnAllLevelsInvisible()

LevelsManager.SetLevelVisible(Value, True)

 

GraphicsManager.Repaint(True)

 

ElseIf ComboBox1.SelectedIndex = 3 Then

 

Dim Value As Integer = NumericUpDown4.Value

TurnAllLevelsInvisible()

LevelsManager.SetLevelVisible(Value, True)

 

GraphicsManager.Repaint(True)

 

ElseIf ComboBox1.SelectedIndex = 4 Then

 

Dim Value As Integer = NumericUpDown4.Value

TurnAllLevelsInvisible()

LevelsManager.SetLevelVisible(Value, True)

 

GraphicsManager.Repaint(True)

 

End If

 

End Sub

 

Private Sub TurnAllLevelsVisible()

 

' Get all of the active levels in the level manager

Dim LevelNumbers() As Integer = LevelsManager.GetActiveLevelNumbers()

Dim CurrentLevelNumber As Integer

 

' Make each of the active levels visible

For Each CurrentLevelNumber In LevelNumbers

LevelsManager.SetLevelVisible(CurrentLevelNumber, True)

Next

 

End Sub

 

Private Sub TurnAllLevelsInvisible()

 

' Get all of the active levels in the level manager

Dim LevelNumbers() As Integer = LevelsManager.GetActiveLevelNumbers()

Dim CurrentLevelNumber As Integer

 

' Make each of the active levels invisible

For Each CurrentLevelNumber In LevelNumbers

LevelsManager.SetLevelVisible(CurrentLevelNumber, False)

Next

 

End Sub

 

Private Sub MoveGeomToLevelBtn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

' Get the value of the level option #1

Dim Value As Integer = NumericUpDown1.Value

 

' Get all of the selected geometry in the part

Dim SelectedItems As SelectionMask = New SelectionMask(True, True, False)

Dim SelectedGeometry() As Geometry = SearchManager.GetGeometry(SelectedItems)

Dim GeometryItem As Geometry

 

' Set each of the selected geometry items to the level option #1 level value

For Each GeometryItem In SelectedGeometry

GeometryItem.Level = Value

GeometryItem.Commit()

Next

 

End Sub

 

Private Sub MoveGeomToLevelBtn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

Dim Value As Integer = NumericUpDown2.Value

Dim SelectedItems As SelectionMask = New SelectionMask(True, True, False)

Dim SelectedGeometry() As Geometry = SearchManager.GetGeometry(SelectedItems)

Dim GeometryItem As Geometry

 

For Each GeometryItem In SelectedGeometry

GeometryItem.Level = Value

GeometryItem.Commit()

Next

 

End Sub

 

Private Sub MoveGeomToLevelBtn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

Dim Value As Integer = NumericUpDown3.Value

Dim SelectedItems As SelectionMask = New SelectionMask(True, True, False)

Dim SelectedGeometry() As Geometry = SearchManager.GetGeometry(SelectedItems)

Dim GeometryItem As Geometry

 

For Each GeometryItem In SelectedGeometry

GeometryItem.Level = Value

GeometryItem.Commit()

Next

 

End Sub

 

Private Sub MoveGeomToLevelBtn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

Dim Value As Integer = NumericUpDown4.Value

Dim SelectedItems As SelectionMask = New SelectionMask(True, True, False)

Dim SelectedGeometry() As Geometry = SearchManager.GetGeometry(SelectedItems)

Dim GeometryItem As Geometry

 

For Each GeometryItem In SelectedGeometry

GeometryItem.Level = Value

GeometryItem.Commit()

Next

 

End Sub

 

Private Sub MoveGeomToLevelBtn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

 

Dim Value As Integer = NumericUpDown5.Value

Dim SelectedItems As SelectionMask = New SelectionMask(True, True, False)

Dim SelectedGeometry() As Geometry = SearchManager.GetGeometry(SelectedItems)

Dim GeometryItem As Geometry

 

For Each GeometryItem In SelectedGeometry

GeometryItem.Level = Value

GeometryItem.Commit()

Next

 

End Sub

 

End Class

That should just about do it!! Hope the example helps (you and anybody else who's interested), and if you need any additional help let me know.

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