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:

vbscript : open mcx file and import iges


Recommended Posts

hello,

 

that's my first automation in mastercam, I am using X8 but i am not sure i can adress it using vbscript.

 

I have a mcx file with some geometry and operations which is used as a template

I want to open it

import an iges file (add the geometry into the template)

rename the nci

saveas the mcx file

 

from the vbscript doc, i understand that importfile import the content into the current mcx session, but it seems it import it into a new session instead of the active one ? AM I right ?

if yes, do i need to first save the iges as a mcx file and then merge it with my template ? or is there any other solution ?

 

to open the mcx template, I am using AskForFileName and then OpenMC, but the mcx file is not opened. is it because the iges is already imported ?

 

Thanks in advance

Thomas

Link to comment
Share on other sites

Unfortunately the MergeMC function you need does not support merging IGS file, however in X8 it was found that the MergeMC function was not working at all so that is not going to help you i'm afraid. I did test a quick script in X9 and it is working but I had to import the igs file first then merge the mcx file as shown below.


Call Main

Sub Main


Dim igs
igs = "C:\Users\Public\Documents\shared mcamx8\mcx\base.igs"

Dim mcx
mcx = "C:\Users\Public\Documents\shared mcamx8\mcx\T.mcx-8"

Dim saveAs
saveAs = "C:\Users\Public\Documents\shared mcamx9\mcx\baseT.mcx-9"

NewMC false 

If (ImportFile(igs)) Then
   If (MergeMC(mcx)) Then
	 RepaintScreen true
	 
	 ' -- TODO: Update NCI
	 
	 
	 ' -- SaveAs
	 If SaveMCAs(saveAs, true) Then
	   ShowString "File saved " & saveAs
	 Else
	   ShowString "Failed to save as " & saveAs
	 End If
	 
   Else
     ShowString "Failed to merge " & mcx
   End If

Else
   ShowString "Failed to import " & igs
End If



End Sub

If you are not upgrading to X9 any-time soon and you feel a little adventurous I would recommend you taking a look at creating a VB.NET Mastercam NETHook. You can download the free Community Edition of Visual Studio and then download and install a Mastercam NETHook project template for Visual Studio (see the sticky threads in this forum) to set up all the necessary boiler plate code ready to get started. There is also a document that is included in the project that walks you through the steps of setting up the project to deploy and debug with Mastercam.

 

Visual Studio Community Edition (Free):

https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

 

Visual Studio C# and VB.NET Project Templates: Install from within Visual Studio under Tools->Extensions and Updates search for online for Mastercam.

 

VB.NET and C# Example projects: https://www.mastercam.com/en-us/Communities/3rd-Party-

API Documentation: https://www.mastercam.com/en-us/Communities/3rd-Party-Developers/NET-Hook-Downloads

 

If you have any other questions don't hesitate to reply to this thread.

 

  • Like 1
Link to comment
Share on other sites

Thanks for your quick and valuable reply Mick.

 

Well, I will check if we can switch to X9 for this project soon (we also use MoldPlus) since it will be easier.

Else, I gonna use Mastercam NETHook .... hope it won't be to hard to start.

 

Getting started should be pretty straight forward, just follow the document installed with the project template and look at some of the examples on the website. If you get stuck feel free to reply to this thread or email.

Link to comment
Share on other sites

I created a quick VB.NET NETHook for X8 that prompts for an IGES file and merges the file into an existing MCX file, renames the NCI for all selected operations and then saves the file to another file name. Hopefully this will help.

 

VB.NET source code and NETHook attached.

 

Copy the NETHook (DLL) and FT file to your X8 chooks folder, you may need to unblock the NETHook (right click the DLL and go to properties and unblock)

 

Start Mastercam, go to Settings-> Customize and under the Category select NETHook, you should see the Merge IGS in the list, drag that to a toolbar or a menu.

 

