batch script file create

Discussion in 'AutoCAD' started by john coon, Oct 27, 2004.

  1. john coon

    john coon Guest

    hI All,
    I looking for help in creating a batch script text file. what I'm looking to
    do is select a group of files in a subdirectory and capture the string path
    and filename and have it place the filename into a text file to create a
    batch script file.
    I can create the ListBox.List of the filenames and I can create the
    CommonDialog1 for the location of the filename that the path & filename is
    to be inserted into. The problem is inserting the listbox.list path &
    filename into the sample text file included below.
    any comments or sample code to help me with this problem is greatly
    appreciated.

    Thank you,
    John Coon

    '''''''''''''''''''''''''''''''''''''''sample text file that I'm trying to
    create
    OPEN
    H:\030071\DWG\BID3\CONTRACT\marking\r35cm401.dwg ''''''''' string path and
    filename marker location where listbox.list path & filename needs to be
    inserted
    PLOT
    W
    ..25,.35
    33.75,21.65
    0
    QSAVE
    ''''''''''''''''''''''''''''''''''''''''''ad space loop then insert next
    filename from listbox.lst into Text file.
    OPEN
    H:\030071\DWG\BID3\CONTRACT\marking\r35cm303.dwg '''''''''''string path and
    filename marker location where listbox.list path & filename needs to be
    inserted
    PLOT
    W
    ..25,.35
    33.75,21.65
    0
    QSAVE

    Private Sub cmdSearch_Click()
    Dim Filename As String
    Dim SearchDir As String

    'Opens a Treeview control that displays the directories in a computer
    ListBox1.Clear
    Dim lpIDList As Long
    Dim sBuffer As String
    Dim szTitle As String
    Dim tBrowseInfo As BrowseInfo

    szTitle = "Select a Folder:"
    With tBrowseInfo
    .lpszTitle = lstrcat(szTitle, "")
    .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
    End With

    lpIDList = SHBrowseForFolder(tBrowseInfo)

    If (lpIDList) Then
    sBuffer = Space(MAX_PATH)
    SHGetPathFromIDList lpIDList, sBuffer
    SearchDir = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    End If

    Filename = Dir(SearchDir & "\" & "*.dwg")
    While Filename <> ""
    If Right$(SearchDir, 1) <> "\" Then
    ListBox1.AddItem SearchDir & "\" & Filename
    Else
    ListBox1.AddItem SearchDir & Filename
    End If
    Filename = Dir
    Wend

    Dim Green As Integer 'outer loop
    Dim Red As Integer 'inner loop
    Dim intTemp As Integer
    Dim strListArray(1000) As String

    For intTemp = 0 To ListBox1.ListCount - 1
    strListArray(intTemp) = ListBox1.List(intTemp)
    Next

    For Green = ListBox1.ListCount - 1 To 0 Step -1
    For Red = 0 To Green - 1
    If UCase(strListArray(Red)) > UCase(strListArray(Red + 1)) Then
    swap strListArray(Red), strListArray(Red + 1)
    End If
    Next Red
    Next Green

    Dim tempList As Integer
    tempList = ListBox1.ListCount - 1
    ListBox1.Clear

    For intTemp = 0 To tempList
    ListBox1.AddItem strListArray(intTemp)
    Next intTemp

    Label2.Caption = SearchDir & " - " & ListBox1.ListCount & " file(s)."

    End Sub



    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim j As Integer
    Dim flag As Integer
    flag = 0

    For j = 0 To ListBox2.ListCount - 1
    ListBox2.ListIndex = j
    If ListBox1.List(ListBox1.ListIndex) = ListBox2.List(j) Then
    flag = 1
    End If
    Next j

    If flag = 0 Then
    ListBox2.AddItem ListBox1.List(ListBox1.ListIndex)
    ListBox1.RemoveItem ListBox1.ListIndex
    End If
    lblPrintList.Caption = "Print List - " & ListBox2.ListCount & " file(s)."
    End Sub
     
    john coon, Oct 27, 2004
    #1
  2. john coon

    Matt W Guest

    This should get you started...


    --
    I support two teams: the Red Sox and whoever beats the Yankees.


    | hI All,
    | I looking for help in creating a batch script text file. what I'm looking
    to
    | do is select a group of files in a subdirectory and capture the string
    path
    | and filename and have it place the filename into a text file to create a
    | batch script file.
    | I can create the ListBox.List of the filenames and I can create the
    | CommonDialog1 for the location of the filename that the path & filename is
    | to be inserted into. The problem is inserting the listbox.list path &
    | filename into the sample text file included below.
    | any comments or sample code to help me with this problem is greatly
    | appreciated.
    |
    | Thank you,
    | John Coon
    |
    | '''''''''''''''''''''''''''''''''''''''sample text file that I'm trying to
    | create
    | OPEN
    | H:\030071\DWG\BID3\CONTRACT\marking\r35cm401.dwg ''''''''' string path
    and
    | filename marker location where listbox.list path & filename needs to be
    | inserted
    | PLOT
    | W
    | .25,.35
    | 33.75,21.65
    | 0
    | QSAVE
    | ''''''''''''''''''''''''''''''''''''''''''ad space loop then insert next
    | filename from listbox.lst into Text file.
    | OPEN
    | H:\030071\DWG\BID3\CONTRACT\marking\r35cm303.dwg '''''''''''string path
    and
    | filename marker location where listbox.list path & filename needs to be
    | inserted
    | PLOT
    | W
    | .25,.35
    | 33.75,21.65
    | 0
    | QSAVE
    |
    | Private Sub cmdSearch_Click()
    | Dim Filename As String
    | Dim SearchDir As String
    |
    | 'Opens a Treeview control that displays the directories in a computer
    | ListBox1.Clear
    | Dim lpIDList As Long
    | Dim sBuffer As String
    | Dim szTitle As String
    | Dim tBrowseInfo As BrowseInfo
    |
    | szTitle = "Select a Folder:"
    | With tBrowseInfo
    | .lpszTitle = lstrcat(szTitle, "")
    | .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
    | End With
    |
    | lpIDList = SHBrowseForFolder(tBrowseInfo)
    |
    | If (lpIDList) Then
    | sBuffer = Space(MAX_PATH)
    | SHGetPathFromIDList lpIDList, sBuffer
    | SearchDir = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    | End If
    |
    | Filename = Dir(SearchDir & "\" & "*.dwg")
    | While Filename <> ""
    | If Right$(SearchDir, 1) <> "\" Then
    | ListBox1.AddItem SearchDir & "\" & Filename
    | Else
    | ListBox1.AddItem SearchDir & Filename
    | End If
    | Filename = Dir
    | Wend
    |
    | Dim Green As Integer 'outer loop
    | Dim Red As Integer 'inner loop
    | Dim intTemp As Integer
    | Dim strListArray(1000) As String
    |
    | For intTemp = 0 To ListBox1.ListCount - 1
    | strListArray(intTemp) = ListBox1.List(intTemp)
    | Next
    |
    | For Green = ListBox1.ListCount - 1 To 0 Step -1
    | For Red = 0 To Green - 1
    | If UCase(strListArray(Red)) > UCase(strListArray(Red + 1)) Then
    | swap strListArray(Red), strListArray(Red + 1)
    | End If
    | Next Red
    | Next Green
    |
    | Dim tempList As Integer
    | tempList = ListBox1.ListCount - 1
    | ListBox1.Clear
    |
    | For intTemp = 0 To tempList
    | ListBox1.AddItem strListArray(intTemp)
    | Next intTemp
    |
    | Label2.Caption = SearchDir & " - " & ListBox1.ListCount & " file(s)."
    |
    | End Sub
    |
    |
    |
    | Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    | Dim j As Integer
    | Dim flag As Integer
    | flag = 0
    |
    | For j = 0 To ListBox2.ListCount - 1
    | ListBox2.ListIndex = j
    | If ListBox1.List(ListBox1.ListIndex) = ListBox2.List(j) Then
    | flag = 1
    | End If
    | Next j
    |
    | If flag = 0 Then
    | ListBox2.AddItem ListBox1.List(ListBox1.ListIndex)
    | ListBox1.RemoveItem ListBox1.ListIndex
    | End If
    | lblPrintList.Caption = "Print List - " & ListBox2.ListCount & " file(s)."
    | End Sub
    |
    |
     
    Matt W, Oct 27, 2004
    #2
  3. john coon

    John Coon Guest

    Matt,
    One more game to go!
    Thanks for the sample I appreciate it. That's close to what I'm looking for
    but how would I add a link to an external file containing different
    keystrokes. under your method I would use the Print # to hard code the
    keystrokes to be written out. Is there a method to point to an external file
    and have it contents written then place the Print #filenum,
    ListBox1.List(i) for the drawing file to open. can I update these keystrokes
    contained in a external file with the keystrokes.
    The sample code I supplied wasn't the best selection for this discussion
    although It will work great for canned routines.

    I found a snip of code Do While Not EOF(intInputFile)
    'read 2 sequential, delimited values from the input file
    Input #intInputFile, dblSta, dblOff
    Could I use something like this to point to a block of script keystokes
    inside a file and have the contains written to the newly created script
    file.

    Thanks as always
    John Coon
    New Hampshire
     
    John Coon, Oct 27, 2004
    #3
  4. john coon

    Matt W Guest

    Using my previous example, replace the code behind the button with this...
    and create a simple file called KeyStrokes.txt with script-like commands.

    Code:
    Dim DwgListCount As Integer
    Dim i1 As Integer
    Dim i2 As Integer
    
    Dim filenum1 As Integer
    Dim strLine1 As String
    Dim filenum2 As Integer
    Dim strLine2 As String
    Dim x As Integer
    
    filenum1 = 1
    filenum2 = 2
    Open "e:\temp\script.scr" For Output As #filenum1
    
    For i1 = 0 To ListBox1.ListCount - 1
    ListBox1.Selected(i1) = True
    Print #filenum1, "OPEN"
    Print #filenum1, ListBox1.List(i1)
    Open "e:\temp\keystrokes.txt" For Input As #filenum2
    Do While Not EOF(filenum2)
    Line Input #filenum2, strLine2
    Print #filenum1, strLine2
    Loop
    Close filenum2
    Print #filenum1, "QSAVE"
    Next i1
    
    Close filenum1
    
     
    Matt W, Oct 28, 2004
    #4
  5. john coon

    John Coon Guest

    WOW Matt,

    That was IT! Fantastic.......I stepped thru your code and now understand how
    the Do While Not EOF(filenum2) works
    Thank you some much for your help. I hope to built on this concept. I'm
    going to add a CommonDialog1 for the location of the filename you used
    keystrokes.txt
    that should give the routine some legs. I'm off and running thanks to your
    help.

    Thanks for all your help.
    John
     
    John Coon, Oct 28, 2004
    #5
  6. john coon

    Matt W Guest

    Glad I could help.

    --
    I support two teams: The Red Sox and whoever beats the Yankees.

     
    Matt W, Oct 29, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.