hexagon logo

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...
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!
  • 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...
    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...
    ' 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
    ' 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
    
  • I'm trying to figure out how to get this to work with the current code that I have. This is the full 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..

    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?
  • Dim oEw As PCDLRN.EditWindow
    oEw = PCDPartProgram.EditWindow
    oEw.SelectCommand() ' this will select command at cursor location
  • 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.

    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.
  • 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
  • You don't need to set editwindow object, just be sure that you,ve clicked on place where you want to add new command
  • Awesome! Thanks for the help. This is the code I went with.

    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?
  • All good man. I still appreciate the help! You guys are always a life saver.
  • You're welcome. Yes you're right, IsSet is not necessary, it's just for check if insertionpointafter succeed.