Basic Script

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

  • Basic Script

    I am running PCDMIS 4.0 Release on a ONE 775.

    I have written a basic script that I want to execute at the absolute end of my CMM program. The script gets the name of PDF report that PCDMIS ceated. It also collects some user input information (P.O. Number, Receiver Number, Vendor Name). Then it simply writes this information to a text file for processing by a third-party indexing program. The script successfully completes its task but PCDMIS crashes. I have the script available to email/post if anyone would like to look at it. Any ideas while I wait for a call back from Tech Support?

  • #2
    tech support will probably call you next week. Sounds like it's a 4.0 issue and not the script. Post or email me the program &/or script.
    I used to be high on life but I built up a tolerance.

    Brown & Sharpe Global Advantage
    PCDMIS CAD++ v2011mr2
    PH10MQ/SP600M


    sigpic

    Comment


    • #3
      Well, the current expert of 4.0 is on a timeout. He would probably say "Upgrade to 4.1 before going any further..."
      Links to my utilities for PCDMIS

      Comment


      • #4
        Here is the code...I tried to add comments to make it easier to understand...


        Sub Main()
        'The purpose of this script is to generate a text file for DataMagine indexing
        'The index file needs to have the following information, formatted as below:
        ' PDFFILENAME|PARTNAME|DWGNUMBER|DWGREVISION|PONUMBE R|RECEIVERNUMBER|VENDORNAME
        'The PDFFILENAME is found by listing out files in the CMMOutpu folder
        'The PARTNAME is taken from the PCDMIS Part Name
        'The DWGNUMBER is taken from the PCDMIS Revision Number
        'The DWGREVISION is taken from the PCDMIS Serial Number
        'PO, Receiver, and Vendor are taken from PCDMIS commands of CommandType 1
        'Once all of this is determined, the PDFFILENAME will be moved to the server from
        ' the CMMOutput folder and the index file will be written on the server.

        Dim App As Object
        Dim Part As Object
        Dim Cmds As Object
        Dim Cmd As Object
        Dim DCmd As Object
        Dim sExtendedInfo As String
        Dim sProcName As String
        Dim sErrorText As String
        Dim commentSeqNumber As Integer
        Dim dimSeqNumber As Integer
        Dim ch As Integer
        Dim questString As String
        Dim RetVal As Integer
        Dim CMMOutputFile As String
        Dim DataMagineData As String

        On Error GoTo ErrorTrap: sProcName = "Main"
        commentSeqNumber = 1
        dimSeqNumber = 1

        ' Create new PCDMIS program Object ...
        sExtendedInfo = "Error creating a new PCDMIS program object."
        Set App = CreateObject("PCDLRN.Application")

        ' Open current PCDMIS part program ...
        sExtendedInfo = "Error opening current PCDMIS program."
        Set Part = App.ActivePartProgram

        ' Open PCDMIS program 'commands' collection ...
        sExtendedInfo = "Error referencing PCDMIS 'commands' collection."
        Set Cmds = Part.Commands

        ' Start creating the DataMagine Index file Output String
        sExtendedInfo = "Error creating DataMagine index file."
        DataMagineData = ""
        CMMOutputFile = Dir("c:\CMMOutput\" & Part.partname & "*")
        DataMagineData = CMMOutputFile & "|" & Part.partname & "|" & Part.revisionnumber & "|" & Part.serialnumber & "|"

        sExtendedInfo = "Error accessing commands."
        For Each Cmd In Cmds
        ' Get the PO number And other information typed In by the user ...
        If (Cmd.isComment) Then
        Set DCmd = Cmd.CommentCommand
        If (DCmd.CommentType = 1) Then
        questionstr = ""
        For ch = 1 To Len(DCmd.Comment)
        If (Mid(DCmd.Comment, ch, 1) <> "'") Then
        questionstr = questionstr + Mid(DCmd.Comment, ch, 1)
        End If
        Next ch
        Select Case Left(questionstr, 6)
        Case Is = "P.O. N"
        DataMagineData = DataMagineData & Mid(questionstr, (InStr(1, questionstr, ":") + 2), Len(questionstr) - InStr(1, questionstr, ":")) & "|"
        Case Is = "Receiv"
        DataMagineData = DataMagineData & Mid(questionstr, (InStr(1, questionstr, ":") + 2), Len(questionstr) - InStr(1, questionstr, ":")) & "|"
        Case Is = "Vendor"
        DataMagineData = DataMagineData & Mid(questionstr, (InStr(1, questionstr, ":") + 2), Len(questionstr) - InStr(1, questionstr, ":"))
        End Select
        sExtendedInfo = "Error getting input information for index file."
        End If
        End If
        Next Cmd

        'Commands below will eventually write the CMMIndex file and move the PDF file to the server
        Open "C:\CMMOutput\CMMIndex.txt" For Append As #1
        Print #1, DataMagineData
        Close

        Exit Sub

        ErrorTrap:

        ' Format the text To be displayed In the message box ...
        sErrorText = "Routine: " & sRoutine & Chr(13) & _
        "Error Number: " & Err.Number & Chr(13) & _
        "Error Source: " & Err.Source & Chr(13) & _
        "Error Description: " & Err.Description & Chr(13) & _
        "Extended Info: " & sExtendedInfo

        ' Show the message box ...
        errResult = MsgBox(sErrorText, vbAbortRetryIgnore Or vbCritical, "Error")

        Select Case errResult
        Case vbAbort
        Exit Function
        Case vbRetry
        ' Resume
        Case vbIgnore
        Resume Next
        End Select

        End Sub

        Comment


        • #5
          When PCDMIS crashes. What does the error say?
          I used to be high on life but I built up a tolerance.

          Brown & Sharpe Global Advantage
          PCDMIS CAD++ v2011mr2
          PH10MQ/SP600M


          sigpic

          Comment


          • #6
            Why are you using a .bas to write to a text file when PCDMIS will do it for you? Is it simply because you need to get the .pdf filename to include in the text file and manage it's location? I must be missing something in your code because it looks good other than you may want to early bind the PCDMIS application object. But that should not cause a crash at the end to my knowledge. Also you use the Close command without your file name variable (#1) but again I don't believe that would cause a crash either. I'll look at it some more maybe even comment some of it and run it when I get a chance but like Underspec said does PCDMIS throw an error or just crash?

            Craig
            <internet bumper sticker goes here>

            Comment


            • #7
              Craiger is right. You can use the file write commands within PCDMIS to write to a text file.

              From looking at the code, this is an independant program? If you are calling it from within PCDMIS you don't need the:

              Create new PCDMIS program Object ...
              sExtendedInfo = "Error creating a new PCDMIS program object."
              Set App = CreateObject("PCDLRN.Application")
              I used to be high on life but I built up a tolerance.

              Brown & Sharpe Global Advantage
              PCDMIS CAD++ v2011mr2
              PH10MQ/SP600M


              sigpic

              Comment


              • #8
                Originally posted by Underspec
                Craiger is right. You can use the file write commands within PCDMIS to write to a text file.

                From looking at the code, this is an independant program? If you are calling it from within PCDMIS you don't need the:

                Create new PCDMIS program Object ...
                sExtendedInfo = "Error creating a new PCDMIS program object."
                Set App = CreateObject("PCDLRN.Application")
                Yeah he needs that that is the application object he sets his reference to for automating PCDMIS that is where he is late binding (shouldn't be a prob though). I'm thinking the reason he runs it as a .bas is because he needs to get the filename of the .pdf then move it to another directory and he is using VB for that. There may be a way around that though. I'm not sure what ways you can name the .pdf that pcdmis generates but depending on the flexability of that and the ability to output it to the directory he wants then he may be able to do what he wants with PCDMIS. I'm curious why he is crashing at the end though.

                KasonQC do you say that the .bas executes completely in that it appends the data and moves your .pdf or does some portion not happen? If it does you could add a lock condition to the File Open (on a test file) then when PCDMIS crashes see if you can access that file from another means, if you can't then that is probably where it is hung up. I'd try Close #1 instead of just close. You may also want to try to get a free file handle in case for some reason #1 is tied up but if you can append my guess is that your handle is not the problem.

                Craig
                <internet bumper sticker goes here>

                Comment


                • #9
                  Ok, maybe this is a dumb question and maybe I am missing something.

                  Why all of the gymnastics to do what seems easy. Instead of doing all of this in PCDMIS, why cant you use a watchdog program(External) that watches the PDF folder and then copies whatever shows up to a specific destination on the server. Doing this part is PCDMIS seems rather a pain for ever program.

                  The other part (the program info) - cant that be simply written to a txt file within PCDMIS without the script.
                  Links to my utilities for PCDMIS

                  Comment


                  • #10
                    Try adding a comment as the last line in your part program but do not mark it for execution. Maybe pcdmis does not like having the script as the very last command. Just a thought.

                    Comment


                    • #11
                      Just my 2 cents: a few times in the last week, when I ran into an unexplainable problems with (internal and external code) execution, I had to completely shutdown PC-DMIS and get back in. That resolved the issues (for a while).


                      Jan.
                      ***************************
                      PC-DMIS/NC 2010MR3; 15 December 2010; running on 18 machine tools.
                      Romer Infinite; PC-DMIS 2010 MR3; 15 December 2010.

                      Comment


                      • #12
                        Originally posted by Underspec
                        When PCDMIS crashes. What does the error say?
                        I am getting the wonderful Microsoft apology error "...this program must close, we are sorry for the inconvenience..."

                        Comment


                        • #13
                          Originally posted by craiger_ny
                          Why are you using a .bas to write to a text file when PCDMIS will do it for you? Is it simply because you need to get the .pdf filename to include in the text file and manage it's location? ... I'll look at it some more maybe even comment some of it and run it when I get a chance but like Underspec said does PCDMIS throw an error or just crash?

                          Craig
                          Yes, I am using the .bas just to get the filename of the .PDF file and later I am going to use it to move the file to the server so I can get the report into our document database.

                          PCDMIS does not give an error itself, it is the Microsoft error that the application must close.

                          Comment


                          • #14
                            Click details to see what is causing the error.
                            I used to be high on life but I built up a tolerance.

                            Brown & Sharpe Global Advantage
                            PCDMIS CAD++ v2011mr2
                            PH10MQ/SP600M


                            sigpic

                            Comment

                            Related Topics

                            Collapse

                            Working...
                            X