Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessViolationException when accessing the Above, Below, Suffix, and Prefix properties of a Dimension
    primarykey
    data
    text
    <p>In Revit 2013 I have tool that I'm making that copies dimensions from one drafting view to another. I've got it to properly create a new version of a dimension including the <code>Curve</code>, <code>DimensionType</code>, and <code>References</code> but I'm having trouble with the properties <code>Above</code>, <code>Below</code>, <code>Prefix</code>, and <code>Suffix</code>. They copy just fine if at least one of them has a value. However, if none of them have a value then it will throw an <code>AccessViolationException</code> when I try to access them. I have tried to catch that exception but it bubbles up and it crashes Revit (I'm assuming it's caused by native code that fails).</p> <p>How can I check to see if these properties have any value when I do my copying without triggering this <code>AccessViolationException</code>?</p> <p><a href="http://forums.autodesk.com/t5/Autodesk-Revit-API/AccessViolationException-on-Above-Below-Prefix-and-Suffix-for/m-p/3765595" rel="nofollow">Autodesk Discussion Group Question</a></p> <p>The <code>DimensionData</code> class is my own used for storing the dimension information so that it can be used to create the dimension in a separate document.</p> <pre><code>private IEnumerable&lt;DimensionData&gt; GetDimensionDataSet(Document document, View view) { if (document == null) throw new ArgumentNullException("document"); if (view == null) throw new ArgumentNullException("view"); List&lt;DimensionData&gt; dimensionDataSet = new List&lt;DimensionData&gt;(); FilteredElementCollector dimensionCollector = new FilteredElementCollector(document, view.Id); dimensionCollector.OfClass(typeof(Dimension)); foreach (Dimension oldDimension in dimensionCollector) { Line oldDimensionLine = (Line)oldDimension.Curve; string dimensionTypeName = oldDimension.DimensionType.Name; List&lt;ElementId&gt; oldReferences = new List&lt;ElementId&gt;(); foreach (Reference oldReference in oldDimension.References) oldReferences.Add(oldReference.ElementId); DimensionData dimensionData; try { string prefix = oldDimension.Prefix; dimensionData = new DimensionData(oldDimensionLine, oldReferences, dimensionTypeName, prefix, oldDimension.Suffix, oldDimension.Above, oldDimension.Below); } catch (AccessViolationException) { dimensionData = new DimensionData(oldDimensionLine, oldReferences, dimensionTypeName); } dimensionDataSet.Add(dimensionData); } return dimensionDataSet; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload