Civil Engineering Association

Full Version: How to start Language (C#, dot Net & VB) Study
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi,
windows is written in C++ and assembler, so you have to know these software!!
Or..... not . Definitively not.
If you want to start a language, you have to begin from something easy and in many steps:
- look for a manual about pascal and basic, for understand the main concept, if and loop clauses;
- then you can pass to a currently useful language, as C#, VB or, in my opinion Pyton.
In particular, C # and VB allow you to create a dialogue between different software, for example I set data into Excel and from there (VBA) is possible to launch an autocad session and draw a part, then opens word and writes a related report.
When you knows C # or VB you can easily understand the other language, ad transport code
in you favourite language. The net is plenty of vb or c# example.
But things like C++ noooooooooooo.
I expect you've installed by now visual studio and completed most of the samples.
Also you understood the operators, variables, conditions and loops.
Here is the same naive code (for simplicity reasons) in different languages. I'll let you figure out what it does.
[Image: 97402884402721040352.png]
Python code:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

To run the vb script simply make a file with extension .vbs open it with notepad write the code. Double click it.

To run the turbo pascal, here is the download link:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

To run python:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************
@kvtasp

this is a little help ^_^

Microsoft Visual C#2012 Step By Step
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************


Lynda.com C# & C,C++ Essential Training
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************
Hi KVtasp,

Based on my exp. I think you should study the C# from the basic as Liviu M explained in his example. Just three weeks ago, I still leaned from that ( just to know how to declare the variable) and then you can practice the simple exercise Create Beam form Chris keyact, you can seach on youtube.

I did that example ( just to know the method of Tekla ) and then read on the TEKLA API Start up Package. ( Self learning .pdf and the see how Tekla run.

I 've just copied the code in the exercise and learn! You should read the book of C# to know about: variable, for loop, while loop. I think that will be enough for startign point.
I will give the simple code how I wrote just to create a silos by using the parametric profile.

This the link for the self learning Tekla API :
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

This the link about the C# basics issued by TEKLA :
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************
It is very useful for the dummy as me at the begining.

Hope it can help
Hi kvtasp,
This is my code to create a silos ( practice from the exercise " Create Beam").
using Tekla.Structures.Model;
using Tekla.Structures.Solid;
using Tekla.Structures.Geometry3d;
using T3D = Tekla.Structures.Geometry3d;
using TSM = Tekla.Structures.Model;
using TSMUI = Tekla.Structures.Model.UI;
// Additional Namespace references
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Globalization;
using System.Threading;
namespace Create_Beam
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Model model = new Model();
double a = Math.Tan(int.Parse(textBox4.Text) * 2 * 3.141592654 / 360);

double c = (int.Parse(textBox1.Text)/2 - int.Parse(textBox2.Text)/2 )* a ;
Beam beam = new Beam (new T3D.Point (0,0,c),new T3D.Point (0,0,0)) ;


beam.Profile.ProfileString = "EPD"+textBox1.Text + "*" + textBox1.Text + "*" + textBox2.Text + "*"+ textBox2.Text + "*" + textBox3.Text ;
// beam.Position.Rotation.
beam.Insert();

Beam beam2 = new Beam (new T3D.Point(0,0, c+int.Parse(textBox5.Text)), new T3D.Point (0,0,c));

beam2.Profile.ProfileString = "PD" + textBox1.Text + "*" + textBox3.Text ;

beam2.Insert();

model.CommitChanges() ;


}

private void textBox1_TextChanged(object sender, EventArgs e)
{



}

private void label1_Click(object sender, EventArgs e)
{

}

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void textBox3_TextChanged(object sender, EventArgs e)
{

}

private void textBox4_TextChanged(object sender, EventArgs e)
{

}

private void textBox5_TextChanged(object sender, EventArgs e)
{

}

private void pictureBox1_Click(object sender, EventArgs e)
{

}
}
}


I did some buttons to allow the user prompt the dimension of the silo. I have no idea how to upload a small application file here. But we can discuss my code and I can explain for you.

Hope you will be better with this example!
Hello again,

It's important to write your app's in a structured way.
Here I was writing a lot of stuff about design patterns.
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************
We can talk endlessly on this subject but it's not worthing.

So a basic rule:
Never write your "application logic code" inside your "interface code".

I can't understand your code, the names of variables are impossible to decipher.
It's like the code is obfuscated Grin, no offense.

