-
-
July 4, 2024 at 9:26 amhallinenjesseSubscriberIt seems in newer versions of Mechanical we can use LabelManager class but in 2020 we have to use either functions in Graphics.InternalObject (like setnewanno3dtext, AddAnnoItemDS,...) or use javascript functions directly. Using those functions I can edit the Graphics Annotations table cells but the actual label won't appear in the 3d view and the new table row also disappears after focus changes.ÂSo it seems I'm missing the mouse click part where the label position is decided but I have no idea how to do that. I can't find the javascript function that gets executed on mouse click nor I can find any way to simulate the mouse click via script.ÂÂI also noticed the label may appear in position (0,0,0) if I run correct functions immediately after restarting the Mechanical. My guess is that it works because the mouse position has been initialised with (0,0,0).ÂAny ideas?
-
July 6, 2024 at 12:25 ammjmiddleAnsys Employee
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'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:
"Mechanical Application > Scripting in Mechanical Guide > Scripting Examples > Script Examples for Interacting with Results > Finding Hot Spots"
Look at the end of the code. It is done in a method similar to the following:resultObject=ExtAPI.DataModel.GetObjectsByName('Equivalent Stress')[0]
probeLabel = Graphics.LabelManager.CreateProbeLabel(resultObject)
probeLabel.Scoping.Node=1464
probeLabel.Note = "hello"This method will print a result value as well as the node ID and a label.
You can create a custom annotation in the following way, which will work in 2020 R1 as well as the current 2024 R1:
Point3D = ExtAPI.Graphics.CreateWorldPoint
Pt = Point3D(0.1, 0, 0)Â Â Â # XYZ location in geometry units
Label = ExtAPI.Graphics.Scene.Factory2D.CreateText(Pt, "Testing")
Label.Color = 0x000000Â Â Â # black
You can see the word "Testing" in the image above, but it doesn't show very well because it doesn'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'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't extend over the background.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's only available on Windows:
defResult = ExtAPI.DataModel.Project.Model.Analyses[0].Solution.Children[1]
ds=ExtAPI.DataModel.InternalObject["ds"]
labelID=ds.Graphics.AddLabel(defResult.ObjectId, 520, "DeformResult", 0.024, 0.004136, 0.0082857, 0x0000ff)
# Arguments are: ObjectID, classID(520 for result), X_coor, Y_coor, Z_coor, color
# This just creates an annotation probe with text "DeformResult" not the value of a result at that location
ExtAPI.Graphics.Redraw()You can see this above as the red background label.
The two examples above are only for custom text labels. This is no way to create an annotation by script entirely in 2020 R1 that displays a result value.
-
July 13, 2024 at 10:20 amhallinenjesseSubscriber
Thank you, that's some good info, and sorry for late reply, I thought my posts didn't get submitted because last week My Posts list was always empty.
-
November 19, 2024 at 10:57 amhallinenjesseSubscriberIt seems my other reply disappeared, so here it is again.ÂdefResult = ExtAPI.DataModel.Project.Model.Analyses[0].Solution.Children[1]ds=ExtAPI.DataModel.InternalObject["ds"]labelID=ds.Graphics.AddLabel(defResult.ObjectId, 520, "DeformResult", 0.024, 0.004136, 0.0082857, 0x0000ff)# Arguments are: ObjectID, classID(520 for result), X_coor, Y_coor, Z_coor, color# This just creates an annotation probe with text "DeformResult" not the value of a result at that locationExtAPI.Graphics.Redraw()ÂThe code above worked pretty well for our use case, because we only needed labels with some custom text, but now I got asked if we can edit those labels some more.So basically, is it possible to:
- Detect which label was clicked and get its labelID?
- Remove the line that connects the label and the Point?
- Temporary hide some of the labels?
I already checked the source code but couldn't find anything.
-
-
- The topic ‘How to add annotations or probes using python in Mechanical 2020 version?’ is closed to new replies.
- Problem with access to session files
- Ayuda con Error: “Unable to access the source: EngineeringData”
- Reaction forces and moments during random vibration at local coordinate systems
- At least one body has been found to have only 1 element in at least 2 directions
- Using APDL to extract stresses on a beam element.
- How to select the interface delamination surface of a laminate?
- Geometric stiffness matrix for solid elements
- Timestep range set for animation export
- Non-linear convergence issue
- Computation Accleration
-
1131
-
471
-
468
-
225
-
201
© 2024 Copyright ANSYS, Inc. All rights reserved.