


{"id":370845,"date":"2024-07-06T00:25:57","date_gmt":"2024-07-06T00:25:57","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/reply\/370845\/"},"modified":"2024-07-06T00:25:57","modified_gmt":"2024-07-06T00:25:57","slug":"370845","status":"publish","type":"reply","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/reply\/370845\/","title":{"rendered":"Reply To: How to add annotations or probes using python in Mechanical 2020 version?"},"content":{"rendered":"<p>&lt;p&gt;There is no javascript function to select a location\/node on the model or specify an xyz that project to the model in 2020 R1. This is in complied code. So you couldn&#8217;t make an annotation entirely by script in older versions. This is why they added the feature in newer versions. For 2022 R1 and later see documentation at:&lt;br&gt;&#8221;Mechanical Application &gt; Scripting in Mechanical Guide &gt; Scripting Examples &gt; Script Examples for Interacting with Results &gt; Finding Hot Spots&#8221;&lt;br&gt;Look at the end of the code. It is done in a method similar to the following:&lt;\/p&gt;&lt;p&gt;resultObject=ExtAPI.DataModel.GetObjectsByName(&#8216;Equivalent Stress&#8217;)[0]&lt;br clear=&#8221;none&#8221;&gt;probeLabel = Graphics.LabelManager.CreateProbeLabel(resultObject)&lt;br clear=&#8221;none&#8221;&gt;probeLabel.Scoping.Node=1464&lt;br clear=&#8221;none&#8221;&gt;probeLabel.Note = &#8220;hello&#8221;&lt;\/p&gt;&lt;p&gt;This method will print a result value as well as the node ID and a label.&lt;\/p&gt;&lt;p&gt;You can create a custom annotation in the following way, which will work in 2020 R1 as well as the current 2024 R1:&lt;\/p&gt;&lt;p&gt;Point3D = ExtAPI.Graphics.CreateWorldPoint&lt;br clear=&#8221;none&#8221;&gt;Pt = Point3D(0.1, 0, 0)&nbsp;&nbsp;&nbsp; # XYZ location in geometry units&lt;br clear=&#8221;none&#8221;&gt;Label = ExtAPI.Graphics.Scene.Factory2D.CreateText(Pt, &#8220;Testing&#8221;)&lt;br clear=&#8221;none&#8221;&gt;Label.Color = 0x000000&nbsp;&nbsp;&nbsp; # black&lt;br clear=&#8221;none&#8221;&gt;<img decoding=\"async\" src=\"https:\/\/innovationspace.ansys.com\/forum\/wp-content\/uploads\/sites\/2\/2024\/07\/06-07-2024-1720224992-mceclip0.png\" \/>&lt;br clear=&#8221;none&#8221;&gt;You can see the word &#8220;Testing&#8221; in the image above, but it doesn&#8217;t show very well because it doesn&#8217;t have a border with background color. This is an enhancement that has been submitted previously. You can use a different text color, but depending on the contour color where you place it, it still may not show well. Maybe if you use a color that&#8217;s not used in the contour, such as purple, assuming the independent bands are not turned on, of which the top band is purple. Or maybe white, assuming the label doesn&#8217;t extend over the background.&lt;\/p&gt;&lt;p&gt;Here is another way which uses the unpublished InternalObject. Think of this as a beta option. Anything under the InternalObject may not work right or at all; it may not be documented; and it&#8217;s only available on Windows:&lt;\/p&gt;&lt;p&gt;defResult = ExtAPI.DataModel.Project.Model.Analyses[0].Solution.Children[1]&lt;br&gt;ds=ExtAPI.DataModel.InternalObject[&#8220;ds&#8221;]&lt;br&gt;labelID=ds.Graphics.AddLabel(defResult.ObjectId, 520, &#8220;DeformResult&#8221;, 0.024, 0.004136, 0.0082857, 0x0000ff)&lt;br&gt;# Arguments are: ObjectID, classID(520 for result), X_coor, Y_coor, Z_coor, color&lt;br&gt;# This just creates an annotation probe with text &#8220;DeformResult&#8221; not the value of a result at that location&lt;br&gt;ExtAPI.Graphics.Redraw()&lt;\/p&gt;&lt;p&gt;You can see this above as the red background label.&lt;\/p&gt;&lt;p&gt;The two examples above are only for custom text labels.&nbsp;This is no way to create an annotation by script entirely in 2020 R1 that displays a result value.&lt;\/p&gt;<\/p>\n","protected":false},"template":"","class_list":["post-370845","reply","type-reply","status-publish","hentry"],"aioseo_notices":[],"acf":[],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies\/370845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/reply"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies\/370845\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=370845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}