


{"id":392277,"date":"2024-10-31T15:34:42","date_gmt":"2024-10-31T15:34:42","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/adding-end-releases-in-scripting\/"},"modified":"2024-10-31T15:34:42","modified_gmt":"2024-10-31T15:34:42","slug":"adding-end-releases-in-scripting","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/adding-end-releases-in-scripting\/","title":{"rendered":"Adding End Releases in Scripting"},"content":{"rendered":"<p>&lt;p&gt;Hello,&lt;br&gt;&lt;br&gt;I have been attempting over the course of this afternoon to add end releases to an imported line body model. The model has shared topology from the discovery export.&nbsp;&lt;br&gt;There are 8 edges, 9 vertices in my model. The code I have is producing 8 end releases, however, an end release can only be scoped to a vertex which connects to more than 1 beam, as such in my model I should only have 6 end releases.&nbsp;&lt;br&gt;&lt;br&gt;printing vertex_beam_count produces:&lt;br&gt;{247: 2, 248: 1, 251: 2, 252: 2, 253: 2, 254: 2, 257: 1, 258: 3, 259: 1}&lt;br&gt;So that&#8217;s behaving correctly, showing 6 vertices with more than one beam attached.&lt;br&gt;&lt;br&gt;Where am i going wrong with the logic?&nbsp;&nbsp;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;\/p&gt;&lt;p&gt;# Beam Model Setup&lt;\/p&gt;&lt;p&gt;# Section 1 &#8211; General Setup&lt;br&gt;model = ExtAPI.DataModel.Project.Model&lt;br&gt;geom = model.Geometry&lt;br&gt;mesh = model.Mesh&lt;br&gt;connections = model.Connections&lt;br&gt;materials = model.Materials&lt;br&gt;analysis = model.Analyses[0]&lt;br&gt;solution = analysis.Solution&lt;\/p&gt;&lt;p&gt;# Section 4 &#8211; Create end Releases at each qualifying vertex (more than one beam connected)&lt;\/p&gt;&lt;p&gt;Verts = []&lt;br&gt;Edges = []&lt;br&gt;with Transaction():&lt;br&gt;&nbsp; &nbsp; # Loop through all assemblies, parts, and bodies&lt;br&gt;&nbsp; &nbsp; for Assembly in ExtAPI.DataModel.GeoData.Assemblies:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp;for Part in Assembly.AllParts:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for Body in Part.Bodies:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for Edge in Body.Edges:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Edges.append(Edge)&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Collect vertices from edges&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for Vertex in Edge.Vertices:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Verts.append(Vertex)&lt;\/p&gt;&lt;p&gt;&nbsp;&lt;\/p&gt;&lt;p&gt;# Dictionary to count connections at each vertex using vertex ID&lt;br&gt;vertex_beam_count = {}&lt;\/p&gt;&lt;p&gt;# Count beams (edges) connected to each vertex&lt;br&gt;for edge in Edges:&lt;br&gt;&nbsp; &nbsp; for vertex in edge.Vertices:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; vertex_id = vertex.Id &nbsp;# Use unique identifier for each vertex&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; if vertex_id not in vertex_beam_count:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vertex_beam_count[vertex_id] = 0&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; vertex_beam_count[vertex_id] += 1&lt;\/p&gt;&lt;p&gt;# Set to track edges where end releases have already been added&lt;br&gt;processed_edges = set()&lt;\/p&gt;&lt;p&gt;# Add end releases only at edges connected by vertices with more than one beam&lt;br&gt;with Transaction():&lt;br&gt;&nbsp; &nbsp; for edge in Edges:&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; edge_id = edge.Id &nbsp;# Unique ID of the edge&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; # Check if either of the edge&#8217;s vertices has more than one connected beam&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; if edge_id not in processed_edges and any(vertex_beam_count[vertex.Id] &gt; 1 for vertex in edge.Vertices):&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Add an end release to the current edge&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end_release = connections.AddEndRelease()&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; processed_edges.add(edge_id) &nbsp;# Mark edge as processed to avoid duplicates&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Configure end release properties if needed&lt;\/p&gt;&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;\/p&gt;<\/p>\n","protected":false},"template":"","class_list":["post-392277","topic","type-topic","status-publish","hentry","topic-tag-end-release-1","topic-tag-mechanical","topic-tag-python-scripting","topic-tag-structures"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_author_ip":["77.104.130.57"],"_btv_view_count":["182"],"_bbp_topic_status":["unanswered"],"_bbp_subscription":["349602"],"_bbp_topic_id":["392277"],"_bbp_forum_id":["153047"],"_bbp_engagement":["349602"],"_bbp_voice_count":["1"],"_bbp_reply_count":["1"],"_bbp_last_reply_id":["392278"],"_bbp_last_active_id":["392278"],"_bbp_last_active_time":["2024-10-31 15:37:44"]},"test":"joe-lindleyredengineering-co-uk"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/392277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/392277\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=392277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}