Comment Script

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

  • Comment Script

    I was working on this script to help quickly insert comments into a program for reporting purposes and thought I would share with people to get feedback and maybe answer a couple of questions.

    The way the script works is it asks the user to enter the number of comments to insert with an input box, then it adds numbered (001,002,etc) $$ comments based on the number entered.

    Everything works well for me when I use Excel VBA, but I get errors when using the PC-Dmis basic editor. I'm aware there are differences between the two, but I'm not really sure what the key differences are. So if anyone has input on that or how to fix my script to work INSIDE the pc-dmis basic editor, I would greatly appreciate it.

    Below is the working code for Excel VBA:
    Code:
    Sub QuickPCDComment()
    
    Dim DmisApp As Object
    Dim DmisPart As Object
    Dim DmisCommands As Object
    Dim DmisCommand As Object
    
    
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
    
    
    Dim inputAnswer As Integer
    
        inputAnswer = InputBox("Enter number of comments to insert (zero ends loop):")
    
    '''Displays PC-DMIS Application
    
    DmisApp.Visible = True
    DmisApp.SetActive
    DmisApp.Maximize
    
    If inputAnswer < 10 Then
    
    '''Input entered below 10
    
    Dim counter
    
    Dim commentNumber As String
    
        counter = 0
    
        commentNumber = 1
    
    Do While counter < inputAnswer
    
       Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
        DmisCommand.Marked = True
        retval = DmisCommand.PutText("", ID, 0)
        retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
        retval = DmisCommand.PutText("00" + commentNumber, COMMENT_FIELD, 1)
        retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)
    
        counter = counter + 1
    
        commentNumber = commentNumber + 1
    
    Loop
    
    Else
    
    '''Input entered above 10
    
    Dim counter2
    
    Dim commentNumber2 As String
    
        counter2 = 0
    
        commentNumber2 = 1
    
    '''Comments # 1-9
    
    Do While counter2 < 9
    
       Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
        DmisCommand.Marked = True
        retval = DmisCommand.PutText("", ID, 0)
        retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
        retval = DmisCommand.PutText("00" + commentNumber2, COMMENT_FIELD, 1)
        retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)
    
        counter2 = counter2 + 1
    
        commentNumber2 = commentNumber2 + 1
    
    Loop
    
    
    '''Comments # 10-inputAnswer
    
    Do While counter2 < inputAnswer
    
       Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
        DmisCommand.Marked = True
        retval = DmisCommand.PutText("", ID, 0)
        retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
        retval = DmisCommand.PutText("0" + commentNumber2, COMMENT_FIELD, 1)
        retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)
    
        counter2 = counter2 + 1
    
        commentNumber2 = commentNumber2 + 1
    
    Loop
    
    
    End If
    
    
    
    End Sub
    Below is sample code for reference to change to a REPT comment
    Code:
      Set DmisCommand = DmisCommands.Add(SET_COMMENT, TRUE)
        DmisCommand.Marked = TRUE
      ' Set Id  =
        retval = DmisCommand.PutText ("", ID, 0)
      ' Set Comment Type  = REPT
        retval = DmisCommand.SetToggleString (2, COMMENT_TYPE, 0)
      ' Set Comment Item 1 = Please Edit Comment Text!
        retval = DmisCommand.PutText ("Please Edit Comment Text!", COMMENT_FIELD, 1)

  • #2
    Is this what you need? See post #16
    How do you pull variable values from PCD program using VB.NET? I know how to do it with VBA and BASIC etc.... but how do you do it with VB.NET, I can get variable
    PcDmis 2015.1 SP10 CAD++
    Global 7-10-7 DC800S

    Comment


    • #3
      Yeah that looks a lot more sophisticated than what I've got going on currently. I'm studying your code from the earlier posts in that thread and have noticed some differences like in the beginning..
      "Public Class Form1 Private Sub CSV_Out_Click(sender As Object, e As EventArgs)" This is written in .NET framework correct? I've been trying to migrate from using Excel VBA to visual studio (or something more visual basic friendly), but some of the syntax and stuff is slightly different so my trouble is getting my working scripts with VBA to work in visual studio or PCD Basic Editor.

      Comment


      • #4
        Originally posted by CodeWarrior View Post
        Yeah that looks a lot more sophisticated than what I've got going on currently. I'm studying your code from the earlier posts in that thread and have noticed some differences like in the beginning..
        "Public Class Form1 Private Sub CSV_Out_Click(sender As Object, e As EventArgs)" This is written in .NET framework correct? I've been trying to migrate from using Excel VBA to visual studio (or something more visual basic friendly), but some of the syntax and stuff is slightly different so my trouble is getting my working scripts with VBA to work in visual studio or PCD Basic Editor.
        Post something you'd like to have converted over, maybe one of us will do it for you (pick the shortest one). Sometimes that's all a novice coder needs is an example that really interests them. Once the light bulb comes on we won't hear from you for a while... you'll be busy in the dungeon coding away.
        PcDmis 2015.1 SP10 CAD++
        Global 7-10-7 DC800S

        Comment


        • #5
          You're right about example code turning on a light bulb, I've learned so much by just googling and searching threads. When I feel like I hit a wall, another forum thread will pop-up and turn the bulb back on.

          The code below works with VBA, not inside PC-DMIS Basic Editor.
          Code:
          Sub TestComment()
          
          Dim DmisApp As Object
          Dim DmisPart As Object
          Dim DmisCommands As Object
          Dim DmisCommand As Object
          
          
            Set DmisApp = CreateObject("PCDLRN.Application")
            Set DmisPart = DmisApp.ActivePartProgram
            Set DmisCommands = DmisPart.Commands
          
          
          
             Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
              DmisCommand.Marked = True
              retval = DmisCommand.PutText("", ID, 0)
              retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
              retval = DmisCommand.PutText("00", COMMENT_FIELD, 1)
              retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)
          
          
          End Sub

          Comment


          • #6
            Give it the name "Sub Main()" instead - works for me in 2019 R2 SP1.

            Or add

            Code:
            Sub Main()
             TestComment
            End Sub
            to the Basic window. The Run button only runs the Main() sub, not the current sub as Excel VBA does.
            AndersI
            SW support - Hexagon Metrology Nordic AB

            Comment


            • #7
              Originally posted by CodeWarrior View Post
              You're right about example code turning on a light bulb, I've learned so much by just googling and searching threads. When I feel like I hit a wall, another forum thread will pop-up and turn the bulb back on.
              First off I would look at:
              Code:
              CS1        =SCRIPT/FILENAME= V1
                          FUNCTION/Main,SHOW=YES,,
                          STARTSCRIPT/
              within your part routine.

              What does this line say:

              Code:
                          FUNCTION/[COLOR=#FF0000]Main[/COLOR],SHOW=YES,,
              It's calling a sub/function that doesn't exist. I would change it to call your sub name, "TestComment", or change your sub name to "Main".

              EDIT:
              Or if you actually read AndersI post (obviously I didn't the first time) his is the best solution out of the 3 possibilities covered thus far IMO.
              Last edited by Kp61dude!; 10-02-2019, 01:20 PM.
              PcDmis 2015.1 SP10 CAD++
              Global 7-10-7 DC800S

              Comment


              • #8
                I changed it to what AndersI suggested within the script to get it working. Now I understand that "FUNCTION/Main" within PC-DMIS is calling Sub Main () within the script.

                Thank you both for the explanation.

                This has gotten me thinking and prompted another question for me. Is it common/good practice to use ONE bas script file containing multiple "Subs/Functions" and then calling the script in different spots in the PC-DMIS program?

                Example Script:
                Code:
                Sub [COLOR=#FF0000]Main[/COLOR] ()
                stuff
                End Sub
                
                Sub [COLOR=#FF0000]Alt [/COLOR]()
                stuff
                End Sub
                
                Sub [COLOR=#FF0000]Alt2[/COLOR] ()
                stuff
                End Sub
                In the PC-DMIS program..
                Code:
                CS1 =SCRIPT/FILENAME= V1
                FUNCTION/[COLOR=#FF0000]Main[/COLOR],SHOW=YES,,
                STARTSCRIPT/
                
                stuff..
                
                CS2 =SCRIPT/FILENAME= V1
                FUNCTION/[COLOR=#FF0000]Alt[/COLOR],SHOW=YES,,
                STARTSCRIPT/
                
                stuff..
                
                CS3 =SCRIPT/FILENAME= V1
                FUNCTION/[COLOR=#FF0000]Alt2[/COLOR],SHOW=YES,,
                STARTSCRIPT/

                Comment


                • AndersI
                  AndersI commented
                  Editing a comment
                  Definitely, yes!

              • #9
                Originally posted by CodeWarrior View Post
                I changed it to what AndersI suggested within the script to get it working. Now I understand that "FUNCTION/Main" within PC-DMIS is calling Sub Main () within the script.

                Thank you both for the explanation.

                This has gotten me thinking and prompted another question for me. Is it common/good practice to use ONE bas script file containing multiple "Subs/Functions" and then calling the script in different spots in the PC-DMIS program?

                Example Script:
                Code:
                Sub [COLOR=#FF0000]Main[/COLOR] ()
                stuff
                End Sub
                
                Sub [COLOR=#FF0000]Alt [/COLOR]()
                stuff
                End Sub
                
                Sub [COLOR=#FF0000]Alt2[/COLOR] ()
                stuff
                End Sub
                In the PC-DMIS program..
                Code:
                CS1 =SCRIPT/FILENAME= V1
                FUNCTION/[COLOR=#FF0000]Main[/COLOR],SHOW=YES,,
                STARTSCRIPT/
                
                stuff..
                
                CS2 =SCRIPT/FILENAME= V1
                FUNCTION/[COLOR=#FF0000]Alt[/COLOR],SHOW=YES,,
                STARTSCRIPT/
                
                stuff..
                
                CS3 =SCRIPT/FILENAME= V1
                FUNCTION/[COLOR=#FF0000]Alt2[/COLOR],SHOW=YES,,
                STARTSCRIPT/
                Sure that's a valid way and it would be my preference to keep it all in one .BAS file vs creating individual ones that sometimes get difficult to keep track of and/or maintain. It's called a "library" of scripts that are all conveniently located in one place (keep backups of backups of backups!). And remember duplicated code is bad, so please Don’t Repeat Yourself (DRY), and also Keep It Simple, Stupid (KISS). Be lazy the right way - write code only once!
                PcDmis 2015.1 SP10 CAD++
                Global 7-10-7 DC800S

                Comment


                • #10
                  Originally posted by CodeWarrior View Post
                  Is it common/good practice to use ONE bas script file...
                  Yes, and no. Depends…

                  If your script functions are specific to a certain part program, best to keep them together in one file, preferrably named after the pp, and stored in the same folder.

                  If your script functions are generic (like your COMMENT script), best to collect them in one or more .BAS files, out of the part programs folder hierarchy. This will with time give you a library of useful functions that can be used with any pp.
                  AndersI
                  SW support - Hexagon Metrology Nordic AB

                  Comment


                  • #11
                    That makes a lot of sense. Thank you for your insight. Currently I have everything set up where most of the scripts inside my programs are part specific (I have a billion scripts now). I wanted to start adding in more functions to my scripts and was thinking it would be incredibly cumbersome to update and re-update all of them constantly.

                    One of the things I want to start adding to my scripts is variables based on text files and stuff that are being updated on a day to day week to week basis and having things in one place will make that much easier to edit. I know that wouldn't apply to this comment script, but I'm glad I got that working as a toolbar button

                    Comment

                    Related Topics

                    Collapse

                    Working...
                    X