CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSA (https://www.cfd-online.com/Forums/ansa/)
-   -   Script to assign PIDs to Parts in Model Browser (https://www.cfd-online.com/Forums/ansa/243961-script-assign-pids-parts-model-browser.html)

mrosellini July 14, 2022 08:42

Script to assign PIDs to Parts in Model Browser
 
Hi,

I need to write a py script to create a new part in the Model Browser and assign certain PIDs to it. My code is the following:


Code:

import os
import ansa
from ansa import constants
from ansa import base

deck=constants.OPENFOAM

def main():
       
        #collect all entities
        ent = base.CollectEntities(deck,None,'SHELL_PROPERTY')
       
        filter=[]
       
        for i in ent:
               
                #find PIDs whose name matches a string named "string"

                if "string" in str(i._name):
                        print(i._name)                       
                        filter.append(i)               

        #create a new part named "New_Part"                                               
        part = base.NewPart('New Part')
       
        base.SetEntityPart(filter,part)
       
       
if __name__ == '__main__':
        main()


The code prints correctly the name of the filtered PIDs and creates the part "New_Part" in the Model Browser but does not assign any entity, so "New_Part" remains an empty part. How can I fix it?

Thank you in advance!


All times are GMT -4. The time now is 19:50.