<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Direct context 3D over view in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13273540#M1351</link>
    <description>&lt;P&gt;Hello. I asked Gemini for you, and it replies:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="model-response-message-contentr_87938809073b5b77" class="markdown markdown-main-panel stronger" dir="ltr"&gt;
&lt;P data-sourcepos="1:1-1:79"&gt;Subject: Re: Direct Context 3D - Ensuring 2D Geometry Visibility in Revit Views&lt;/P&gt;
&lt;P data-sourcepos="3:1-3:282"&gt;You're encountering a common challenge with DirectContext3D: ensuring your geometry is consistently visible across different view types and display settings. The key lies in understanding how Revit handles view projections, clipping planes, and the DirectContext3D drawing pipeline.&lt;/P&gt;
&lt;P data-sourcepos="5:1-5:57"&gt;Here's a breakdown of the issues and how to address them:&lt;/P&gt;
&lt;P data-sourcepos="7:1-7:30"&gt;&lt;STRONG&gt;Understanding the Problem:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-sourcepos="9:1-13:0"&gt;
&lt;LI data-sourcepos="9:1-9:210"&gt;&lt;STRONG&gt;View Projections:&lt;/STRONG&gt; Revit views are projections of the 3D model onto a 2D plane. Plan views project downwards, elevations and sections project orthogonally, and perspective views project with perspective.&lt;/LI&gt;
&lt;LI data-sourcepos="10:1-10:227"&gt;&lt;STRONG&gt;Clipping Planes:&lt;/STRONG&gt; Views have clipping planes that define the visible portion of the model. These include view range (in plan views), section boxes, and far clipping planes. Geometry outside these planes is not displayed.&lt;/LI&gt;
&lt;LI data-sourcepos="11:1-11:283"&gt;&lt;STRONG&gt;DirectContext3D Drawing:&lt;/STRONG&gt; DirectContext3D draws directly into the view's graphics pipeline. However, it's still subject to the view's projection and clipping. If your geometry isn't correctly positioned relative to these, it might be clipped or projected in an unexpected way.&lt;/LI&gt;
&lt;LI data-sourcepos="12:1-13:0"&gt;&lt;STRONG&gt;Graphics Pipeline and Z-Fighting:&lt;/STRONG&gt; Even if your geometry is within the view's clipping, it might still have z-fighting issues if it's coplanar with existing model elements. This causes flickering or parts of the geometry to disappear.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P data-sourcepos="14:1-14:33"&gt;&lt;STRONG&gt;Solutions and Best Practices:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL data-sourcepos="16:1-62:0"&gt;
&lt;LI data-sourcepos="16:1-42:0"&gt;
&lt;P data-sourcepos="16:5-16:183"&gt;&lt;STRONG&gt;Projecting onto the View Plane:&lt;/STRONG&gt; The most robust solution is to project your 2D geometry onto the view's plane. This ensures that the geometry is drawn in the correct 2D space.&lt;/P&gt;
&lt;UL data-sourcepos="18:5-21:0"&gt;
&lt;LI data-sourcepos="18:5-18:114"&gt;&lt;STRONG&gt;Get the View's Transformation:&lt;/STRONG&gt; Use &lt;CODE&gt;view.GetTransform()&lt;/CODE&gt; to get the transformation matrix of the view.&lt;/LI&gt;
&lt;LI data-sourcepos="19:5-19:174"&gt;&lt;STRONG&gt;Project Points:&lt;/STRONG&gt; Transform the points of your 2D geometry using the inverse of the view's transformation. This effectively projects the points onto the view plane.&lt;/LI&gt;
&lt;LI data-sourcepos="20:5-21:0"&gt;&lt;STRONG&gt;Example (Conceptual C#):&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="code-block ng-tns-c1602499850-26 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-26 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-26"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-26 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-26 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-26"&gt;
&lt;PRE class="ng-tns-c1602499850-26"&gt;&lt;CODE class="code-container ng-tns-c1602499850-26 formatted" role="text" data-test-id="code-content" data-sourcepos="22:5-41:10"&gt;View view = doc.ActiveView;
Transform viewTransform = view.GetTransform();
Transform inverseViewTransform = viewTransform.Inverse;

&lt;SPAN class="hljs-comment"&gt;// Your 2D points (in model space)&lt;/SPAN&gt;
XYZ p1 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);
XYZ p2 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);
XYZ p3 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);
XYZ p4 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);

