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:

VB Script ImportNCI


Recommended Posts

Anybody give me some pointers as to why this code fails:


If FSO.FileExists(NCIFileImport) Then ShowString("NCI file found" )bRet = ImportNCI(NCIFileImport)

If debug = true then ShowString("ImportNCI bRet = " & bRet)


 

The FSO returns true so I know the filename is good but the importnci  bret always returns false and of course no nci file is imported into the operation tree.

 

Machine is successfully added first.

 

Thanks for looking

Link to comment
Share on other sites

This is a new script that I'm workiing on with MasterCAM 2017.

 

Here is more of the script. There is not much of it yet as it is still a work in progress. Everything works properly up to the importNCI, no error just returns false.

If FSO.FileExists(ImportDirectory & JobNumber & "_MB.X_T") Then ' File found								ImportFile(ImportDirectory & JobNumber & "_MB.X_T")							bRet = ChangeMachineType(DEF_MILL)									If GetActiveMachine() <> MachineDefinitionPath & MachineDefinition then				call SetActiveMachine(MachineDefinitionPath & MachineDefinition)			End if							Call RunMastercamCommand(Clear_Colors)		SetGViewNumber(7)		Call RunMastercamCommand(Screen_Fit)												bRet = ImportNCI(NCIFileImport)			If FSO.FileExists(NCIFileImport) Then ShowString("NCI file found" ) ' File found			If debug = true then ShowString("ImportNCI bRet = " & bRet)		bret = SaveMCAs(FilePath & JobNumber & "_MB.mcam",True)							Else							ShowString ("No job file found")			Exit sub							End If

Thanks for looking

Link to comment
Share on other sites

Karl,

 

I just ran this in 2017 and it worked fine ->

(Or course you must have an active Mill machine group to do the import into.)

 

Sub Main()
    Dim bRet
    Dim NCIFileImport
    ' This NCI is a simple 2D Contour toolpath
    NCIFileImport = "C:\Users\me\Documents\my mcam2017\Mill\NCI\T.nci"
    bRet = ImportNCI(NCIFileImport)
    if bRet then
        ShowString "ImportNCI -> True"
    else
        ShowString "ImportNCI -> False"
    end if
End Sub
Edited by Roger Martin from CNC Software
Link to comment
Share on other sites

I think I found the error. Thanks to Roger for the pointer. I had the file name as a mastercam file NOT the actual NCI file.

Unfortunately this is not what I was hoping for. 

I'd really like to import the actual operations from a file. Is this possible in a script with out having to select geometry first?  

The MakeOperationFromID needs the user to select geometry before importing the operation, which will not always be in the file.

 

Here is what I had for my first attempt. Some of the operations fail to create because some of the operations need surfaces to be selected and not just chains

Dim objOverRidesDim NumOfOperationsDim OperationNameDim ReturnDim i 	Set objOverRides = New McOverride	If debug = True then ShowString("Inside of AddOperation sub")	NumOfOperations = GetOperationCount(NCIFileImport)		If debug = True then ShowString("Operation count = " & NumOfOperations)	OperationName = GetFirstOperationName(NCIFileImport)		If debug = True then ShowString("Operation number " & i & " name = " & OperationName)		GrabChain (OperationName)	Return = MakeOperationFromName(NCIFileImport,OperationName,OperationName,objOverRides)		If debug = True then ShowString("Make Op returns " & Return)	For i = 2 To NumOfOperations		OperationName = GetNextOperationName() 				If debug = True then ShowString("Operation number " & i & " name = " & OperationName)				GrabChain (OperationName)		Return = MakeOperationFromName(NCIFileImport,OperationName,OperationName,objOverRides)				If debug = True then ShowString("Make Op returns " & Return)	NextEnd Sub' ////////////////////' Sub Declaration' ////////////////////Sub GrabChain (OperationName)If debug = True then ShowString("Inside of GrabChain sub")      If  AskForChain("Select Chain for Operation " & OperationName) = False Then        ShowString("Bad Input Chain")    End If   End Sub
Link to comment
Share on other sites

Karl,

 

I'm not seeing anyway of importing an operation with VB Script from an external file without having "something" already Chained (for a Chain-based op) or Drill Points (for a Point-based op).

 

Dim OpID

Dim HaveChain

OpID = -1

HaveChain = ChainAll(False, False, 0, "") ' Chain anything and everything (only "something" is really needed)

if (HaveChain) then

      OpID = MakeOperationFromName ( ...)
 end if
 
' If OpID is NOT -1, we must have imported an operation from the specified file
Link to comment
Share on other sites

Thanks Roger. That was what I thought also. I have used this( MakeOperationFrom () ) to bring in operations before, but in this case the toolpath operations are surfacing operations.

I will pursue having  the script open a dummy file with the operations and machine already included and then import the new geometry into it. 

Thanks again

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