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:

Setting VB Script to use parts of file name


Recommended Posts

When I have MasterCam open accross the top of the screen is the file name,

"Z:"customer name""part name"source"part name".mcx.

I know tis is the path to the source file.

Here is my question.

I have a VB Script that askes me for "customer name" and part number" so it can use it later on in the script.

Is there anyway to capture those without having to type them in every time I use the script?

Link to comment
Share on other sites
Guest SAIPEM

code:

    

Call Main

 

Sub Main()

 

MsgBox GetCustomer("Z:customer namepart namesourcepart name.mcx")

MsgBox GetPartNumber("Z:customer namepart namesourcepart name.mcx")

 

End Sub

 

 

Function GetCustomer(strQualifiedPath)

 

Dim intN

 

For intN = 4 To Len(strQualifiedPath)

 

 

If Mid(strQualifiedPath,intN,1) = "" Then

 

Exit For

 

Else

 

GetCustomer = GetCustomer & Mid(strQualifiedPath,intN,1)

 

End if

 

Next

 

End Function

 

 

Function GetPartNumber(strQualifiedPath)

 

Dim intN

Dim intCount

Dim strCustomer

 

strCustomer = GetCustomer(strQualifiedPath)

 

For intN = 4 To Len(strQualifiedPath)

 

If Mid(strQualifiedPath,intN,1) = "" Then

 

intCount = intCount + 1

 

If intCount = 2 then

Exit For

End if

 

Else

 

GetPartNumber = GetPartNumber & Mid(strQualifiedPath,intN,1)

 

End if

 

Next

 

GetPartNumber = Replace(GetPartNumber, strCustomer, vbNullString)

 

End Function

 

[ 03-12-2007, 10:57 AM: Message edited by: SAIPEM ]

Link to comment
Share on other sites

OK

I went from this

 

code:

'///////////////// My Global Variables //////////

 

 

 

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

 

'On Error Resume Next

 

' -- Check for drawing

If IsDrawing Then

 

 

Dim companyname

Dim Program

 

 

Do 'ask until a real company name is entered

companyname=Trim(AskString("Enter Company's Name",""))

Loop While companyname="Company Name?" Or companyname="((ESC))" Or companyname=""

 

Do 'ask until a real program number is used

Program=Trim(AskString("Enter Part Number and Rev.",""))

Loop While Program="Part number?" Or Program="" Or Program="((ESC))"

 

 

If Not MakeFolders(companyname, Program) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

 


to this:

 

code:

'///////////////// My Global Variables //////////

 

 

 

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

 

Sub Main()

 

MsgBox GetCustomer("Z:companynameprogramsourceptogram.mcx")

MsgBox GetPartNumber("Z:companynameprogramsourceprogram.mcx")

 

End Sub

 

 

Function GetCustomer(strQualifiedPath)

 

Dim intN

 

For intN = 4 To Len(strQualifiedPath)

 

 

If Mid(strQualifiedPath,intN,1) = "" Then

 

Exit For

 

Else

 

GetCustomer = GetCustomer & Mid(strQualifiedPath,intN,1)

 

End if

 

Next

 

End Function

 

 

Function GetPartNumber(strQualifiedPath)

 

Dim intN

Dim intCount

Dim strCustomer

 

strCustomer = GetCustomer(strQualifiedPath)

 

For intN = 4 To Len(strQualifiedPath)

 

If Mid(strQualifiedPath,intN,1) = "" Then

 

intCount = intCount + 1

 

If intCount = 2 then

Exit For

End if

 

Else

 

GetPartNumber = GetPartNumber & Mid(strQualifiedPath,intN,1)

 

End if

 

Next

 

GetPartNumber = Replace(GetPartNumber, strCustomer, vbNullString)

 

End Function

 


and it gives me an error

IActiveScriptSite::OnScriptError()

Line: End If

Link to comment
Share on other sites
Guest SAIPEM

code:

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

Sub Main()

Dim strName

strName = GetCurrentFileName

ShowString GetCustomer(strName)

ShowString GetPartNumber(strName)

 

End Sub

 

Function GetCustomer(strQualifiedPath)

 

Dim intN

 

For intN = 4 To Len(strQualifiedPath)

 

 

If Mid(strQualifiedPath,intN,1) = "" Then

 

Exit For

 

Else

 

GetCustomer = GetCustomer & Mid(strQualifiedPath,intN,1)

 

End If

 

Next

 

End Function

 

 

Function GetPartNumber(strQualifiedPath)

 

Dim intN

Dim intCount

Dim strCustomer

 

strCustomer = GetCustomer(strQualifiedPath)

 

For intN = 4 To Len(strQualifiedPath)

 

If Mid(strQualifiedPath,intN,1) = "" Then

 

intCount = intCount + 1

 

If intCount = 2 Then

Exit For

End If

 

Else

 

GetPartNumber = GetPartNumber & Mid(strQualifiedPath,intN,1)

 

End If

 

Next

 

GetPartNumber = Replace(GetPartNumber, strCustomer, vbNullString)

 

End Function

Link to comment
Share on other sites

Replace the Msgbox calls with ShowString()

 

code:

' -- Start Script

Call Main()

 

 

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

' Sub Declaration

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

 

Sub Main()

 

ShowString(GetCustomer("Z:companynameprogramsourceptogram.mcx"))

ShowString(GetPartNumber("Z:companynameprogramsourceprogram.mcx"))

 

End Sub

 

 

Function GetCustomer(strQualifiedPath)

 

Dim intN

 

For intN = 4 To Len(strQualifiedPath)

If Mid(strQualifiedPath,intN,1) = "" Then

Exit For

Else

GetCustomer = GetCustomer & Mid(strQualifiedPath,intN,1)

End If

 

Next

 

End Function

 

 

Function GetPartNumber(strQualifiedPath)

 

Dim intN

Dim intCount

Dim strCustomer

 

strCustomer = GetCustomer(strQualifiedPath)

 

For intN = 4 To Len(strQualifiedPath)

 

If Mid(strQualifiedPath,intN,1) = "" Then

intCount = intCount + 1

 

If intCount = 2 Then

Exit For

End If

 

Else

 

GetPartNumber = GetPartNumber & Mid(strQualifiedPath,intN,1)

 

End If

 

Next

 

GetPartNumber = Replace(GetPartNumber, strCustomer, vbNullString)

 

End Function

Link to comment
Share on other sites

Ok thanks for all the help. Please don't shoot me. I am trying to figure this out. I have to change my show string line from this

ShowString(GetCustomer("Z:companynameprogramsourceptogram.mcx"))

ShowString(GetPartNumber("Z:companynameprogramsourceprogram.mcx"))

 

To this:

 

ShowString(GetCustomer("WAIKIKIMSProgramscompanynameprogramsourceprogram.mcx"))

ShowString(GetPartNumber("WAIKIKIMSProgramscompanynameprogramsourceprogram.mcx"))

 

will this mess up the rest of the statments.

 

Also I'm getting an "end if" error?

Link to comment
Share on other sites

Post your code like here: http://xodus.pastebin.ca/new.php and do VB.NET highlighting so we can read it better smile.gif You're IDE should give you the line where there error is and everything?

 

I'm a C# guy but to replace string / char's I would do (This is implying that is an escape character like in C#, if it's not, you don't have to use 2 and 4!)

code:

foo = GetCustomer.ToString;

 

foo = foo.Replace("","");

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