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:

Auto shapes coordinate problem.


Recommended Posts

I'm new at mastercam & VBA scpirt. I'm trying to write a script to auto draw Rectangles into the Mastercam 9. I have 1 text file with the original centre location of the objects, and 1 file is the objects size with center point. When it run till the end of the command it show error as " Microsoft VBScript runtime error Type mismatch "MakeRectangle' IActiveScriptSite::OnScriptError() Line: OK buttom"

 

Below is my script :

=================================================

Call Main()

Sub Main()

 

Const File_name1 = "C:mcam9vbtestTestData.txt"

Const File_name2 = "C:mcam9vbtestnetlist.txt"

 

Dim FSO,objTextFile1,objTextFile2,i,n,Lines_array1(99),Lines_array2(99),Row2,Rowa,Rect,color,level

 

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objTextFile1 = FSO.OpenTextFile(File_name1, 1)

Set objTextFile2 = FSO.OpenTextFile(File_name2, 1)

i = 0

 

Do Until objTextFile1.AtEndOfStream

Lines_array1(i) = objTextFile1.ReadLine

i = i + 1

Loop

 

n = 0

Do Until objTextFile2.AtEndOfStream

Lines_array2(n) = objTextFile2.ReadLine

n = n + 1

Loop

 

a = 1

b = 1

 

Row2 = Split(Lines_array1(a),",",-1,0)

Rowa = Split(Lines_array2(B),",",-1,0)

 

If Row2(0) = Rowa(0) Then

Set Rect = New McRe

With Rect

.X1 = Rowa(1) - Row2(4)

.X2 = Row2(4) + Rowa(1)

.Y1 = Rowa(2) - Row2(5)

.Y2 = Rowa(2) + Row2(5)

End With

 

Call CreateRectangle(Rect, mcCONSTRUCTION_COLOR_CURRENT, mcCONSTRUCTION_COLOR_CURRENT)

 

End Sub

Link to comment
Share on other sites

Hi Ragdemai,

 

There were two places causing a problem with the above script, first the variables a and b were not declared and secondly the CreateRectangle() function accepts double values from an instance of McRe, the values you were assigning from the text files are strings, adding CDbl() to those values fixes it.

 

Check you e-mail for the edited script.

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