C# (API) Load Combinations null value

C# (API) Load Combinations null value

Benjamin.Ainsworth
Contributor Contributor
442 Views
3 Replies
Message 1 of 4

C# (API) Load Combinations null value

Benjamin.Ainsworth
Contributor
Contributor

I am busy trying to create a load combination in Robot using C# API and visual studio.  My code can be seen below:

 

Structure = Robot.Project.Structure;
CaseCollection = new RobotCaseCollection();
RobotLoadCombination = new RobotCaseCombination();


CaseCollection = Structure.Cases.GetAll();
int loadCombinationNumber = Structure.Cases.FreeNumber;
int loadCaseFactorNumber;

//ULS or SLS condition

if (loadCombination.Condition == "ULS")
{
RobotLoadCombination = Structure.Cases.CreateCombination(loadCombinationNumber, loadCombination.Designation, IRobotCombinationType.I_CBT_ULS, IRobotCaseNature.I_CN_SEISMIC, IRobotCaseAnalizeType.I_CAT_COMB_CODE);
}
else
{ //SLS
RobotLoadCombination = Structure.Cases.CreateCombination(loadCombinationNumber, loadCombination.Designation, IRobotCombinationType.I_CBT_SLS, IRobotCaseNature.I_CN_SEISMIC, IRobotCaseAnalizeType.I_CAT_COMB_CODE);
}

//Assign Load Case Factors to Load combination
CaseCollection = Structure.Cases.GetAll();
foreach (LoadCaseFactor loadCaseFactor in loadCaseFactors)
{
loadCaseFactorNumber = LoadCaseExist(CaseCollection, loadCaseFactor.LoadCaseName); //This is a function to retrieve the exisiting case number
RobotLoadCombination.CaseFactors.New(loadCaseFactorNumber, loadCaseFactor.Factor); //The error occurs here.

}

 

BenjaminAinsworth_0-1708517078224.png

The above error is showing because RobotLoadCombination is null, as can be seen here:

BenjaminAinsworth_1-1708517139327.png

But it only becomes null after the CreateCombination rule has run.

I have exactly the same line of code in VBA and it runs fine. Am I missing something.

 

 

0 Likes
Accepted solutions (1)
443 Views
3 Replies
Replies (3)
Message 2 of 4

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

hi @Benjamin.Ainsworth 

Private Sub CreateCombination()
  Dim RobApp As RobotApplication
  Set RobApp = New RobotApplication
  
  Dim Cases As RobotCaseServer, Comb As IRobotCaseCombination, CaseFactors As RobotCaseFactorMngr
  Set Cases = RobApp.Project.Structure.Cases
  
  CmbNbr = Cases.FreeNumber
  Set Comb = Cases.CreateCombination(CmbNbr, "COMB" & CmbNbr & " [ULS] 1*1.35 + 2*1.5", I_CBT_ULS, I_CN_EXPLOATATION, I_CAT_COMB)
  Set CaseFactors = Comb.CaseFactors
  With CaseFactors
    .New 1, 1.35
    .New 2, 1.5:
  End With
  
  Set RobApp = Nothing
End Sub
static void CreateCombination()
{
    RobotApplication RobApp = new RobotApplication();
    RobotCaseServer Cases = RobApp.Project.Structure.Cases;
    int CmbNbr = Cases.FreeNumber;
    string Title = $"COMB{CmbNbr} [ULS] 1*1.35 + 2*1.5";
    IRobotCaseCombination Comb = Cases.CreateCombination(CmbNbr, Title, IRobotCombinationType.I_CBT_ULS,
                                                                        IRobotCaseNature.I_CN_EXPLOATATION,
                                                                        IRobotCaseAnalizeType.I_CAT_COMB);
    RobotCaseFactorMngr CaseFactors = Comb.CaseFactors;
    CaseFactors.New(1, 1.35);
    CaseFactors.New(2, 1.5);

    RobApp = null;
}

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 3 of 4

Benjamin.Ainsworth
Contributor
Contributor

Thanks so much, it is working now. 

I compared our code and I saw that the only difference was that I had this:

IRobotCaseAnalizeType.I_CAT_COMB_CODE

 But it should have been :

IRobotCaseAnalizeType.I_CAT_COMB

 Thanks again.

Message 4 of 4

see also:

https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-generate-code-combinations/m-p/54...

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature