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

Changing Dimension style property to same value crashes AutoCAD

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
matus.brlit
2081 Views, 5 Replies

Changing Dimension style property to same value crashes AutoCAD

In my code, I create a copy of dimension style:

 

s3 = New DimStyleTableRecord
s3.CopyFrom(vz)
s3.Name = nazov
tst.Add(s3)

_trans.AddNewlyCreatedDBObject(s3, True)
_trans.Commit()

 then, in another part of the code, I open the new style and change a property:

 

        Using trans As Transaction = db.TransactionManager.StartTransaction

            ds = trans.GetObject(ds.ObjectId, OpenMode.ForWrite)
            ds.Dimtxsty = s2TextStyle.ObjectId
            trans.Commit()

        End Using

 

this works OK for the first time, but when I run the code again, I don't create the new style, I just take the existing one and changing the Dimtxtsty property to the value it already has causes AutoCAD crash

5 REPLIES 5
Message 2 of 6
sszabo
in reply to: matus.brlit

My guess would be that your object was createcd/copied in the context of a different transaction and you don't have access to it the second time around. 

 

It would help if you recreated your problem in a self contained example (autocad command) so that people can try it themselves.  For instance I could copy your code into an existing project that installes thread/domain unhandled exception handlers and see why acad is crashing to begin with.

Message 3 of 6
matus.brlit
in reply to: sszabo

I will separate it and post later

 

is there a way to catch the exception before the fatal error?

Message 4 of 6
matus.brlit
in reply to: matus.brlit

I can't reproduce the problem when I separate the code, I also simulated the multithreading and call from a form, but the problem doesn't show.

 

I solved it by testing, if the style is already the same:

 

If ds.Dimtxsty <> s2TextStyle.ObjectId Then ds.Dimtxsty = s2TextStyle.ObjectId

 

Message 5 of 6
sszabo
in reply to: matus.brlit

Ok, I am glad you solved it. 

 

I usually inherit from control and install handlers for AppDomain.CurrentDomain.FirstChanceException and AppDomain.CurrentDomain.UnhandledException in the Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize routine.  Note that you will have to use some logging system that's independent of autocad (I'm using Nlog) and it's not going to work 100% of the time but it will catch most of your mistakes and some of autodesk's.  I might cook up an example and post it in a few days.

Message 6 of 6
matus.brlit
in reply to: sszabo

I was experimenting with this, I had handler hooked on those events, but it didn't help, because I didn't go as far as you  with the logging system so fatal errors still produced no information.

That example would be really helpful for many people, because you can mess up in so many ways and the result is always the same - fatal error.

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