Dimension Value Ovveride

Dimension Value Ovveride

Anonymous
Not applicable
723 Views
7 Replies
Message 1 of 8

Dimension Value Ovveride

Anonymous
Not applicable

Hi all,

 

Tell me please, how to override value for Dimension from API (C#)?

Thanks.

0 Likes
724 Views
7 Replies
Replies (7)
Message 2 of 8

rosalesduquej
Alumni
Alumni

Dear Aleksandr,

 

Have you tried using Dimension.ValueOverride Property

http://revitapisearch.com/html/4560ec6c-5aab-fcae-a64c-6f939ae06d94.htm

 

Hope it helps. 

 

Cheers,



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thank you Jaime,

 

I have seen that, but I do not know how to apply... Tried in different ways, sometimes Revit crashes. It would be nice to get a ready example.

 

Thanks.

0 Likes
Message 4 of 8

BobbyC.Jones
Advocate
Advocate

I have also observed a Revit crash when accessing a DimensionSegment.ValueOverride property via a System.AccessViolationException when the .ValueOverride property has no value.  It will also crash if the .Below, .Above, .Prefix, or .Suffix properties are accessed when they contain no value.

 

I found a workaround on stackoverflow, How to handle AccessViolationException, which has links to some addition articles on MSDN.

 

Basically you wrap reads to those properties in a Try/Catch block and decorate the calling method with a [HandleProcessCorruptedStateExceptions] attribute  (The stackoverflow link has other solutions but this is the only one that I've tried).

 

        [HandleProcessCorruptedStateExceptions]
        private void GetOverride(Dimension singleSegmentDimension)
        {
            try
            {
                ValueOverride = singleSegmentDimension.ValueOverride;
            }
            catch (System.AccessViolationException ex)
            {
                //Handle the scary "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." message...
            }
        }
--
Bobby C. Jones
0 Likes
Message 5 of 8

Anonymous
Not applicable

Thanks Bobby, but... I want write different value to Value Override of Dimension.

0 Likes
Message 6 of 8

BobbyC.Jones
Advocate
Advocate

I haven't tested yet, but this may have been addressed in 2016 SP2 per the release notes.

 

 

  • Improves stability when DimensionSegment ValueOverride API is called when the dimension value was not overridden.

 

--
Bobby C. Jones
0 Likes
Message 7 of 8

tdaniel
Contributor
Contributor

Does the crash happen on Single or Multi-Segment Dimensions or both?

0 Likes
Message 8 of 8

BobbyC.Jones
Advocate
Advocate

Both.

 

<unrelated side rant>

I REALLY HATE that we have to handle single and multiple segments differently!  Sorry, but sometimes you just gotta let that stuff out  🙂

--
Bobby C. Jones
0 Likes