But starting from you code I split the actions in the event button1_click into two parts:
First part is related to input, the second part is the actual action.
By doing this way I can easily move the logic, the actual action, in a let's say console application without forms, or in loop which generates more than one silo, or even in a macro. The silo generating algorithm no longer is dependent on controls on the form.
Also I can easily add some input checking in various places.

To explain the code, first I convert the textboxes input into numbers by doing a double.tryparse.
Users will always find a combination of actions that lead to errors or that doesn't follow the intended usage path.
You have to limit the chances of crashes as much as you can.

So if tryparse fails the user is informed and no action takes place.
the int.parse will fail if number is not integer, or if number is not in proper format.
The failure is an application crash if you don't use try-catch-finally.

From the code I think you need doubles not integers, this is why I used double.tryparse instead of int.parse.

Another rule is to never artificially limit the functionality of your code. If it can run with doubles, let it run with doubles.
The y2k virus/problem is the best example.
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************
So never limit to 2 beams and 4 joints if the machine can handle 1000 beams and 4000 joints.

It would make the code readable if t1..t5 are renamed to actual names, the same with textboxes, consider that.

After checking the input at interface level I run the actual logic CreateSilo(),
I placed the CreateSilo inside the event because I don't have a Controller.
A controller is the part of the application that would make the link between the viewer (the form) and the model (application logic and data provider (tekla api)).
The error handling should be inside the controller, which could write errors on disk in a log or show a message in a console or a popup message box or a textbox or in another window or whatever.

In your case the controller is the same with the view, the form. This is why error handling is at System.Windows.Forms level (MessageBox).
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

There's a try-catch error block because it can fail because no connection with tekla or because the math leads to errors. like 0 devision, or because the numbers don't pass some checks.
It can also fail because of antivirus or UAC or simply the user doesn't have tekla or the api is not correctly registered.

If you do simple stuff like adding one beam in an empty model you can see if all went well.
But if you modify a huge model it's much harder to see changes.
So we try to predict from code if all wen't well. A solution could be to check if the beam has weight after it was added to the model.
Remember that users always expect software to do well what it says it does.


If you make a macro, a connection, and it's used allover the model imagine if each one throws unhandled errors. You'll have to use end task for tekla to stop all errors. This is why a silent warning should be used.

The full revised code:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

In the above, I described what function CreateSilo does and what the input means:
[Image: 45131241423515380625.png]
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

The input t1,t2..t5 should be renamed into more readable variable names.

A function should be named like an imperative action/request.
E.g. CreateSilo, DeleteSilo, ModifySilo, AppendSilo.
OR MakeitRain, OpenConnection, CreateThread.

By splitting the code I can have multiple input,like the above debug action.

And here is the console version. As you can see the silo creation no longer depends on interface, textboxes and whatever from forms environment. The input can even come from a file. The error handling is done in a console environment so no more messageboxes.
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

private void CreateSilo turned into private static void CreateSilo.
Static because it does not share context (variable, instance) with anything.

e.g.
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

For you code the CreateSilo uses a tekla model.
Model model = new Model();
This can be done only once when application starts, and reused for each action.

So the console application gets split like this:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

And another file, in fact another class called TeklaTools.cs
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

As you can see the using statements are now only where you actually use the tekla api.
The tekla model object is created only once when the TeklaTools object is created first.
teklatools = new TeklaTools(); goes to it's contructor
public TeklaTools()
{
model = new Model();
}

As you can see TeklaTools is now part of a different namespace called MyCompany.
And the console app is using it.
About namespace, a simple example is using System.Microsoft....
of using Tekla.Structures....
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

Changing the namespace makes the TeklaTools class be reusable, we can use it in the forms application by simply adding it to the project.

In the forms version of code, it can be stored in a variable inside the Model part of the app, which is controlled by the controller.
Because here the main form is controller we can do it like this:

Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************

The next step might be to convert the tekla tools to a class library (a dll) and reused it in all projects.

The main purpose of this is to show how things can be structured so that they become reusable and easy to maintain. The most important aspect is to avoid creating unnecessary links between independent parts of the application.

I've converted numbers to doubles by writing instead of 2, 2.0.
A number defined in c# like 2 or 3 is an integer and so if you write:
double a=3/2; a will have the value 1
while
double a=3.0/2.0; a will have the value 1.5
Had some fun recently with tekla api, below is come code, to create helix.
Maybe you'll find it useful for something.
[Image: 44369966071281206862.jpg]
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:

http://forum.civilea.com/thread-27464.html
***************************************
Pages: 1 2 3