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

Creating Drawings from template

0 REPLIES 0
Reply
Message 1 of 1
BrentBurgess1980
295 Views, 0 Replies

Creating Drawings from template

Hi All,

I am creating a tool that can edit drawing title blocks, and also create new drawings, insert title block and edit the attributes.

Now, for existing drawings, this code is great and works well and can open the drawing after completion

{code}
Dim myDrawing As KBRDrawing = New KBRDrawing(LvwDrawings.Items(i).Tag)
myDrawing.OpenDrawingAsDatabase()
myDrawing.UpdateAttributes(LvwDrawings.Items(i), myStuff)
myDrawing.SaveDrawing()
myDrawing.CloseDrawing()
{code}

When I try to create the drawings, I can not open them and need to recover.
{code}
Dim myDrawing As New KBRDrawing(myItem.Tag)
myDrawing.CreateDrawing(myDrawing.FileName)
myDrawing.OpenDrawingAsDatabase()
myDrawing.UpdateAttributes(LvwDrawings.Items(i), myStuff)
myDrawing.SaveDrawing()
myDrawing.CloseDrawing()
{code}

Here are the methods
{code}
Public Sub CreateDrawing(ByVal Filename As String)
Dim StrTemplate As String = "O:\G&I\CAD\Software\Acad\Perth\Clients\Wcorp\WCX_Acad\Sht\WC Template.dwt"

My.Computer.FileSystem.CopyFile(StrTemplate, Filename)

End Sub

Public Sub OpenDrawingAsDatabase()
Me.Database = New DatabaseServices.Database()

Try
' create a file stream from the file, opening it for read only exclusive rights
Dim FS As IO.FileStream = IO.File.Open(Me.FileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
' close and clean up right awat, if the open succeeded, we have our answer
FS.Close()
FS.Dispose()
FS = Nothing

Me.Database.ReadDwgFile(Me.FileName, DatabaseServices.FileOpenMode.OpenForReadAndAllShare, False, Nothing)

Catch ex As IO.IOException
Catch ex As Exception
MessageBox.Show("Unknown error occured" & Environment.NewLine & ex.Message)
End Try

End Sub

Public Sub SaveDrawing()
Try
Me.Database.SaveAs(Me.FileName, DatabaseServices.DwgVersion.Current)
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Public Sub CloseDrawing()
Me.Database.Dispose()
End Sub
{code}

After I recover the drawing and open it, everything is completed correctly. I have narrowed it down to either the CreateDrawing being the offender, as this is the only difference in the 2 options above.

I have tried the CreateDrawing where it copies an existing dwg file, and it works fine, but when I use a dwt file, I need to recover.

Is there something that I have missed? Edited by: BrentBurgess1980 on Apr 29, 2010 2:26 PM
0 REPLIES 0

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