.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help creating and saving new drawings

2 REPLIES 2
Reply
Message 1 of 3
lvthunder
337 Views, 2 Replies

Help creating and saving new drawings

I'm creating a program which takes an Excel spreadsheet and creates new drawings then throws blocks in those drawings and saves them.  I have got it to where it reads the Excel sheet and will create a new drawing for each line in the spreadsheet.  The problem is it doesn't save them and I must switch back to the first drawing before the program continues.  I don't even care if the drawing gets opened  Can someone help me?

 

 

 <CommandMethod("CreateShopDrawing")> _
    Public Sub CreateShopDrawing() ' This method can have any name

        beamlist()

        Dim i As Integer = 7 'For i As Integer = 7 To nmcount
        file = mybmlist.Cells(i, 2).value()
        filename = filepath & mybmlist.Cells(i, 2).value() & ".dwg"
        sheetnum = mybmlist.Cells(i, 1).value()
        'MsgBox(filename)
        NewDrawing()
        BlockInsert("left")
        BlockInsert("right")
        'tab1BlockInsert()
        'tab2BlockInsert()
        'sectionblockinsert()
        'plan()
        SaveActiveDrawing(filename)
        'Next i
        closeExcel()
    End Sub
    Private Sub beamlist()
        ' **********************************************************************
        ' *      Purpose: Beamlist Sub to open Excel and assign sheet names    *
        ' *               to objects                                           *
        ' *      Date: 2/11/11                                                 *
        ' **********************************************************************
        Dim Main_Options As New Main_Options
DialogBox:
        Select Case ApplicationServices.Application.ShowModalDialog(Main_Options)
            Case System.Windows.Forms.DialogResult.Cancel
                GoTo EOS
            Case System.Windows.Forms.DialogResult.OK
                If Main_Options.TextBox1.Text = "" Or Main_Options.TextBox2.Text = "" Or Main_Options.TextBox3.Text = "" Then
                    MsgBox("You must select files and folders for all the fields")
                    GoTo DialogBox
                Else
                    filepath = Main_Options.TextBox3.Text & "\"
                    On Error GoTo ExcelError
                    myExcel = New Microsoft.Office.Interop.Excel.Application
                    myWorkbook = myExcel.Workbooks.Open(Main_Options.TextBox1.Text)
                    'MsgBox("Workbook Open")
                    mybmlist = myExcel.Worksheets("Beam Table")
                    mysheet = myExcel.Worksheets("ShopDwgsTables")
                    mysched = myExcel.Worksheets("Schedules")
                    'MsgBox("Worksheets Open")
                    Do While mybmlist.Cells(nmcount, 2).value <> ""
                        nmcount = nmcount + 1
                    Loop
                    'MsgBox("number of files:  " & nmcount - 7)
                    nmcount = nmcount - 1
                    GoTo EOS
                End If
        End Select
ExcelError:
        MsgBox("You need to select an Excel File that has a Beam Table, ShopDwgsTables, and Schedules tab")
        GoTo DialogBox
EOS:
    End Sub
    Public Sub NewDrawing()
        '' Specify the template to use, if the template is not found
        '' the default settings are used.
        Dim strTemplatePath As String = "acad.dwt"
        Dim acDocMgr As DocumentCollection = ApplicationServices.Application.DocumentManager
        Dim acDoc As Document = acDocMgr.Add(strTemplatePath)
        acDocMgr.MdiActiveDocument = acDoc
    End Sub
    Public Sub SaveActiveDrawing(ByVal filepath As String)
        Dim acDoc As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim strDWGName As String = acDoc.Name
        Dim obj As Object = ApplicationServices.Application.GetSystemVariable("DWGTITLED")
        '' Check to see if the drawing has been named
        If System.Convert.ToInt16(obj) = 0 Then
            '' If the drawing is using a default name (Drawing1, Drawing2, etc)
            '' then provide a new name
            strDWGName = filepath
        End If
        '' Save the active drawing
        acDoc.Database.SaveAs(strDWGName, True, DwgVersion.Current, _
                              acDoc.Database.SecurityParameters)
    End Sub

 

 

2 REPLIES 2
Message 2 of 3
arcticad
in reply to: lvthunder

 

This will create a new drawing without having to use the editor. 

Public Sub NewDrawing(ByVal dwgFullPath As String)

Using db As New Database(True, False)
Using tr As Transaction = db.TransactionManager.StartTransaction()
' Lock the drawing in the editor.
Dim myDWG As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Using lock As DocumentLock = myDWG.LockDocument
' Write out new Drawing File.
db.SaveAs(dwgFullPath, DwgVersion.Current, DwgVersion.Current, db.SecurityParameters)
End Using
End Using
End Using

End Sub

 

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 3
lvthunder
in reply to: arcticad

Thanks for the help.  One question.  How would I specify the template file to use?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost