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

Edit drawing without opening in AutoCAD

3 REPLIES 3
Reply
Message 1 of 4
coralie.jacobi
826 Views, 3 Replies

Edit drawing without opening in AutoCAD

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.

 

thanks

 

 

Try

                           

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

          btr.AppendEntity(myline)

          Trans.AddNewlyCreatedDBObject(myline,True)

                               

  EndUsing

    Trans.Commit()

                           

EndUsing

mydb.SaveAs(Newfname,True, DwgVersion.Current, mydb.SecurityParameters)

                       

Catch ex As Autodesk.AutoCAD.Runtime.Exception

                       

EndTry

3 REPLIES 3
Message 2 of 4


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

Message 3 of 4
norman.yuan
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?).

Message 4 of 4
jaboone
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

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