Opening files in AutoCAD with VBA and Plotting with LISP command in memory.

Discussion in 'AutoCAD' started by Steve Anderson, Jun 28, 2004.

  1. Excuse the hyperlinks, spaces are "_".

    In the code below, I am trying to open files to plot them in VB. I am accessing a database to get the list of files to plot - which works fine - producing the result below for PFile:

    PFile = PATH4 & PN & ".dwg"

    PFile = \\deepblue\Projects\36100-36149\36136_B-D_Holdrege_PILS_Pen_Project\Parts\36136-1-661.dwg

    I then wish to open the file, plot it using a few LISP routines and close.

    ThisDrawing.Open (PFile) - This produces a runtime error '-2145320848 (80210070)': Method not available in MDI mode. Use OPen method of documents collection.
    ' ThisDrawing.sp1 - I was hoping to run the 'SP1' LISP command (loaded in memory, which plots the file). Apparently, this is not the correct format.
    ' ThisDrawing.fpb1 - I was hoping to run the 'FPB1' LISP command (loaded in memory, which plots the file). Apparently, this is not the correct format.
    ThisDrawing.Close - Close the file

    Any help you can provide with this would be greatly appreciated.

    Code

    Dim sqlPartNo As String
    sqlPartNo = "SELECT tblBOM.PartNo, tblBOM.SubAssy, tblBOM.PartNo, tblPartsListing.ManufacturedBy FROM tblPartsListing " & _
    "INNER JOIN tblBOM ON tblPartsListing.PartNo = tblBOM.PartNo " & _
    "WHERE (((tblBOM.JobNo) = " & Me.cboJobNo.Value & ") AND " & _
    "((tblBOM.SubAssy) = '" & Me.cboSubAssy.Value & "') AND " & _
    "((tblPartsListing.ManufacturedBy) = '" & "METRO MACHINE" & "'))"
    Debug.Print "sqlPartNo: " & sqlPartNo

    rs.Open sqlPartNo, sConn, adOpenKeyset, adLockOptimistic
    rs.MoveFirst
    Debug.Print rs.RecordCount

    Dim PN As String
    Dim PATH1 As String
    Dim PATH2 As String


    Do While Not rs.EOF
    PN = rs.Fields("PartNo")

    ' Determine file location per filename
    JN = Left(PN, 5)
    PATH1 = "\\deepblue\Projects\"

    If Int(Right(JN, 2)) >= 50 Then
    PATH2 = Left(JN, 3) & "50-" & Left(JN, 3) & "99\"
    Else
    PATH2 = Left(JN, 3) & "00-" & Left(JN, 3) & "49\"
    End If

    PATH3 = PATH1 & PATH2

    FindFolderName (JN)

    Dim PFile As String
    PFile = PATH4 & PN & ".dwg"
    Debug.Print PFile

    On Error GoTo skip2
    ThisDrawing.Open (PFile)
    ' ThisDrawing.sp1
    ' ThisDrawing.fpb1
    ThisDrawing.Close

    skip2:
    rs.MoveNext

    Loop
     
    Steve Anderson, Jun 28, 2004
    #1
  2. Steve Anderson

    MickyV Guest

    Hi Steve,

    Instead of using ThisDrawing.Open(PFile), try this.

    Dim oDwg as AcadDocument
    Set oDwg = Application.Documents.Open(PFile)

    Dragged straight from the help file:
    "When working in MDI mode, you should always use the Open method from the Documents collection. When working in SDI mode, use the Open method from the Document object."

    Then, to send your lisp commands, use SendCommand.

    ThisDrawing.SendCommand "SP1"
    ThisDrawing.SendCommand "FPB1"

    That should take care of your troubles.
    Mick.
     
    MickyV, Jun 28, 2004
    #2
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.