hexagon logo

Questions about script suggested to me in Pc-DMIs IDEA CENTER

Below is some code someone suggested to me to have a program auto save while its running. I know very little to nothing about this. Would someone be will to explain to me what the code is doing in the script? 

Thank you guys in advance

Make a Basic Script:

Sub SaveDuringExecution()

'Create objects
Dim PCDMISApp As Object
Set PCDMISApp = CreateObject("PCDLRN.Application")

Dim PCDMISPart As Object
Set PCDMISPart = PCDMISApp.ActivePartprogram

'Save existing program
PCDMISPart.Save

' finish
Set PCDMISApp = Nothing
Set PCDMISApp = Nothing

End Sub

Put it in a subprogram and you can easily summon the script in your partprogram by typing 'CALLSUB' and select the subprogram.

You can also run the sctript directly in the partprogram but it's easier when you place it in a subprogram.

But if you check out the PCDMIS forum (Nexus), you can find answers for questions like these ;)

Parents
  • When the script is called, the program gets saved. Same method as (CTRL + S) or File > Save within PC-DMIS. Then they empty the variables to a non-nullable value using "Nothing" I personally don't use it sometimes and have no issues, so I am not 100% certain why it is incorporated so much. It may help freeing memory.

    If you are curious about how the scripts work, take an existing, short simple program you just made, and export it as a .BAS file, and open it up. You will notice at the top, all programs open up with similar variables like this. Helps with reverse engineering if you're new to Basic.

    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
      Set DmisCommand = DmisCommands.Add(START_ALIGN, TRUE)

    Be sure if copying and pasting a script from online, you change the "function" from the Default "Main" on any script created in the edit window.

    If modifying within the pasted script just rename it Main, the PC-DMIS default.

    CS1        =SCRIPT/FILENAME= SAVEDURING.BAS
                FUNCTION/SaveDuringExecution,SHOW=YES,,
                STARTSCRIPT/

    Sub SaveDuringExecution()
    
    'Create objects
    Dim PCDMISApp As Object
    Set PCDMISApp = CreateObject("PCDLRN.Application")
    Dim PCDMISPart As Object
    Set PCDMISPart = PCDMISApp.ActivePartprogram
    
    'Save existing program
    PCDMISPart.Save
    
    ' finish
    Set PCDMISApp = Nothing
    Set PCDMISApp = Nothing
    
    End Sub

  • So Using Google Gemini I tried the script this morning. PC-DMIS keeps freezing and closing. This could easily be my computer as I need a upgrade. Could be the code as well but I cant be sure

  • Something is definitely going on besides a possible script error. I'm trying run a simple script of showing a message box saying hello and PC-DMIS Keeps locking up and crashing. Anyone have any similar issues with this?

  • Have you tried running it from inside PC-DMIS using the basic script editor?

  • Yea I actually just did. Im updating PC-DMIS to the latest version of 2022 our license will allow. I dont have much confidence in that but it couldn't hurt

  • Try this instead...

    ' this script will automatically save the program
    ' reads In original program Name And saves As this at the End
    
    ' Declare As objects - Not application, etc
    
    Dim PCDapp As Object
    Dim PP As Object
    
    'defines "suffix" As String And sets As ARG1 from script command In PCD prog
    Sub Main (suffix As String)
      'objects must be assigned using Set command
      Set PCDapp=createObject("PCDLRN.Application")
      Set PP=PCDapp.ActivePartProgram
    
      'define "Oldname" And Set As original program Name
      Dim OldName As String
      OldName = PP.Fullname
    
      'save under original Name
      PP.SaveAs Oldname
    
      Set PP = Nothing
      Set PCDapp = Nothing
    End Sub
    

  • Dim PCDapp As Object
    Dim PP As Object

    Sub Main(suffix As String)

    Set PCDapp = CreateObject("PCDLRN.Application")
    Set PP = PCDapp.ActivePartProgram

    Dim blank As String
    blank= PP.Fullname

    PP.SaveAs blank & "_" & suffix "autoip" and suffix

    Set PP = Nothing
    Set PCDapp = Nothing

    End Sub

    Like this?

Reply Children