General Mechanical

General Mechanical

Topics related to Mechanical Enterprise, Motion, Additive Print and more.

Getting type string data from Mechanical script to APDL Command Snippets (via ARGs or otherwise)

    • fruswrit
      Subscriber

      Hi,


      I want APDL to read my Named Selection... well, "names" created in Mechanical, and I have been unable to find a way to do it natively. I have been able to do it via Mechanical script (as follows, for those interested):


      named_selection_all=DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.NamedSelection)

      for ns in named_selection_all:

        print(ns.Name)


      I have been able even to access the ARGS from the script with this kind of command:

      command_snippet_1.InputArgument1 = r'35'


      However, it seems it is not possible to get it to accept a string. Or at least I have not been successful. The reason I want my APDL script to read those string is because I want it to export a series of results for each named selection with the filename being the name of said named selection.


      Any ideas? Thank you in advance!

    • Erik Kostson
      Ansys Employee
      Hi

      We can not put a text as an argument (ARG1 say).

      One workaround is to print with ACT the named selection to a text file and then read that text file with apdl (see perhaps TREAD and *DIM command on how to read in a text file). Then you will have access to all the names in a table (*DIM).

      Another way is to use just apdl commands to get the named selections since they are defined in the ds.dat as components (CM). These commands are relevant to get the total number of components and the name of the first and second one.
      *GET,mycm, COMP, 0,NCOMP *GET, myfcm,COMP, 1,NAME
      *GET, myscm,COMP, 2,NAME
      All the best

      Erik
    • fruswrit
      Subscriber
      Hi Thank you. I was trying to avoid it as it is kind of a pain, but it may be the only way.

      Cheers
    • Erik Kostson
      Ansys Employee
      actually this is quite easy and can be automated via a *do loop - so you can write to arg1 how many named selections you have (via act as you showed above) and
      then just do a loop in the command snippet to get all their names and to create .txt files with their names:
      imax=ARG1
      *DO, i, 1, imax, 1
      *GET,myfcm%i%,COMP,i,NAME
      *CFOPEN,myfcm%i% *CFCLOS
      *ENDDO

    • fruswrit
      Subscriber
      Wow, that might be the best of both worlds!

      I have tried it and it is working now (well, more or less, I think ):

      *DO LOOP ON PARAMETER= I FROM1.0000TO3.0000BY1.0000

      *GETMYFCM1FROMCOMPITEM=NAMEVALUE= RESPUESTA

      OPENED FILE= RESPUESTA FOR COMMAND FILE DATA


      COMMAND FILE CLOSED


      *ENDDOINDEX= I
      "RESPUESTA" was the name of my named selection indeed.
      I will have to check a little bit, as it does not appear to be looping beyond the first iteration. But certainly it works.

      Thank you for your extremely fast and helpful answers! You deserve a raise!
    • Erik Kostson
      Ansys Employee
      Yes it is quite OK I think - I tried it on my end and it generated all the files based on the number of named selections and their names, so seems to be working (in the solve.out it will not write out all the iterations in the loop).

      All the best

      Erik
Viewing 5 reply threads
  • The topic ‘Getting type string data from Mechanical script to APDL Command Snippets (via ARGs or otherwise)’ is closed to new replies.