TheSwamp
Code Red => .NET => Topic started by: TJK44 on November 16, 2011, 03:58:38 PM
-
Can anyone help me out with code on how to create a new drawing and save it?
Thanks for any help,
Ted
-
I tried just using this but didnt work and threw an error.
Dim db As Database = New Database(False, False)
Using trans As Transaction = db.TransactionManager.StartTransaction()
db.SaveAs("C:\test\DIDTHISWORK.dwg", DwgVersion.Newest)
End Using
-
I solved how to get it to work. I changed the database line
Dim db As Database = New Database(True, False)
-
Have tried some searches for adding a new document to the document collection?
Here's one link:
http://www.theswamp.org/index.php?topic=39914.msg452117#msg452117
There are plenty of examples on SaveAs if you wish to save the document to a file name.
-
I wanted a new dwg file to be created in the background so I could then add xrefs to it without the user having to create the empty dwg. It's working now.
-
I wanted a new dwg file to be created in the background so I could then add xrefs to it without the user having to create the empty dwg. It's working now.
Oh, you should have said that in the first place.
People can help you better if they know what you trying to do.
Glad you got it going.
-
< ... > It's working now.
Care to post your solution so others may learn from your testing ?
[< .. >
Oh, you should have said that in the first place.
People can help you better if they know what you trying to do.
Glad you got it going.
Can't argue with that.
-
Dim xrefdb As Database = New Database(False, False)
Dim fName2 As String = database.Filename
Dim curdir2 As String = Path.GetDirectoryName(fName2)
Dim db As Database = New Database(True, False)
Using trans As Transaction = db.TransactionManager.StartTransaction()
db.SaveAs(curdir2 & "\Master.dwg", DwgVersion.Newest)
End Using
xrefdb.ReadDwgFile(curdir2 & "\Master.dwg", FileShare.ReadWrite, False, "")
Using trx As Transaction = xrefdb.TransactionManager.StartTransaction()
Dim xrefBt As BlockTable = trx.GetObject(xrefdb.BlockTableId, OpenMode.ForWrite)
Dim btrMs As BlockTableRecord = trx.GetObject(xrefBt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim files As String() = Directory.GetFiles(curdir2 & "\parts")
'list the names of all files in the specified directory
For Each file In files
Dim xrefObjId As ObjectId = xrefdb.AttachXref(file, Path.GetFileNameWithoutExtension(file))
Dim bref As New BlockReference(Point3d.Origin, xrefObjId)
btrMs.AppendEntity(bref)
Dim blname As String = "XRef - " & Path.GetFileNameWithoutExtension(file)
'Get the layer table first...
Dim lt As LayerTable = trx.GetObject(xrefdb.LayerTableId, OpenMode.ForRead)
Dim layerId As ObjectId = ObjectId.Null
'Check if EmployeeLayer exists...
If lt.Has(blname) Then
layerId = lt.Item(blname)
Else
'If not, create the layer here.
lt.UpgradeOpen()
Dim ltr As LayerTableRecord = New LayerTableRecord()
ltr.Name = blname ' Set the layer name
ltr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 7)
layerId = lt.Add(ltr)
trx.AddNewlyCreatedDBObject(ltr, True)
End If
bref.LayerId = layerId
trx.AddNewlyCreatedDBObject(bref, True)
Next
trx.Commit()
End Using
xrefdb.SaveAs(curdir2 & "\Master.dwg", DwgVersion.Newest)
I should have a try block in here too, didn't get around to that yet.
-
TJK44
How are you declaring this code snip.
ie
What is the method called.
What is the CommandMethod used
How about giving us enough so that we don't have to guess how you are using this snippet ... and don't need to spend time adding to the code so we can test it.
Are you calling it from the Command line or from a Modal or Modeless or Pallete dialog
-
Sorry Kerry. Its at the end of a sub procedure, you want me to post the entire sub? What it does is it takes blocks from a drawing one by one if they have a certain attribute, creates a folder called parts, then drops each block into the folder as a part. Then creates the blank drawing and drops all the parts in as xrefs and also creates a separate layer for each xref. The part I posted essentially just pulls dwgs out of a folder and then xrefs them to the new dwg that is being created in the code.
-
Seems like a lot to put into one Sub.
anyway,
I personally don't need to see all the code ... but I do expect to be given all the information relating to a problem I'm asked to look at ; and enough code to demonstrate the issue.
You project sounds interesting. From the last message you posted it seems that all issues are resolved ... which is great.
-
If you need anymore information on it let me know, I'll be more than happy to help.
-
:) Thanks.
-
I did actually have the entire layer creation process in a function, but it wasn't working for me. Kept getting an error saying WrongDb I think. So I put it in the sub just to get it to work for the time being. Probably look into that tomorrow.