hexagon logo

Read values from a textfile to populate variables in partprogram

Feel free to tweak it to suit your own needs.

' Takes definitions from a textfile and adds these as ASSIGNMENT
' commands in the activepartprogram.
'
' The format of the definitions in the textfile:
' 
' <VARIABLE_NAME>$<VARIABLE_VALUE>
'
' Ex.
'
' V1$"this is a string"
' V2$123.456
' V3$CIR1.X
' MY_VAR$"my variable"
'
'
' (c) vpt.se 2009-27-08
'

sub Main

Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
Set PCDApp = CreateObject("PCDLRN.Application")
Set PCDPartPrograms = PCDApp.PartPrograms
Set PCDPartProgram = PCDApp.ActivePartProgram
Set PCDCommands = PCDPartProgram.Commands

Dim CMDline, CMDvar, CMDval, CMDfile, delimpos, LineCnt

' the cmds.txt must reside in the activepartprograms folder!
CMDfile = PCDApp.ActivePartProgram.Path & "cmds.txt"
' a linecounter for navigation in the cmds.txt file (if errors occurs)
LineCnt = 0

Open CMDfile for input as #1
do while not EOF(1)
line input #1, CMDline
LineCnt = LineCnt + 1 ' we have read a line, increment the counter
delimpos = instr(1, CMDline, "$") ' find the delimiter
if delimpos then ' delimiter found
  CMDvar = left(CMDline, delimpos - 1) ' get text left of delimiter
  CMDval = right(CMDline, len(CMDline) - delimpos) ' get text right of delimiter
  CMDval = left(CMDval, len(CMDval)-1) ' get rid of the carriage return at the end
    set PCDCommand = PCDCommands.Add(195, True) ' add an assignment command to the program
    retval = PCDCommand.PutText(CMDvar, DEST_EXPR, 0) ' set the variable name
    retval = PCDCommand.PutText(CMDval, SRC_EXPR, 0) ' set the variable value
    PCDCommand.ReDraw
    PCDPartProgram.Refresh    
else
  MsgBox "Delimiter not found!" & Chr(13) & "Stopped at line " & LineCnt & "." ' what line lacks the delimiter?
  Exit do ' don't loop through the entire file if delimiter not found
end if
loop
close #1
end sub
Parents
  • vpt.se - This was so cool. Run it and watch PC-DMIS update on the fly. Had to modify it for my taste, but GREAT App to have.

    Also, had to block the PCDPartProgram.Refresh. Kept erroring out. (Runtime error 438 Object doesn't support this property or method.) PC-DMIS 4.2 MR2...

    And, can you tell me why it drops the last character off of lines like these ?

    CBD_X=((C_BORE_DIA_NOM/2)-5)
    CBD_ZCL=C_BORE_ZNOM+2
    TAPER_NOM=(TAPER_MAX+TAPER_MIN)/2
    TAPER_UT=(TAPER_MAX-TAPER_MIN)/2
    TAPER_LT=TAPER_UT*(-1)

    Thanks again.
Reply
  • vpt.se - This was so cool. Run it and watch PC-DMIS update on the fly. Had to modify it for my taste, but GREAT App to have.

    Also, had to block the PCDPartProgram.Refresh. Kept erroring out. (Runtime error 438 Object doesn't support this property or method.) PC-DMIS 4.2 MR2...

    And, can you tell me why it drops the last character off of lines like these ?

    CBD_X=((C_BORE_DIA_NOM/2)-5)
    CBD_ZCL=C_BORE_ZNOM+2
    TAPER_NOM=(TAPER_MAX+TAPER_MIN)/2
    TAPER_UT=(TAPER_MAX-TAPER_MIN)/2
    TAPER_LT=TAPER_UT*(-1)

    Thanks again.
Children
No Data