hexagon logo

How to access PC-DMIS Arrays using the Basic Script Editor?

HI everyone, 

First post here so please forgive any lack of clarity in the question.

I'm trying to pass the hit array from a scan to the Basic Script editor in order to write the measured data to a comma delimited file for further investigation on non-conforming hardware. I've read other examples on the forums but none seems to be doing what I need them to do and I can't figure this one out myself.

When I execute this code as it is now, the MsgBox command prints a 0 and the File I/O commands also prints a 0. So I don't think the data is being passed in a way that is accessible.

Any help would be greatly appreciated and let me know if any additional information is needed for clarification.

Thanks!

-Corey

PCDMIS code:

ASSIGN/X_ARRAY=ARRAY(SCN_13_1.HIT[1..SCN_13_1.NUMHITS].X)

CS2 =SCRIPT/FILENAME= D:\PCDMIS_2019\Test\Test_JOBS\OP_test\POINT_EXPORT.BAS
FUNCTION/Main,SHOW=YES,,
STARTSCRIPT/
ENDSCRIPT/

Below is a snip of the BASIC code currently:

Option Explicit

Public objFSO, objShell As Object
Public PCDApp, PCDPartProgram, PCDCommands, PCDCommand, retval As Object
Public objFile, objFolder As Object

Public xArrayOut As Object
Public xArrayOutIndex As Object
Public xArray As Object

Sub main()

Set PCDApp=CreateObject("PCDLRN.Application")
Set PCDPartProgram=PCDApp.ActivePartProgram
Set PCDCommands=PCDPartProgram.Commands
Set xArray = PCDPartProgram.GetVariableValue("X_ARRAY")
Set numberHits = PCDPartProgram.GetVariableValue("NUMHITS")

Dim tempOut As String
Dim counter As Long
Dim Start_Time As Object

counter = numberHits.LongValue
MsgBox "Counter Variable: " & counter

' Dim xArray As PCDLRN.Variable
Dim testfile As String
testFile = "D:\PCDMIS_2019\TPCE\3074T58P01_Jobs\Op200\point_data_test.txt"
Dim i As Long
For i = 1 To counter
Set xArrayOutIndex = xArray.GetArrayIndexValue(i)
'xArrayOut = xArrayOutIndex(i).LongValue
'tempOut = str(xArrayOut(i))
MsgBox xArrayOutIndex.LongValue, 0, "Title"
Open testfile For Output As #1
Print #1, xArrayOutindex.longValue
Close #1
Next i

MsgBox "End Loop"


Set Start_Time = PCDPartProgram.GetVariableValue("V2")
'Dim tempOut As String
tempOut = Start_Time.LongValue
MsgBox "Test Var Value: " & Start_time.longvalue
'Set yArray = PCDPartProgram.GetVariableValue("Y_ARRAY")
'Set zArray = PCDPartProgram.GetVariableValue("Z_ARRAY")

End Sub

Parents Reply Children
  • The first post is actually the thread I was referencing, but I'm having trouble accessing the actual array data. The file I/O is writing 0 to the output file and I'm not sure exactly why that is.

  • Have you executed this program already? Sometimes the variables need to be executed first.

  • This worked for me. YMMV. You do have to make sure the program runs through the assignment lines prior to the script execution, or you will receive errors. Sorry for the formatting. I can't seem to post formatted code anymore in the forum.

    Option Explicit

    Public pcdApp As Object
    Public pcdPart As Object
    Public pcdVar As Object

    Public pcdTemp As Object
    Public pcdX As Object
    Public pcdY As Object

    Sub Main
    ' On Error GoTo Clean:
    Dim I As Long, outString As String

    Set pcdApp = GetObject(Chr$(0), "PCDLRN.Application")
    Set pcdPart = pcdApp.ActivePartProgram
    Set pcdVar = pcdPart.GetVariableValue("X_ARRAY")

    Set pcdTemp = pcdVar.GetArrayIndexValue(1)

    For I = 1 To pcdTemp.GetArrayUpperBound - 1
    Set pcdX = pcdTemp.GetArrayIndexValue(I)
    outString = outString & pcdX.DoubleValue & ", "
    Next I

    MsgBox outString, 0, "X" : outString = ""

    Set pcdVar = pcdPart.GetVariableValue("Y_ARRAY")

    Set pcdTemp = pcdVar.GetArrayIndexValue(1)

    For I = 1 To pcdTemp.GetArrayUpperBound - 1
    Set pcdY = pcdTemp.GetArrayIndexValue(I)
    outString = outString & pcdY.DoubleValue & ", "
    Next I

    MsgBox outString, 0, "Y"

    Clean:

    Set pcdVar = Nothing
    Set pcdPart = Nothing
    Set pcdApp = Nothing
    End Sub