Valued Contributor
Posts: 54
Registered: ‎11-12-2012
Message 1 of 4 (476 Views)

Edit drawing without opening in AutoCAD

476 Views, 3 Replies
07-05-2013 08:00 AM

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



*Expert Elite*
Posts: 1,024
Registered: ‎04-27-2009
Message 2 of 4 (465 Views)

Re: Edit drawing without opening in AutoCAD

07-05-2013 09:06 AM in reply to: cjacobi

... 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.

*Expert Elite*
Posts: 1,024
Registered: ‎04-27-2009
Message 3 of 4 (439 Views)

Re: Edit drawing without opening in AutoCAD

07-05-2013 01:45 PM in reply to: norman.yuan

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?).

Valued Contributor
Posts: 91
Registered: ‎12-05-2011
Message 4 of 4 (354 Views)

Re: Edit drawing without opening in AutoCAD

07-16-2013 08:06 AM in reply to: norman.yuan

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.

Learning as I go
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.