&lt;SPAN class="hljs-comment"&gt;// Project the points onto the view plane&lt;/SPAN&gt;
XYZ projectedP1 = inverseViewTransform.OfPoint(p1);
XYZ projectedP2 = inverseViewTransform.OfPoint(p2);
XYZ projectedP3 = inverseViewTransform.OfPoint(p3);
XYZ projectedP4 = inverseViewTransform.OfPoint(p4);

&lt;SPAN class="hljs-comment"&gt;// Use the projected points to create your DirectContext3D geometry&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="43:1-56:0"&gt;
&lt;P data-sourcepos="43:5-43:239"&gt;&lt;STRONG&gt;Slight Offset (Z-Fighting Avoidance):&lt;/STRONG&gt; To avoid z-fighting, give your DirectContext3D geometry a very slight offset in the direction of the view's normal vector. This pushes the geometry just in front of the existing model elements.&lt;/P&gt;
&lt;UL data-sourcepos="45:5-47:0"&gt;
&lt;LI data-sourcepos="45:5-45:140"&gt;&lt;STRONG&gt;Get the View's Direction:&lt;/STRONG&gt; For plan views, this is typically &lt;CODE&gt;XYZ.BasisZ&lt;/CODE&gt;. For elevations and sections, use &lt;CODE&gt;view.ViewDirection&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI data-sourcepos="46:5-47:0"&gt;&lt;STRONG&gt;Offset:&lt;/STRONG&gt; Add a small multiple of the view direction to your geometry's points.&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="code-block ng-tns-c1602499850-27 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-27 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-27"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-27 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-27 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-27"&gt;
&lt;PRE class="ng-tns-c1602499850-27"&gt;&lt;CODE class="code-container ng-tns-c1602499850-27 formatted" role="text" data-test-id="code-content" data-sourcepos="48:5-55:10"&gt;XYZ viewDirection = view.ViewDirection; &lt;SPAN class="hljs-comment"&gt;// Or XYZ.BasisZ for plan views&lt;/SPAN&gt;
&lt;SPAN class="hljs-built_in"&gt;double&lt;/SPAN&gt; offset = &lt;SPAN class="hljs-number"&gt;0.001&lt;/SPAN&gt;; &lt;SPAN class="hljs-comment"&gt;// A very small offset&lt;/SPAN&gt;
XYZ offsetVector = viewDirection.Multiply(offset);

projectedP1 = projectedP1.Add(offsetVector); &lt;SPAN class="hljs-comment"&gt;// Apply offset to all points&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="57:1-58:0"&gt;
&lt;P data-sourcepos="57:5-57:307"&gt;&lt;STRONG&gt;Section Views and Cut Planes:&lt;/STRONG&gt; In section views, ensure your geometry is within the section box. You can get the section box using &lt;CODE&gt;view.GetSectionBox()&lt;/CODE&gt;. If you need to draw geometry outside the section box, you'll need to use a different approach (e.g., creating a detail line in the section view).&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="59:1-60:0"&gt;
&lt;P data-sourcepos="59:5-59:245"&gt;&lt;STRONG&gt;Hidden Line vs. Shaded Views:&lt;/STRONG&gt; The visibility of DirectContext3D geometry is generally consistent across different visual styles. However, ensure that the line weight and color you're using are appropriate for the view's background color.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="61:1-62:0"&gt;
&lt;P data-sourcepos="61:5-61:153"&gt;&lt;STRONG&gt;BrepBuilder and Face Creation:&lt;/STRONG&gt; When using &lt;CODE&gt;BrepBuilder&lt;/CODE&gt;, make sure the face normal is oriented correctly. This affects how the face is displayed.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P data-sourcepos="63:1-63:34"&gt;&lt;STRONG&gt;Complete Example (Conceptual):&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV class="code-block ng-tns-c1602499850-28 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-28 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-28"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-28 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-28 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-28"&gt;
&lt;PRE class="ng-tns-c1602499850-28"&gt;&lt;CODE class="code-container ng-tns-c1602499850-28 formatted" role="text" data-test-id="code-content" data-sourcepos="65:1-78:6"&gt;&lt;SPAN class="hljs-comment"&gt;// ... (Get view, points, etc.)&lt;/SPAN&gt;

