Robot Structural Analysis Forum
Welcome to Autodesk’s Robot Structural Analysis Forums. Share your knowledge, ask questions, and explore popular Robot Structural Analysis topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 8
pipu123
2483 Views, 7 Replies

C# API help

I started programming C# RSA , I have difficulties to translate code from vb to c#. Please help me .

please write sample code

how to change:

1) tools / job preferences / materials / basic set / steel

   how to change type of steel for example: put S355

 

RobotMaterialData Material;

 

2) how to

  create a new section

  standard

Database: Simple Catpro        Family:  HEA         Section: HEA120         Section type Aluminum

 

3)  on the http://www.robobat.com/n/ros/

 

There is a code In vb , I couldn’t translate all to c#, please correct me

It is original code:

Reading the basic geometry 

 

 

 

Declare the main variable representing the Robot application and connect it to the currently running instance of Robot.  

Dim robapp As IRobotApplication

Set robapp = New RobotApplication

  Get the collection of all bars from the structure.  

Set bar_col = robapp.Project.Structure.Bars.GetAll()

  Iterate for consecutive bars from the collection.  

For i = 1 To bar_col.Count

    Get the object representing the following (i-th) bar in the collection.    

Set bar = bar_col.Get(i)

    Read required attributes of the i-th bar.    

bar_num = bar.Number

start_node_num = bar.StartNode

end_node_num = bar.EndNode

    Declare variables defining individual nodes.    

Dim start_node As IRobotNode, end_node As IRobotNode

    Get the node with start_node_num number from the server.    

Set start_node = robapp.Project.Structure.Nodes.Get(start_node_num)

    Read the values of coordinates x, y, z for the node with start_node_num number.    

start_node_x = start_node.X

start_node_y = start_node.Y

start_node_z = start_node.Z

    Get the node with end_node_num from the server and read its coordinates.    

Set end_node = robapp.Project.Structure.Nodes.Get(end_node_num)

end_node_x = end_node.X

end_node_y = end_node.Y

end_node_z = end_node.Z

    Free all declared variable references.    

Set bar = Nothing

Set start_node = Nothing

Set end_node = Nothing

  Repeat the operation of reading data for the next bar from the collection.  

Next

  Free all the references declared in the example.  

Set bar_col = Nothing

Set robapp = Nothing

 

!!!!!!!!!!!!!!!!!!!!!!!!

Mine code:

IRobotApplication robApp;

  robApp = new RobotApplicationClass();

 

   IRobotCollection bar_col = robApp.Project.Structure.Bars.GetAll();

           for (int i = 0; i <= Convert.ToInt32(bar_col.Count); i++)

           {

           //   IRobotBar bar = bar_col.Get(i);

            

// this below is something wrong 

                IRobotBar bar = robApp.Project.Structure.Bars.Get(i);

           }

 

Error      1             Cannot implicitly convert type 'RobotOM.IRobotDataObject' to 'RobotOM.IRobotBar'. An explicit conversion exists (are you missing a cast?) G:\nauka c# cad\Robot02\Robot02\Form1.cs  

 
 

4) Remove selected load cases

Declare the main variable representing Robot aplication and its connection to the currently running program instance.  

Dim robapp As IRobotApplication

Set robapp = New RobotApplication

Dim casesrv As IRobotCaseServer

Set casesrv = robapp.Project.Structure.Cases

  Get the collection including all load cases.  

Dim casecol As IRobotCaseCollection

Set casecol = robapp.Project.Structure.Cases.GetAll()

  Iterate for consecutive cases from the collection.  

For i = 1 To casecol.Count

    Get i-th case    

Dim c As IRobotCase

Set c = casecol.Get(i)

    Remove the case from the server if the analysis type is different from the linear static analysis.    

If c.AnalizeType <> I_CAT_STATIC_LINEAR Then casesrv.Delete c.Number

    Free variable representing a case    

Set c = Nothing

  Repeat the iteration for the following case.  

Next

 

Mine code:

 

