Set Active Unit System to Solution Unit System

Hello.

To avoid the possibility of someone running a post-processing extension in the wrong unit system, I was hoping to read the solution coordinate system and set the active system to it, irrespective of if they've changed the active system. However I'm struggling to get it to work.

I point to the solution with:
SolvLoc=ExtAPI.DataModel.Project.Model.Analyses[0].Solution

and assign the solution unit system:
SolvUnit=SolvLoc.SolutionUnitSystem

If I get type (SolvUnit.GetType() )it returns:

Ansys.ACT.Interfaces.Common.MechanicalUnitSystem

If I get the active system type (ExtAPI.Application.ActiveUnitSystem.GetType() ) it returns the same.

The tooltip suggests I should be able to use it to set the system:
ExtAPI.Application.ActiveUnitSystem=SolvUnit

but this returns the error:
Specified argument was out of the range of valid values.
Parameter name: ConsistentMKS

I'm sure there is something simple I'm missing, but can anyone help explain how to resolve this

Best Answer

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 449
    250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
    ✭✭✭✭
    edited September 12 Answer ✓

    @Liam Mealey

    Solver unit system expects a "Consistent Unit System" while the project unit system expects a "Standard Unit System". As your error points out, you are trying to assign a "Consistent Unit System" to project. There are only 6 "Consistent Unit Systems" available in Mechanical (see below). A solution I see here is you create an internal mapper, to map consistent to standard. For example ConsistentNMM -> StandardNMMton

Answers

  • Liam Mealey
    Liam Mealey Member Posts: 2
    First Comment
    **

    Thank you.

    I think I was thrown because if I do a dir on ExtAPI.Application.ActiveUnitSystem in the shell, it lists the Consistent systems, and so assumed they would be valid assignments.

    You've pointed me at a solution though, so thanks