&lt;SPAN class="hljs-comment"&gt;// Project points and apply offset&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;foreach&lt;/SPAN&gt; (XYZ point &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; points)
{
    XYZ projectedPoint = inverseViewTransform.OfPoint(point);
    projectedPoint = projectedPoint.Add(offsetVector);
    &lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
}

&lt;SPAN class="hljs-comment"&gt;// Create DirectContext3D geometry using the projected and offset points&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P data-sourcepos="80:1-80:320"&gt;By combining projection onto the view plane with a small offset, you can ensure that your DirectContext3D geometry is consistently visible and avoids z-fighting, regardless of the view type or display style. Remember to handle exceptions and consider performance implications when working with large amounts of geometry.&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;This approach addresses the core issue of incorrect placement relative to the view's coordinate system and clipping planes. It provides a more robust and reliable solution compared to simply relying on bounding boxes or other indirect methods.&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;Please let us know whether this helps or you find a better solution. Thank you!&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 21 Jan 2025 13:19:49 GMT</pubDate>
    <dc:creator>jeremy_tammik</dc:creator>
    <dc:date>2025-01-21T13:19:49Z</dc:date>
    <item>
      <title>Direct context 3D over view</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13273446#M1350</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am using direct context 3D to draw marking rectangle on view, my requirement is marking rectangle should be on top. In 3D view I could do this by using bounding of entire model. In 2D views also I am able to do it by using viewplan or cropBox. But I observed that in some cases rectangle (its a rectangular face created using Brepbuilder) the geometry is not shown as it is not drawn at correct plane may be, in some cases (ViewSection) if I make 'shadow on' then geometry is visible. I have just started to understand Revit , how I can make sure that my geometry is always visible irrespective of display style \mode using Direct context 3D. I want to understand Revit views\ cut planes \sections and create 2D geometry always on top of visible elements.&lt;/P&gt;&lt;P&gt;What things&amp;nbsp; I need to consider to make sure that 2D planar geometry is visible..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Dhanraj D&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 12:12:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13273446#M1350</guid>
      <dc:creator>dhanraj.dhokale</dc:creator>
      <dc:date>2025-01-21T12:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Direct context 3D over view</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13273540#M1351</link>
      <description>&lt;P&gt;Hello. I asked Gemini for you, and it replies:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="model-response-message-contentr_87938809073b5b77" class="markdown markdown-main-panel stronger" dir="ltr"&gt;
