idea-statica / iom-examples

Examples of using IDEA StatiCa IOM API
MIT License
8 stars 4 forks source link

ConnectionHiddenCalculation.sln based on ideaCon filepath #10

Closed BouwenmetStaal closed 4 years ago

BouwenmetStaal commented 4 years ago

Hi Martin,

I want modify the ConnectionHiddenCalculation.sln script so that the hiddencalculation will be executed based on the path of the ideaCon file (without a window popping up).

However, I have been unsuccesfull. Every class contains an object “param”, I do not understand what kind of object it is, probably an ideaCon file, and where it is defined.

Can you provide me a modified example of ConnectionHiddenCalculation.sln where the ideaCon file of a hard coded predefined path is calculated, instead of opening it in the pop up window?

BR, Rayaan

mpospisil commented 4 years ago

Hi Rayaan, you don't need to use CustomCommand : ICommand This pattern comes from WPF - see Using WPF commands

You can add your button and call id directly from your event handler

WPF Button Control Example

` private void Button_Click(object sender, RoutedEventArgs e) { Service = conLinkAssembly.CreateInstance("IdeaRS.ConnectionService.Service.ConnectionSrv"); dynamic serviceDynamic = Service;

                serviceDynamic.OpenIdeaConProjectFile("path to your ideacon file", 0);

                                     // calculate all connections in the project
                var projectData = serviceDynamic.ConDataContract;
                foreach (var con in projectData.Connections.Values)
                {
                   var connectionId =  (Guid)(con.Header.ConnectionID);               
                   object resData = serviceDynamic.CalculateProject(connectionId);
                   ConnectionResultsData cbfemResults = (ConnectionResultsData)resData;
                }
    }

`

I've written this code snippent in a texteditor - maybe you will have to modify it to be able to compile it.

BouwenmetStaal commented 4 years ago

Hi Martin,

I'm afraid you misinterpret my question. I do not want to use any buttons at all, just a hard coded file path of the IDEA file, which will be opened and calculated.

The methods I need to use are: public void Open(object param) public void Calculate(object param)

Inputs to these methods are object param.

Can you provide me a piece of code where object param is created based on the hard coded defined file path?

BR

https://github.com/idea-statica/iom-examples/blob/8a551c29ed897ce70135c558c1c95b096a7efb49/ConnectionHiddenCalculation/ConnectionHiddenCalculation/MainVM.cs#L59-L62

https://github.com/idea-statica/iom-examples/blob/8a551c29ed897ce70135c558c1c95b096a7efb49/ConnectionHiddenCalculation/ConnectionHiddenCalculation/MainVM.cs#L147-L181

https://github.com/idea-statica/iom-examples/blob/8a551c29ed897ce70135c558c1c95b096a7efb49/ConnectionHiddenCalculation/ConnectionHiddenCalculation/MainVM.cs#L221-L241

mpospisil commented 4 years ago

I still don't understand - MainVM is only the viewmodel in my example. You don't need to use it in your application. You can just create the instance of ConnectionSrv and call the method Instead of openFileDialog.FileName you can pass your string :

serviceDynamic.OpenIdeaConProjectFile(yourProjectPathName, 0);

BouwenmetStaal commented 4 years ago

Hi Martin,

Opening the IDEA file works. However, calculate does not work.

I tried to use the Calculate method in my code but I do not know what to do with object param. So I tried to implement the methods of Calculate to Open. However, var conVM is not recognized here and I do not know how to properly assign this variable.

The modified script can be found here: https://github.com/BouwenmetStaal/KarambaIDEA/blob/e70c3725dd8e739bc7cc08efcc41d191b47cb94f/IDEA/HiddenCalculation.cs#L154-L187

Can you modify it so that the calculation is executed?

If something is unclear please let me know.

BR

mpospisil commented 4 years ago

ConnectionVM does almost NOTHING it only provides the name of the connection and its ID (guid) which is required for running calculation

You can do its conversion withou my view model - I sent you how to convert it but I made a mistake . CalculateProject requires guid of the connection you want to calculate

var connectionId = (Guid)(con.Header.ConnectionID); object resData = serviceDynamic.CalculateProject(connectionId); ConnectionResultsData cbfemResults = (ConnectionResultsData)resData;

if you pass Guid.Empty it calculates the first connection in your project

BouwenmetStaal commented 4 years ago

Thank you for your help Martin!