Click on the button or menu you just created to execute the NETHook, it will check to see if you have at least one operation in the operations manager and if so it will prompt your for an IGES file.

 Public Overrides Function Run(ByVal param As Integer) As MCamReturn

            ' Check that we have a drawing
            Dim ops = SearchManager.GetOperations()

            If Not ops.Any Then
                Return MCamReturn.FunctionExit
            End If

            Dim iges As String = String.Empty

            ' Prompt for IGS
            Using selectIgs As New OpenFileDialog

                With selectIgs
                    .CheckFileExists = True
                    .CheckPathExists = True
                    .DefaultExt = "igs"
                    .Filter = "IGES Files (*.igs;*.iges)|*.igs;*.iges"
                    .Multiselect = False
                    .Title = "Merge IGES"

                    ' User failed to select a file so just bail
                    If Not .ShowDialog() = DialogResult.OK Then
                        Return MCamReturn.FunctionExit
                    End If

                    ' Store the selection
                    iges = .FileName

                End With

            End Using

            ' Merge
            If Not FileManager.Open(False, iges, True) Then
                MessageBox.Show("Failed to merge file " & iges, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If

            Dim nci As String = Path.Combine(SettingsManager.CurrentDirectory, "merged.nci")

            ' Iterate all operations
            For Each op In ops
                ' Only selected operations
                If op.Selected Then
                    ' Set the NCI name
                    op.NCIName = nci
                    op.Commit()

                    op.Regenerate()
                End If
            Next

            Dim name As String = Path.Combine(Mastercam.IO.SettingsManager.CurrentDirectory, "merged.mcx-8")

            ' Save As
            If Mastercam.IO.FileManager.SaveAs(name, True) Then

                ' Switch to ISO 
                ViewManager.GraphicsView = SearchManager.GetSystemView(GraphicsViewType.Iso)

                ' and fit screen
                GraphicsManager.FitScreen()

                MessageBox.Show("Saved file to " & name, "Save As", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Failed to save file " & name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If

            Return MCamReturn.NoErrors
        End Function

MergeIGS_VBNETSource.zip

X8NETHook.zip

Edited by Mick from CNC Software Inc.
  • Like 1
Link to comment
Share on other sites

Thanks a lot for your help, that can be called 5 stars support.

 

I am able to build the solution and the NETHook and use it Mastercam.

I started to make changes to the code.

 

Just have to go deeper to well understand everything.

 

My last question for today : how to debug ?

when i start debugging from VS, it launch a new mastercam session, which may not be usefull.

is there a way to start the nethook from mastercam in debug mode ?

Link to comment
Share on other sites

 

My last question for today : how to debug ?

when i start debugging from VS, it launch a new mastercam session, which may not be usefull.

is there a way to start the nethook from mastercam in debug mode ?

 

Because it is a class library it can not be started directly so it needs a host application.

 

For debugging purposes it should not really be an issue, when you stop debugging Mastercam will exit. In some cases you may need to have Mastercam start fresh because of initialization code that may need to be called etc.

post-4901-0-36873900-1433960340_thumb.png

Link to comment
Share on other sites

So I do something wrong :

I set a breakpoint on the first line after run function

after start debugging, Mastercam starts

but code is not running :

in VS the available commands are stop debugging or break like the breakpoint was not reached but execution not finished

in Mastercam, all interactive commands are available

 

What is missing ?

 

 

Nevertheless, I started a new small project to change stock size.

I found the properties to be changed.

My code successfuly change them (.JobSetupStockSize and .JobSetupStockOrigin) since values are changed when I edit the stock.

but the display is not updated (still display previous stock)

the only way  I found to refresh the stock is to edit the stock and validate it, then display is updated.

... but did not found any stockupdate or things like that in NETHook

Any idea ?

Link to comment
Share on other sites

Make sure you are running Visual Studio as Administrator to do so create a short cut to Visual Studio on your desktop and then right click properties check 'Run As Administrator'. Start Visual Studio via the short cut then browse to the project to open it. Windows 8 and possibly Windows 7 doesn't allow copying files to the Program Files folder so you need to be running Visual Studio as an Administrator to bypass this.

 

In Visual Studio make sure you are building a debug version and not a release version of the project,  Build->Configuration Manager set configuration to debug and platform to x64.

 

After this if you still can not debug check the Output Window (View->Output) and make sure it is compiling successfully and that 2 files are copied, that is the NETHook and the FT:

 

------ Rebuild All started: Project: MergeIGS, Configuration: Debug x64 ------
  MergeIGS -> D:\_DEV\support\Misc\MergeIGS\MergeIGS\bin\x64\Debug\MergeIGS.dll
          1 file(s) copied.
          1 file(s) copied.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
 
 
 
As for the JobSetupStockSize  issues, can you post a snippet of code so I can see what it is you are doing, thanks.
 
 
 

 

So I do something wrong :

I set a breakpoint on the first line after run function

after start debugging, Mastercam starts

but code is not running :

in VS the available commands are stop debugging or break like the breakpoint was not reached but execution not finished

in Mastercam, all interactive commands are available

 

What is missing ?

 

 

Nevertheless, I started a new small project to change stock size.

I found the properties to be changed.

My code successfuly change them (.JobSetupStockSize and .JobSetupStockOrigin) since values are changed when I edit the stock.

but the display is not updated (still display previous stock)

the only way  I found to refresh the stock is to edit the stock and validate it, then display is updated.

... but did not found any stockupdate or things like that in NETHook

Any idea ?

Link to comment
Share on other sites

VS is running as admin (admin written in the window title).

Configuration manager was well set (debug + x64)

Compile is successful (the 2 files are copied in Mastercam chooks directory).

Nevertheless, even if I set a breakpoint on the first command in the run function, I do not reach it.

I attach the debug trace of the output view : there are some errors but do not know if there are important or how to fix them.

 

I also attach the NETHookMain.vb of my 'changeepbrut' project which is pretty simple :

if the height and size of the stock are set to 400, change them to 200, and vice and versa.

That is working, it is just that the display of the stock is not updated after the change.

output debug.txt

NETHookMain.zip

Link to comment
Share on other sites

VS is running as admin (admin written in the window title).

Configuration manager was well set (debug + x64)

Compile is successful (the 2 files are copied in Mastercam chooks directory).

Nevertheless, even if I set a breakpoint on the first command in the run function, I do not reach it.

I attach the debug trace of the output view : there are some errors but do not know if there are important or how to fix them.

 

I also attach the NETHookMain.vb of my 'changeepbrut' project which is pretty simple :

if the height and size of the stock are set to 400, change them to 200, and vice and versa.

That is working, it is just that the display of the stock is not updated after the change.

 

 

Not sure why you are not able to debug the first project but something must be out of sync somewhere. I would double check to make sure the post build steps are correct as the files are copied but might only be copied to the x64\Debug folder and not to your Mastercam CHooks folder. I'll post some images of my setup for your other project so you can see how it all comes together.

 

 

In regards to your other project it is working fine for me, you are only updating the Stock Z and StockOrigin Z values nothing else so only the Z will reflect the changes (see images)

 Select Case StockSize.z
            Case 400
                StockSize.z = 200
                StockOrigin.z = 200
            Case 200
                StockSize.z = 400
                StockOrigin.z = 400
            Case Else

post-4901-0-97095300-1434108386_thumb.png

post-4901-0-31424100-1434108435_thumb.png

post-4901-0-70813200-1434108450_thumb.png

post-4901-0-72548400-1434108453_thumb.png

post-4901-0-13758400-1434108465_thumb.png

post-4901-0-72232100-1434108471_thumb.png

post-4901-0-80992400-1434108484_thumb.png

post-4901-0-86272800-1434108492_thumb.png

Link to comment
Share on other sites

well, I do not know what has been changed but debugging is now working !

 

Regarding the stock properties change, the change is reflected into the stock panel, only the 3D view is not updated.

the change is taken into account when operations are computed, so it is OK (3D display is updated at computation time !)

 

Thanks a lot

Link to comment
Share on other sites

well, I do not know what has been changed but debugging is now working !

 

Regarding the stock properties change, the change is reflected into the stock panel, only the 3D view is not updated.

the change is taken into account when operations are computed, so it is OK (3D display is updated at computation time !)

 

Thanks a lot

 

Glad to here you are up and running, enjoy!

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