Info on writting Basic file.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Info on writting Basic file.

    Need some help on writting a *.Bas file. I want to be able send the data to a text file. I have all the variable assaigned. Just cant get them in the text file like I want. Would Just like to have one long column. Hope using a *.bas file it could be easier. I have like 362 variables. Trying to use FILE/WRITELINE,FPTR,
    Would take forever. Any help would be great.
    PCDMIS CAD++ v4.2mr1
    PCDMIS Pro v4.1

  • #2
    try this small example

    Not sure where you're having the trouble exactly, but start out by trying this example -

    ************************************************** ****

    Private Sub Form_Load()

    Dim app As PCDLRN.Application
    Dim cmds As PCDLRN.Commands
    Dim cmd As PCDLRN.Command
    Dim part As PCDLRN.PartProgram

    Set app = CreateObject("PCDLRN.Application")
    Set part = app.ActivePartProgram
    Set cmds = part.Commands

    Dim hourstring As String, timestring_a As String, timestring_b As String, timestring As String

    hourstring = Format(Now, "hh AM/PM")
    If Right(hourstring, 2) = "PM" Then
    hourstring = (Int(Left(hourstring, 2)) + 12)
    Else
    hourstring = Left(hourstring, 2)
    End If
    timestring_a = Format(Now, "yymmdd")
    timestring_b = Format(Now, "mmss")
    ' MsgBox timestring_a + hourstring + timestring_b
    timestring = timestring_a + hourstring + timestring_b + ".txt"


    ' Open file named with timestamp for output
    Open timestring For Output As #1

    For Each cmd In cmds
    If cmd.IsDimension Then
    Print #1, cmd.TypeDescription
    End If
    Next cmd


    Close #1
    ' MsgBox "Finished"
    End

    End Sub

    ************************************************** ****

    If you're working with VB, just paste that into a form, link it to PC-DMIS Object Library, and try it out.

    If you're working with scripts only, then the proper syntax is this -

    ************************************************** ****



    Sub Main()

    Dim app As Object
    Dim cmds As Object
    Dim cmd As Object
    Dim part As Object

    Set app = CreateObject("PCDLRN.Application")
    Set part = app.ActivePartProgram
    Set cmds = part.Commands

    Dim hourstring As String, timestring_a As String, timestring_b As String, timestring As String

    hourstring = Format(Now, "hh AM/PM")
    If Right(hourstring, 2) = "PM" Then
    hourstring = (Int(Left(hourstring, 2)) + 12)
    Else
    hourstring = Left(hourstring, 2)
    End If
    timestring_a = Format(Now, "yymmdd")
    timestring_b = Format(Now, "mmss")
    ' MsgBox timestring_a + hourstring + timestring_b
    timestring = timestring_a + hourstring + timestring_b + ".txt"


    ' Open file named With timestamp For Output
    Open timestring For Output As #1

    For Each cmd In cmds
    If cmd.IsDimension Then
    Print #1, cmd.TypeDescription
    End If
    Next cmd


    Close #1
    ' MsgBox "Finished"


    End Sub


    ************************************************** *****

    The output is merely a description of each command's type but its a good exercise to get started with for output attempts.

    Comment


    • #3
      Don,

      It's been awhile since I've written any codes. This is my first month using PCDmis as well. I will try the code above tomorrow at work. Thanks. My Question is will it use the Variables I already assigned. I assigned them on the Edit screen of PCDmis. I found a code it worked. But I have to put each one in separately. That's alot especially with 362 variables.

      It lookes something like this.
      FPTR =FILE/OPEN,C:\CMM\9630\REPORT.txt,APPEND
      FILE/WRITELINE,FPTR,PARTNUM + "," + V1 + "," + V2 + "," + V3 + "," + V4

      But, I need it to go into the report in a column. Not a row...
      Last edited by drako28; 11-08-2006, 06:41 PM.
      PCDMIS CAD++ v4.2mr1
      PCDMIS Pro v4.1

      Comment


      • #4
        Just a starter program

        Sorry, no. My example was meant to give you an idea of what BASIC scripts and programs can do as a guide to getting started. It was not meant to fully solve your problem.

        I got the impression you had already written some BASIC code but were having trouble with the File I/O part of it. If that is the case, post what you have already so we can work with it and perhaps add a few lines.

        I do not currently have an example that does exactly what you want. . .

        Comment


        • #5
          Perhaps it could be looped. In that case there would be a crarriage return with each itteration. I have not put together the code to test it but maybe the suggestion will put you on the right track...........

          Craig
          <internet bumper sticker goes here>

          Comment


          • #6
            OK

            I almost have it for you. Unfortunately I end up in the dreaded infinite loop. I put a message box in for debugging. It gets each variable in the program and writes it into a column just like you want. However my Do While loop is deadly. For whatever reason it does not evaluate the way I think it should. Let's say you have variables V1 thru V20. I pick up the data then increment to the next variable and assign an object. My thought was when I increment to V21 and assign my object it would be Nothing but for some reason it does not evaluate that way and keeps looping (returning a zero for the .DoubleValue property in each message box). I supose you could instead evaluate the .DoubleValue property and stop the loop itterations when it sees a zero but this will only work if you are absolutely sure that a zero is invalid data.

            Here is my code so far. Perhaps you can tool it so it works for you but please post your solution I'm curious. Maybe Don could help. Like I said it does exactly what you want but it gets caught in an endless loop.


            Code:
            Sub main()
             
            Dim objApp As Object
            Set objApp = CreateObject("PCDLRN.Application")
            Dim objPart As Object
            Set objPart = objApp.ActivePartProgram
            Dim objProgVar As Object
            Set objProgVar = objPart.GetVariableValue("V1")
            Dim strVarName As String
            Dim dblDataToWrite As Double
            Dim strTheFile As String
            strTheFile = "C:\Test.txt"
             
                Open strTheFile For Output As #1
             
            Dim i As Integer
            i = 1
             
            Do While Not objProgVar Is Nothing
             
                dblDataToWrite = objProgVar.DoubleValue
                Write #1, dblDataToWrite
                msgbox(cstr(dblDataToWrite ))
                i = i + 1
                strVarName = "V" & CStr(i)
                Set objProgVar = Nothing
                Set objProgVar = objPart.GetVariableValue(strVarName)
             
            Loop
             
                Close #1
             
            End Sub
            <internet bumper sticker goes here>

            Comment


            • #7
              I had another thought. What are your variables being assigned from? If all they are all certain dimension axis measured values then you could skip the assignment and have the .bas get the dimension measured values and loop through that. I do know how to itterate through that without the ****ed endless loop trap. Plus that would cut down all of your PCDMIS assignment code in the part program. That would be much cleaner. Give us some info on what the specific information is in your part program that you want to write to a file.

              Craig
              <internet bumper sticker goes here>

              Comment


              • #8
                I have about 98 Variables assigned to the Deviations of the Dimensions. The rest are just X Y & Z, of a point.

                Thanks
                Guys
                PCDMIS CAD++ v4.2mr1
                PCDMIS Pro v4.1

                Comment


                • #9
                  OK this will do it for you. This code is dependenat on a couple of things. First your naming convention for variables has to be V1, V2, V3, etc. You will have to recode it if it is not. The file that is created to hold the data in a column is a text file called Test.txt and will be dropped on your C:\ drive, you'll need to recode that if you want it changed. Your PCDMIS part program will need for the very last variable to be assigned "LASTVARIABLE". This .bas can be called by any part program. Each time it is executed it over writes the existing text file or creates one if it does not exist. You will need to recode it if you want to append. Finnaly this will not work on 3.2063, that version does not support .GetVariableValue. I went from 3.2063 to 3.7 it may be supported in 3.5 but I am not positive when it became available, check your documentation.

                  Code:
                  Sub main()
                   
                  Dim objApp As Object
                  Set objApp = CreateObject("PCDLRN.Application")
                  Dim objPart As Object
                  Set objPart = objApp.ActivePartProgram
                  Dim objProgVar As Object
                  Dim strVarName As String
                  strVarName = V1
                  Dim dblDataToWrite As Double
                    Dim strTheFile As String
                    strTheFile = "C:\Test.txt"
                    Open strTheFile For Output As #1
                  Set objProgVar = objPart.GetVariableValue("V1")
                  Dim i As Integer
                  i = 1
                   
                  Do While objProgVar.StringValue <> "LASTVARIABLE"
                   
                      dblDataToWrite = objProgVar.DoubleValue
                      Write #1, dblDataToWrite
                      i = i + 1
                      strVarName = "V" & CStr(i)
                      Set objPartVar = Nothing
                      Set objProgVar = objPart.GetVariableValue(strVarName)
                   
                  Loop
                   
                    Close #1
                   
                  End Sub
                  Here is the PCDMIS code I debugged it on and it worked fine. Note V7, you must have a variable assigned "LASTVARIABLE" and it must be last.

                  Code:
                              ASSIGN/V1 = 1.123
                              ASSIGN/V2 = 4.456
                              ASSIGN/V3 = 7.789
                              ASSIGN/V4 = 9.987
                              ASSIGN/V5 = 6.654
                              ASSIGN/V6 = 3.321
                              ASSIGN/V7 = "LASTVARIABLE"
                  CS1        =SCRIPT/FILENAME= C:\GETVARIABLES.BAS
                              FUNCTION/Main,SHOW=YES,,
                              STARTSCRIPT/
                              ENDSCRIPT/
                  If you have any questions post them or PM me, believe it or not I'm a regular here. It is my hope that you understand this code or will take it upon yourself to make sure you do.

                  Craig
                  <internet bumper sticker goes here>

                  Comment


                  • #10
                    Thanks...

                    Craig,

                    Thanks for the help. Sorry I haven't got back too you. Been tied up with some new jobs. Thanks it worked great.......

                    Would it be a huge file to write or something easy. To take whatever I dimension on a program and put that into a text file as it appears on my report window and just keep appending to it.

                    Thanks
                    PCDMIS CAD++ v4.2mr1
                    PCDMIS Pro v4.1

                    Comment


                    • #11
                      You can print as an *.rtf and one of the options is to append. Check out your print preferences set up. I believe that would be the simplest solution.

                      Craig
                      <internet bumper sticker goes here>

                      Comment

                      Related Topics

                      Collapse

                      Working...
                      X