Insert script at cursor location

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

  • Insert script at cursor location

    I recently created some scripts from PC-DMIS program code that are attached to shortcuts. Once you click on the shortcut, it inserts commonly used codes to the end of the program. I would like it to insert the code wherever the cursor currently is. Is there a way to do this? This code is in the script...
    Code:
     DmisCommands.InsertionPointAfter DmisCommand
    ... and I'm assuming there is something I can do with this, I just don't know what it is. I searched the help file and tried to look on here and haven't found anything yet. Can anyone point me in the right direction?
    Thanks again!

  • #2
    Originally posted by SingularitY View Post
    I recently created some scripts from PC-DMIS program code that are attached to shortcuts. Once you click on the shortcut, it inserts commonly used codes to the end of the program. I would like it to insert the code wherever the cursor currently is. Is there a way to do this? This code is in the script...
    Code:
     DmisCommands.InsertionPointAfter DmisCommand
    ... and I'm assuming there is something I can do with this, I just don't know what it is. I searched the help file and tried to look on here and haven't found anything yet. Can anyone point me in the right direction?
    Thanks again!
    Here's a PcDmis script example for you...
    Code:
    ' Created by: KP61dude!
    ' Create date: 02-03-2020
    ' What: Select command at cursor location.
    Sub Main()
    Dim oPcd As Object
    Dim oPart As Object
    Dim oEw As Object
    
    Set oPcd = CreateObject("PCDLRN.Application")
    Set oPart = oPcd.ActivePartProgram
    Set oEw = oPart.EditWindow
    
    If Not oEw Then
    GoTo exitsub
    End If
    
    ' select currect command
    oEw.SelectCommand
    
    ' clean up
    Set oPcd = Nothing
    Set oPart = Nothing
    Set oEw = Nothing
    exitsub:
    End Sub
    Here's another
    Code:
    ' Created by: KP61dude!
    ' Create date: 01-31-2020
    ' What: Removes command at cursor location.
    Sub Main()
    Dim oPcd As Object
    Dim oPart As Object
    Dim oEw As Object
    
    Set oPcd = CreateObject("PCDLRN.Application")
    Set oPart = oPcd.ActivePartProgram
    Set oEw = oPart.EditWindow
    
    If Not oEw Then
    msgbox("failed")
    GoTo exitsub
    End If
    
    ' select currect command
    oEw.SelectCommand
    oEw.CutSelectedToClipboard
    
    ' clean up
    Set oPcd = Nothing
    Set oPart = Nothing
    Set oEw = Nothing
    
    exitsub:
    End Sub
    PcDmis 2015.1 SP10 CAD++
    Global 7-10-7 DC800S

    Comment


    • #3
      Kp61dude! I'm trying to figure out how to get this to work with the current code that I have. This is the full code..

      Code:
      Dim DmisApp As Object
      Dim DmisPart As Object
      Dim DmisCommands As Object
      Dim DmisCommand As Object
      
      Sub Part1
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
      CommandCount = DmisCommands.Count
      Set DmisCommand = DmisCommands.Item(CommandCount)
      DmisCommands.InsertionPointAfter DmisCommand
      I'm assuming the code I would need to input from yours is..

      Code:
      Dim oEw As Object
      Set oEw = DmisPart.EditWindow
      oEw.SelectCommand
      ...edited so the objects match what I already have. Does the oEw.SelectCommand line return where the cursor currently is in the program?

      Comment


      • #4
        Dim oEw As PCDLRN.EditWindow
        oEw = PCDPartProgram.EditWindow
        oEw.SelectCommand() ' this will select command at cursor location
        PcDmis 2015.1 SP10 CAD++
        Global 7-10-7 DC800S

        Comment


        • #5
          Kp61dude! I feel like an idiot here. I've tried inputting the code into what I have and I get Type Mismatch error in line 10.

          Code:
          Dim DmisApp As Object
          Dim DmisPart As Object
          Dim DmisCommands As Object
          Dim DmisCommand As Object
          Dim oEw As Object
          
          Sub Part1
          Set DmisApp = CreateObject("PCDLRN.Application")
          Set DmisPart = DmisApp.ActivePartProgram
          Set oEw = PCDLRN.EditWindow
          oEw = DmisPart.EditWindow
          Set DmisCommands = DmisPart.Commands
          CommandCount = oEw.SelectCommand
          Set DmisCommand = DmisCommands.Item(CommandCount)
          DmisCommands.InsertionPointAfter DmisCommand
          I guess I'm confused as to where I put those lines of code.

          Comment


          • Kp61dude!
            Kp61dude! commented
            Editing a comment
            It's my Monday today... sorry! Robert Hulman for the save!

          • SingularitY
            SingularitY commented
            Editing a comment
            All good man. I still appreciate the help! You guys are always a life saver.

        • #6
          Dim PCDapp As Object
          Dim PCDpart As Object
          Dim Cmds As Object
          Dim Cmd As Object

          Set PCDapp = CreateObject ("PCDLRN.Application")
          Set PCDpart = PCDapp.ActivePartProgram
          Set Cmds = PCDpart.Commands
          Set Cmd = Cmds.CurrentComand
          IsSet = Cmds.InsertionPointAfter(Cmd)
          If IsSet Then

          Your code..

          End If

          Comment


          • #7
            You don't need to set editwindow object, just be sure that you,ve clicked on place where you want to add new command

            Comment


            • #8
              Awesome! Thanks for the help. This is the code I went with.

              Code:
              Dim DmisApp As Object
              Dim DmisPart As Object
              Dim DmisCommands As Object
              Dim DmisCommand As Object
              
              Sub Part1
              Set DmisApp = CreateObject("PCDLRN.Application")
              Set DmisPart = DmisApp.ActivePartProgram
              Set DmisCommands = DmisPart.Commands
              Set DmisCommand = DmisCommands.CurrentCommand
              DmisCommands.InsertionPointAfter DmisCommand
              I wasn't sure if I would need the IF IsSet portion of the code though. Seems to work well without it. Is this a safety precaution for something? If the cursor isn't in the edit window?

              Comment


              • Robert Hulman
                Robert Hulman commented
                Editing a comment
                You're welcome. Yes you're right, IsSet is not necessary, it's just for check if insertionpointafter succeed.

            • #9
              if would someone like to put command under selected place just put line:

              Set DmisCommand = DmisCommands.CurrentCommand
              DmisCommand.Prev
              DmisCommands.InsertionPointAfter DmisCommand

              Comment

              Related Topics

              Collapse

              Working...
              X