Hi, I need to open a bunch of drawings, update a block and then save. I am trying to do it without opening each drawing in AutoCAD. Here is the code snippet I have. I figured before I plug in my block editing code, I would test things out with just adding a line. It seems to be boing through the drawings, and I get no errors, but the line is not being added. What am I missing here? Any suggestions to improve how I'm doing this would be greatly appreciated.
Dim mydb AsNewDatabase(False, True)
mydb.ReadDwgFile(Newfname,FileOpenMode.OpenForReadAndWriteNoShare, True, "")
Using Trans AsTransaction = mydb.TransactionManager.StartTransaction()
Dim btr AsBlockTableRecord = Trans.GetObject(mydb.CurrentSpaceId,OpenMode.ForWrite)
Using myline AsNewLine(NewPoint3d(0, 0, 0), NewPoint3d(10, 10, 10))
mydb.SaveAs(Newfname,True, DwgVersion.Current, mydb.SecurityParameters)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
... and I get no errors, ...
What do you expect if you leave the Catch clause blank in the Try... Catch... block? Gues what, no error!
Try to do something in the Catch... clause so you could be alerted when exception occurs. Or, have you actually step through the code in debugging? If you do, it is likely you would have found out an exception has raised before the line is added to database.
I could be wrong, but I guess it is myDB.CurrentSpaceId that causes exception, because if the drawing is not opened in AutoCAD editor, the CurrentSpaceId is NULL. You actually want to add line into ModelSpace, or one of PaperSpaces.
OK, I was wrong saying Database.CurrentSpaceId could be NULL.
Your code inside the Try...Catch runs OK on my side, as long as the drawing file read into database is a good drawing file.
You need to place some code in Catch...clause or remove Try...Catch..., or step through in debugging to make sure there is or is not exception being raised (maybe due to a bad drawing file?).
I useually try and see what is erroring by using err.number of err.descrcitpon is the stopping the debugger to see what the problem was.
Dim s As String = Err.Description
look at s and it will tell you what the problem was.
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!