IRobotApplication robApp;

  robApp = new RobotApplicationClass();

 

           IRobotCaseServer casesrv;

           casesrv = robApp.Project.Structure.Cases;

           IRobotCaseCollection casecol;

           casecol = robApp.Project.Structure.Cases.GetAll();

 

           for (int i = 0; i <= Convert.ToInt32(casecol.Count); i++)

           {

               IRobotCase c;

             

               c = Convert.ToInt32(casecol.Get(i));

               if (c.AnalizeType != IRobotCaseAnalizeType.I_CAT_STATIC_LINEAR)

 

// this below is something wrong 

casesrv.Delete(c);

           }

5)

            IRobotStructure str; 

            str = robApp.Project.Structure;

 

            // Generate new load case.

            IRobotSimpleCase caseExp;

            caseExp = robApp.Project.Structure.Cases.CreateSimple(str.Cases.FreeNumber, "caseExp",

                IRobotCaseNature.I_CN_EXPLOATATION, IRobotCaseAnalizeType.I_CAT_STATIC_LINEAR);

            //      Define load record types.

            caseExp.Records.New(IRobotLoadRecordType.I_LRT_NODE_FORCE);

 

  IRobotLoadRecord LoadRecord; // rec

  LoadRecord = (RobotLoadRecord)caseExp.Records.Get(1);

 

// this below is something wrong 

LoadRecord.SetValue(IRobotBarUniformRecordValues.I_BURV_LOCAL, true);

 

6)  

IRobotViewDisplayParams ParamsDisplay01;

ParamsDisplay01 = ?  (how to declare  )

 

    ParamsDisplay01.Set(IRobotViewDisplayAttributes.I_VDA_STRUCTURE_NODE_NUMBERS, true);

7 REPLIES 7
Message 2 of 8
Rafal.Gaweda
in reply to: pipu123

 

!!!!!!!!!!!!!!!!!!!!!!!!

Mine code:

IRobotApplication robApp;

  robApp = new RobotApplicationClass();

 

   IRobotCollection bar_col = robApp.Project.Structure.Bars.GetAll();

           for (int i = 0; i <= Convert.ToInt32(bar_col.Count); i++)

           {

           //   IRobotBar bar = bar_col.Get(i);

            

// this below is something wrong 

                IRobotBar bar = robApp.Project.Structure.Bars.Get(i);

           }

 

 

Should be:

 

            IRobotApplication robApp = new RobotApplication();
            IRobotCollection bar_col = robApp.Project.Structure.Bars.GetAll();
            for (int i = 0; i < bar_col.Count; i++)
            {
                   IRobotBar bar = bar_col.Get(i+1);

                // or
               // IRobotBar bar = (IRobotBar)robApp.Project.Structure.Bars.Get(i+1);

            }

 

 



Rafal Gaweda
Message 3 of 8
Rafal.Gaweda
in reply to: pipu123


Mine code:

 

IRobotApplication robApp;

  robApp = new RobotApplicationClass();

 

           IRobotCaseServer casesrv;

           casesrv = robApp.Project.Structure.Cases;

           IRobotCaseCollection casecol;

           casecol = robApp.Project.Structure.Cases.GetAll();

 

           for (int i = 0; i <= Convert.ToInt32(casecol.Count); i++)

           {

               IRobotCase c;

             

               c = Convert.ToInt32(casecol.Get(i));

               if (c.AnalizeType != IRobotCaseAnalizeType.I_CAT_STATIC_LINEAR)

 

// this below is something wrong 

casesrv.Delete(c);

           }

 


Should be

 

           IRobotCaseServer casesrv = robApp.Project.Structure.Cases;
           IRobotCaseCollection casecol= casesrv.GetAll();
 
           for (int i = 0; i < Convert.ToInt32(casecol.Count); i++)
           {
               IRobotCase c = casecol.Get(i+1);
               if (c.AnalizeType != IRobotCaseAnalizeType.I_CAT_STATIC_LINEAR)
               {
 
                casesrv.Delete(c.Number);
               }

 



Rafal Gaweda
Message 4 of 8
Rafal.Gaweda
in reply to: pipu123


5)

            IRobotStructure str; 

            str = robApp.Project.Structure;

 

            // Generate new load case.

            IRobotSimpleCase caseExp;

            caseExp = robApp.Project.Structure.Cases.CreateSimple(str.Cases.FreeNumber, "caseExp",

                IRobotCaseNature.I_CN_EXPLOATATION, IRobotCaseAnalizeType.I_CAT_STATIC_LINEAR);

            //      Define load record types.

            caseExp.Records.New(IRobotLoadRecordType.I_LRT_NODE_FORCE);

 

  IRobotLoadRecord LoadRecord; // rec

  LoadRecord = (RobotLoadRecord)caseExp.Records.Get(1);

 