&lt;P data-sourcepos="1:1-1:79"&gt;Subject: Re: Direct Context 3D - Ensuring 2D Geometry Visibility in Revit Views&lt;/P&gt;
&lt;P data-sourcepos="3:1-3:282"&gt;You're encountering a common challenge with DirectContext3D: ensuring your geometry is consistently visible across different view types and display settings. The key lies in understanding how Revit handles view projections, clipping planes, and the DirectContext3D drawing pipeline.&lt;/P&gt;
&lt;P data-sourcepos="5:1-5:57"&gt;Here's a breakdown of the issues and how to address them:&lt;/P&gt;
&lt;P data-sourcepos="7:1-7:30"&gt;&lt;STRONG&gt;Understanding the Problem:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL data-sourcepos="9:1-13:0"&gt;
&lt;LI data-sourcepos="9:1-9:210"&gt;&lt;STRONG&gt;View Projections:&lt;/STRONG&gt; Revit views are projections of the 3D model onto a 2D plane. Plan views project downwards, elevations and sections project orthogonally, and perspective views project with perspective.&lt;/LI&gt;
&lt;LI data-sourcepos="10:1-10:227"&gt;&lt;STRONG&gt;Clipping Planes:&lt;/STRONG&gt; Views have clipping planes that define the visible portion of the model. These include view range (in plan views), section boxes, and far clipping planes. Geometry outside these planes is not displayed.&lt;/LI&gt;
&lt;LI data-sourcepos="11:1-11:283"&gt;&lt;STRONG&gt;DirectContext3D Drawing:&lt;/STRONG&gt; DirectContext3D draws directly into the view's graphics pipeline. However, it's still subject to the view's projection and clipping. If your geometry isn't correctly positioned relative to these, it might be clipped or projected in an unexpected way.&lt;/LI&gt;
&lt;LI data-sourcepos="12:1-13:0"&gt;&lt;STRONG&gt;Graphics Pipeline and Z-Fighting:&lt;/STRONG&gt; Even if your geometry is within the view's clipping, it might still have z-fighting issues if it's coplanar with existing model elements. This causes flickering or parts of the geometry to disappear.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P data-sourcepos="14:1-14:33"&gt;&lt;STRONG&gt;Solutions and Best Practices:&lt;/STRONG&gt;&lt;/P&gt;
&lt;OL data-sourcepos="16:1-62:0"&gt;
&lt;LI data-sourcepos="16:1-42:0"&gt;
&lt;P data-sourcepos="16:5-16:183"&gt;&lt;STRONG&gt;Projecting onto the View Plane:&lt;/STRONG&gt; The most robust solution is to project your 2D geometry onto the view's plane. This ensures that the geometry is drawn in the correct 2D space.&lt;/P&gt;
&lt;UL data-sourcepos="18:5-21:0"&gt;
&lt;LI data-sourcepos="18:5-18:114"&gt;&lt;STRONG&gt;Get the View's Transformation:&lt;/STRONG&gt; Use &lt;CODE&gt;view.GetTransform()&lt;/CODE&gt; to get the transformation matrix of the view.&lt;/LI&gt;
&lt;LI data-sourcepos="19:5-19:174"&gt;&lt;STRONG&gt;Project Points:&lt;/STRONG&gt; Transform the points of your 2D geometry using the inverse of the view's transformation. This effectively projects the points onto the view plane.&lt;/LI&gt;
&lt;LI data-sourcepos="20:5-21:0"&gt;&lt;STRONG&gt;Example (Conceptual C#):&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="code-block ng-tns-c1602499850-26 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-26 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-26"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-26 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-26 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-26"&gt;
&lt;PRE class="ng-tns-c1602499850-26"&gt;&lt;CODE class="code-container ng-tns-c1602499850-26 formatted" role="text" data-test-id="code-content" data-sourcepos="22:5-41:10"&gt;View view = doc.ActiveView;
Transform viewTransform = view.GetTransform();
Transform inverseViewTransform = viewTransform.Inverse;

&lt;SPAN class="hljs-comment"&gt;// Your 2D points (in model space)&lt;/SPAN&gt;
XYZ p1 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);
XYZ p2 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);
XYZ p3 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);
XYZ p4 = &lt;SPAN class="hljs-keyword"&gt;new&lt;/SPAN&gt; XYZ(&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;, &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;);

&lt;SPAN class="hljs-comment"&gt;// Project the points onto the view plane&lt;/SPAN&gt;
XYZ projectedP1 = inverseViewTransform.OfPoint(p1);
XYZ projectedP2 = inverseViewTransform.OfPoint(p2);
XYZ projectedP3 = inverseViewTransform.OfPoint(p3);
XYZ projectedP4 = inverseViewTransform.OfPoint(p4);

&lt;SPAN class="hljs-comment"&gt;// Use the projected points to create your DirectContext3D geometry&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="43:1-56:0"&gt;
&lt;P data-sourcepos="43:5-43:239"&gt;&lt;STRONG&gt;Slight Offset (Z-Fighting Avoidance):&lt;/STRONG&gt; To avoid z-fighting, give your DirectContext3D geometry a very slight offset in the direction of the view's normal vector. This pushes the geometry just in front of the existing model elements.&lt;/P&gt;
&lt;UL data-sourcepos="45:5-47:0"&gt;
&lt;LI data-sourcepos="45:5-45:140"&gt;&lt;STRONG&gt;Get the View's Direction:&lt;/STRONG&gt; For plan views, this is typically &lt;CODE&gt;XYZ.BasisZ&lt;/CODE&gt;. For elevations and sections, use &lt;CODE&gt;view.ViewDirection&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI data-sourcepos="46:5-47:0"&gt;&lt;STRONG&gt;Offset:&lt;/STRONG&gt; Add a small multiple of the view direction to your geometry's points.&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="code-block ng-tns-c1602499850-27 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-27 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-27"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-27 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-27 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-27"&gt;
&lt;PRE class="ng-tns-c1602499850-27"&gt;&lt;CODE class="code-container ng-tns-c1602499850-27 formatted" role="text" data-test-id="code-content" data-sourcepos="48:5-55:10"&gt;XYZ viewDirection = view.ViewDirection; &lt;SPAN class="hljs-comment"&gt;// Or XYZ.BasisZ for plan views&lt;/SPAN&gt;
&lt;SPAN class="hljs-built_in"&gt;double&lt;/SPAN&gt; offset = &lt;SPAN class="hljs-number"&gt;0.001&lt;/SPAN&gt;; &lt;SPAN class="hljs-comment"&gt;// A very small offset&lt;/SPAN&gt;
XYZ offsetVector = viewDirection.Multiply(offset);

projectedP1 = projectedP1.Add(offsetVector); &lt;SPAN class="hljs-comment"&gt;// Apply offset to all points&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="57:1-58:0"&gt;
&lt;P data-sourcepos="57:5-57:307"&gt;&lt;STRONG&gt;Section Views and Cut Planes:&lt;/STRONG&gt; In section views, ensure your geometry is within the section box. You can get the section box using &lt;CODE&gt;view.GetSectionBox()&lt;/CODE&gt;. If you need to draw geometry outside the section box, you'll need to use a different approach (e.g., creating a detail line in the section view).&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="59:1-60:0"&gt;
&lt;P data-sourcepos="59:5-59:245"&gt;&lt;STRONG&gt;Hidden Line vs. Shaded Views:&lt;/STRONG&gt; The visibility of DirectContext3D geometry is generally consistent across different visual styles. However, ensure that the line weight and color you're using are appropriate for the view's background color.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI data-sourcepos="61:1-62:0"&gt;
&lt;P data-sourcepos="61:5-61:153"&gt;&lt;STRONG&gt;BrepBuilder and Face Creation:&lt;/STRONG&gt; When using &lt;CODE&gt;BrepBuilder&lt;/CODE&gt;, make sure the face normal is oriented correctly. This affects how the face is displayed.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P data-sourcepos="63:1-63:34"&gt;&lt;STRONG&gt;Complete Example (Conceptual):&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV class="code-block ng-tns-c1602499850-28 ng-trigger ng-trigger-codeBlockRevealAnimation"&gt;
&lt;DIV class="code-block-decoration ng-tns-c1602499850-28 header-formatted gds-title-s ng-star-inserted"&gt;&lt;SPAN class="ng-tns-c1602499850-28"&gt;C#&lt;/SPAN&gt;
&lt;DIV class="buttons ng-tns-c1602499850-28 ng-star-inserted"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="ng-tns-c1602499850-28 formatted-code-block-internal-container"&gt;
&lt;DIV class="animated-opacity ng-tns-c1602499850-28"&gt;
&lt;PRE class="ng-tns-c1602499850-28"&gt;&lt;CODE class="code-container ng-tns-c1602499850-28 formatted" role="text" data-test-id="code-content" data-sourcepos="65:1-78:6"&gt;&lt;SPAN class="hljs-comment"&gt;// ... (Get view, points, etc.)&lt;/SPAN&gt;

