News: Need training? HyperSizer Training Videos are available now! Learn more here: https://hypersizer.com/trainingevents/e-learning/

Author Topic: Setting Concept Variables after Switching Concepts via COM  (Read 17576 times)

mjdiaz89

  • *
  • Posts: 1
    •  
Setting Concept Variables after Switching Concepts via COM
« on: April 10, 2014, 01:08:38 PM »
Very similar to http://hypersizer.com/forum/index.php/topic,455.0.html, in that it was in reference to setting concepts via the COM, I have a group in which I can successfully change its concept using the SetConcepts method as per http://hypersizer.com/help_7.0/index.php#COM/Object/Group.php?Highlight=SetConcepts; however, I encounter an error when I attempt to set its sizing variables as per http://hypersizer.com/help_7.0/index.php#COM/Object/ConceptVariableCol.php.  This is the error I get in Python

Code: [Select]
File "<COMObject GetGroup>", line 2, in Save
com_error: (-2147352567, 'Exception occurred.', (0, u'Group', u"Application Error in Group::Save [Function]()\r\n\r\nLine #20, Error #3201, Application Error in MaterialVariableCol::Save [Function]()\r\n\r\nLine #40, Error #3201, You cannot add or change a record because a related record is required in table 'group_variable'.", None, 1003201, -2146825087), None)

This is the code snippet I am implementing
Code: [Select]
#Example: go from One Stack Unstiffened concept to Integral Blade Stiffened

#as per http://hypersizer.com/help_7.0/index.php#COM/Object/Group.php?Highlight=SetConcepts

conceptId = BeamPanelConcept.bpcBlade
group = hs.Projects(1).Groups.GetGroup(component)
group.SetConcepts(conceptID) #I can confirm via HS GUI that the correct concept is selected

#as per http://hypersizer.com/help_7.0/index.php#COM/Object/ConceptVariableCol.php

#Example: change web thickness variable bounds
variableId = VariableParameterDefinition.vpdWeb_ThicknessMaterial
 
variables = group.Variables
variable = variables.GetVariable(conceptId, variableId)
variable.MinBound = 0.1
variable.MaxBound = 0.6
variable.StepSize = 0.12
variables.Save()

Can you provide any guidance?

Thank you very much for your time.

-M

Ryan

  • Administrator
  • *****
  • Posts: 145
    •  
Re: Setting Concept Variables after Switching Concepts via COM
« Reply #1 on: April 11, 2014, 08:44:57 AM »
I am not able to repeat this error. I was able to run the following code using the "Training - AP1 i02 - Detailed Sizing" project that ships in the Training database. You can import this project from the training database to your own database (File | Import). I was also able to run this code when component was initially a One Stack concept.

Code: [Select]
def main(databasePath, projectName):

    hs, project = OpenHyperSizerProject(databasePath, projectName)
       
    component = project.Components.GetComponent(52)
    groupId = component.GroupId
    group = project.Groups.GetGroup(groupId)
   
    conceptId = BeamPanelConcept.bpcBlade
    variableId = VariableParameterDefinition.vpdWeb_ThicknessMaterial
   
    # Set concept.
    group.SetConcepts(conceptId)
    print (groupId)
   
    # Set variables.
    variables = group.Variables
    variable = variables.GetVariable(conceptId, variableId)
    variable.MinBound = 0.1
    variable.MaxBound = 0.6
    variable.StepSize = 0.12
    variables.Save()

In your exception it lists "COMObject GetGroup" as the error location yet the the message indicates the error occurs in Group.Save() (called when using variables.Save()). Perhaps this line in an issue:

Code: [Select]
group = hs.Projects(1).Groups.GetGroup(component)
When calling GetGroup() you need to pass in the component ID not the component object itself.

The error message also indicates that it's trying to save material variables, yet in the code I don't see you modifying any materials.

Can you run the attached code? Perhaps it will help identify the issue in your code.

-Ryan