// this below is something wrong 

LoadRecord.SetValue(IRobotBarUniformRecordValues.I_BURV_LOCAL, true);

 

 

I assume you want to add nodal force:

 

            IRobotStructure str = robApp.Project.Structure;
 
            // Generate new load case.
            IRobotSimpleCase caseExp;
            caseExp = robApp.Project.Structure.Cases.CreateSimple(str.Cases.FreeNumber, "caseExp",
                IRobotCaseNature.I_CN_EXPLOATATION, IRobotCaseAnalizeType.I_CAT_STATIC_LINEAR);
            //      Define load record types.
            caseExp.Records.New(IRobotLoadRecordType.I_LRT_NODE_FORCE);
 
  IRobotLoadRecord LoadRecord = caseExp.Records.Get(caseExp.Records.Count);
 
            
LoadRecord.SetValue((short)RobotOM.IRobotNodeForceRecordValues.I_NFRV_FZ,-10);
            LoadRecord.Objects.FromText ("1") ;

 

 



Rafal Gaweda
Message 5 of 8
Rafal.Gaweda
in reply to: pipu123


IRobotViewDisplayParams ParamsDisplay01;

ParamsDisplay01 = ?  (how to declare  )

 

    ParamsDisplay01.Set(IRobotViewDisplayAttributes.I_VDA_STRUCTURE_NODE_NUMBERS, true);



Should be

 

            IRobotView robotview = robApp.Project.ViewMngr.GetView(1);
            robotview.ParamsDisplay.Set(IRobotViewDisplayAttributes.I_VDA_STRUCTURE_NODE_NUMBERS, true);

 



Rafal Gaweda
Message 6 of 8
pipu123
in reply to: Rafal.Gaweda

Thank You

Your solution for these points is proper.

If You don't mind please writethe 1) and 2)  

 

1) tools / job preferences / materials / basic set / steel

   how to change type of steel for example: put S355

 

RobotMaterialData Material;

 

2) how to   create a new section

  New profile

    standard   Database: Simple Catpro

Family:  HEA Section: HEA120    Section type Aluminum

 

I tried myself but it is not what I would like to achieve:

 

            IRobotProjectPreferences ProjectPrefs;
            ProjectPrefs = robApp.Project.Preferences;
            ProjectPrefs.SetActiveCode(IRobotCodeType.I_CT_RC_THEORETICAL_REINF, "BAEL91");

            IRobotMaterialDatabase material;
            material = ProjectPrefs.Materials;
           // material.Name = IRobotMaterialDatabase

            RobotMaterialData Material;
            Material = (RobotMaterialData)label.Data;
            Material.Type = IRobotMaterialType.I_MT_CONCRETE;

 

 

 

Message 7 of 8
Rafal.Gaweda
in reply to: pipu123

 

1) tools / job preferences / materials / basic set / steel

   how to change type of steel for example: put S355

 

I hope you meant this:

 

            robApp.Project.Preferences.Materials.Load("Eurocode");
            RobotBar Bar = (RobotBar)robApp.Project.Structure.Bars.Get(bar_number);
            Bar.SetLabel(IRobotLabelType.I_LT_MATERIAL, "S355");

 



Rafal Gaweda
Message 8 of 8
Rafal.Gaweda
in reply to: pipu123


2) how to   create a new section

  New profile

    standard   Database: Simple Catpro

Family:  HEA Section: HEA120   

 

robApp.Project.Preferences.SetCurrentDatabase(IRobotDatabaseType.I_DT_SECTIONS, "SIMPL");
IRobotLabel Section = robApp.Project.Structure.Labels.Create(IRobotLabelType.I_LT_BAR_SECTION,"HEA 120");
IRobotBarSectionData SData = Section.Data;
SData.LoadFromDBase("HEA 120");
robApp.Project.Structure.Labels.Store(Section);

RobotBar Bar = (RobotBar)robApp.Project.Structure.Bars.Get(bar_number);

Bar.SetLabel(IRobotLabelType.I_LT_BAR_SECTION, "HEA 120");

 



Rafal Gaweda

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report