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 !!! Thank You again for this great script. If I use ASSIGN/VariableName to set variables in PC-DMIS, can I get them transferred into the VB script like I do for Part ? I tried the following and it doesn't work for the ASSIGN/MODEL_NO = 634.

    Set PartNo = ActivePart.GetVariableValue(MODEL_NO) [With or without "" 's even...]

    CMDfile = App.ActivePartProgram.Path & PartNo & ".txt" [Doesn't like PartNo of course]

    Note---Using PC-DMIS 4.2 MR2


    Looks like it should work. You must have a file in the partprogram path called 634.txt.
Reply
  • vpt.se !!! Thank You again for this great script. If I use ASSIGN/VariableName to set variables in PC-DMIS, can I get them transferred into the VB script like I do for Part ? I tried the following and it doesn't work for the ASSIGN/MODEL_NO = 634.

    Set PartNo = ActivePart.GetVariableValue(MODEL_NO) [With or without "" 's even...]

    CMDfile = App.ActivePartProgram.Path & PartNo & ".txt" [Doesn't like PartNo of course]

    Note---Using PC-DMIS 4.2 MR2


    Looks like it should work. You must have a file in the partprogram path called 634.txt.
Children
No Data