.NET

Reply
Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 1 of 6 (876 Views)
Accepted Solution

Changing Dimension style property to same value crashes AutoCAD

876 Views, 5 Replies
09-30-2013 06:57 AM

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

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 2 of 6 (855 Views)

Re: Changing Dimension style property to same value crashes AutoCAD

09-30-2013 11:15 AM 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.

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 3 of 6 (839 Views)

Re: Changing Dimension style property to same value crashes AutoCAD

10-01-2013 02:28 AM in reply to: sszabo

I will separate it and post later

 

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

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 4 of 6 (831 Views)

Re: Changing Dimension style property to same value crashes AutoCAD

10-01-2013 05:07 AM 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

 

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 5 of 6 (826 Views)

Re: Changing Dimension style property to same value crashes AutoCAD

10-01-2013 05:19 AM 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.

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 6 of 6 (801 Views)

Re: Changing Dimension style property to same value crashes AutoCAD

10-02-2013 01:45 AM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community