&lt;SPAN class="hljs-comment"&gt;// Project points and apply offset&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;foreach&lt;/SPAN&gt; (XYZ point &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; points)
{
    XYZ projectedPoint = inverseViewTransform.OfPoint(point);
    projectedPoint = projectedPoint.Add(offsetVector);
    &lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
}

&lt;SPAN class="hljs-comment"&gt;// Create DirectContext3D geometry using the projected and offset points&lt;/SPAN&gt;
&lt;SPAN class="hljs-comment"&gt;// ...&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P data-sourcepos="80:1-80:320"&gt;By combining projection onto the view plane with a small offset, you can ensure that your DirectContext3D geometry is consistently visible and avoids z-fighting, regardless of the view type or display style. Remember to handle exceptions and consider performance implications when working with large amounts of geometry.&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;This approach addresses the core issue of incorrect placement relative to the view's coordinate system and clipping planes. It provides a more robust and reliable solution compared to simply relying on bounding boxes or other indirect methods.&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;Please let us know whether this helps or you find a better solution. Thank you!&lt;/P&gt;
&lt;P data-sourcepos="82:1-82:243"&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Jan 2025 13:19:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13273540#M1351</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2025-01-21T13:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Direct context 3D over view</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13289801#M1352</link>
      <description>&lt;P&gt;Thanks for the detail explanation , I tried this for most of views I could resolve issue with this , but still I am getting in some case issue or sometimes just by clicking on crop region on\off geometry is visible.. Will check this there may be some issue in my code..&lt;/P&gt;&lt;P&gt;Also I see for view sheet we can not use Direct context 3D is there any other mechanism to draw temporary graphics on view sheet..&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 04:31:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13289801#M1352</guid>
      <dc:creator>dhanraj.dhokale</dc:creator>
      <dc:date>2025-01-30T04:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Direct context 3D over view</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13289936#M1353</link>
      <description>&lt;P&gt;Thank you for the appreciation. My pleasure, and hopefully the LLM's as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, as the name implies, DirectContext3D is not useful for a sheet view, unfortunately. Here are The Building Coder posts I found on the topic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2017/04/whats-new-in-the-revit-2018-api.html#3.26" target="_blank"&gt;What's New in the Revit 2018 API → DirectContext3D&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2020/10/onbox-directcontext-jig-and-no-cdn.html#3" target="_blank"&gt;DirectContext Rectangle Jig&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2022/09/point-clouds-coloured-triangles-and-faces.html" target="_blank"&gt;Point Clouds, Coloured Triangles and Faces&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2024/01/directcontext3d-ids-and-linked-section-elements-.html" target="_blank"&gt;DirectContext3D, Ids and Linked Section Elements&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2025/01/llm-prompting-rag-ingestion-and-new-projects.html" target="_blank"&gt;LLM Prompting, RAG Ingestion and New Projects&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think the Revit API offers any other transient grphics options. You could maybe either create non-transient persistent Revit geometry, or use the pure Windows API to display transient objects on the screen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 07:11:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/direct-context-3d-over-view/m-p/13289936#M1353</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2025-01-30T07:11:23Z</dc:date>
    </item>
  </channel>
</rss>

