469,315 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Reading a text file..

Hi!

I have a question..
How can csharp read a text file and execute it in another application? What
I mean is that, Im doing a drawing using Tekla Structures. But instead of
doing the same thing over and over again, I want to create an exe file that
allows it to read a text file and execute it in Tekla Structures. All I can
do now is to copy the contents of that text file and paste it in csharp
editor and run it, therefore I cannot compile my program.
Can anybody help me?
Thanks..
Apr 10 '08 #1
6 3163
On Apr 10, 1:37*am, zaldy <za...@discussions.microsoft.comwrote:
I have a question..
How can csharp read a text file and execute it in another application?
It's not clear to me what you mean by "execute it". Text files are
just data -
you don't "execute" them.

Is Tekla Structures an application in itself? What's its input? Could
you give more details of an example?

Jon
Apr 10 '08 #2
Hi Zaldy, Jon, I'm Qu. I'm using C# with Tekla Stuctures, so I thought
I'd join the discussion.

A quick explanation for Jon: Tekla is an external 3d modelling
program. It provides several dll files which are accessed the normal
way ("using Tekla.Structures.Model", "using Tekla.Structures.UI").
These dll files contain classes like the contour points and contour
plates above, as well as some commands to connect to the model. These
commands are run when you compile your program, and connect to the
first open Tekla document and act on it (examples are
ContourPlate.Insert and Model.CommitChanges).

The code Zaldy pasted above would compile and run straight from the C#
executable... you could paste it into Visual C# and it would work.
What he wants to do access a .txt file with it, import it, then
compile and run it. I gather you've already worked this out.

I can't find the CSharpCodeProvider class referenced in the local 2005
MSDN... is it available only to non-express users?

My approach to this problem would be more along the lines of: Create a
dynamic list of Contour Points, and several other variables (Name,
ProfileString, MaterialString, Class, etc) in a separate class, then
make your text file as a delimited file, as seen below. Extract the
variables using string functions (IndexOf, subString, and such), place
them into the constructor of your special class. Finally, get Tekla to
generate all the classes at run time.

~~~~~~~~~~~~~~~~~~
- PEDESTAL
- PL125
- SS400
- 1

~ 0.0000,100.0000,150.0000
~ 100.0000,100.0000,150.0000
~ 100.0000,0.0000,150.0000
~ etc...
~~~~~~~~~~~~~~~~~~~
Of course, you might want more flexability than this method allows, in
which case Jon's idea is much better and heaps easier...
Jun 27 '08 #3
On Apr 13, 11:04*pm, qua...@beagle.com.au wrote:

<snip>
The code Zaldy pasted above would compile and run straight from the C#
executable... you could paste it into Visual C# and it would work.
What he wants to do access a .txt file with it, import it, then
compile and run it. I gather you've already worked this out.
Yes.
I can't find the CSharpCodeProvider class referenced in the local 2005
MSDN... is it available only to non-express users?
No, it's available to everyone although it might not be in the cut-
down MSDN installed with Express. Search for it on the full MSDN - you
can still use it from Express.
My approach to this problem would be more along the lines of: Create a
dynamic list of Contour Points, and several other variables (Name,
ProfileString, MaterialString, Class, etc) in a separate class, then
make your text file as a delimited file, as seen below. Extract the
variables using string functions (IndexOf, subString, and such), place
them into the constructor of your special class. Finally, get Tekla to
generate all the classes at run time.
Yes - that does indeed sound like a better idea than having code
snippets.
Of course, you might want more flexability than this method allows, in
which case Jon's idea is much better and heaps easier...
Sort of - it really depends on who's going to be producing the text
file. Writing code outside an IDE is quite error-prone, for example.

Jon
Jun 27 '08 #4
Sort of - it really depends on who's going to be producing the text
file. Writing code outside an IDE is quite error-prone, for example.
Good point. Hey Zaldy, what are you going to place in the text files?
A database of code snippets to create specific individual objects,
variables to apply to a specific type of object, or something else?
Also important is who is going to be making the code: are you going to
code it in the IDE and copy-paste to the txt file, or is a non-
programmer going to try to write it?

Each of these would warrent a different method.

Cheers,
Qu.
Jun 27 '08 #5


"qu****@beagle.com.au" wrote:
Sort of - it really depends on who's going to be producing the text
file. Writing code outside an IDE is quite error-prone, for example.
Good point. Hey Zaldy, what are you going to place in the text files?
A database of code snippets to create specific individual objects,
variables to apply to a specific type of object, or something else?
It will be the same as the sample text Ive shown you. To tell the truth, Im
tired of modelling structures just to import it in PDS (another application)
and be used for interference checking...It will just be a code to create
specific individual objects.

Also important is who is going to be making the code: are you going to
code it in the IDE and copy-paste to the txt file, or is a non-
programmer going to try to write it?
No one will write the text file. An external application will be the one
doing that for me. Ive already tried it and its 0% error as of now. That
external application will write the text file in drive c. For different
structures, the contents of that text file will also be different. I want to
to create an compiled exe file that could read that text file and create
whats inside the text file in Tekla Structures.
Each of these would warrent a different method.

Cheers,
Qu.
Thanks.
Zaldy
Jun 27 '08 #6
It will be the same as the sample text Ive shown you. To tell the truth, Im
tired of modellingstructuresjust to import it in PDS (another application)
and be used for interference checking...It will just be a code to create
specific individual objects.

No one will write the text file. An external application will be the one
doing that for me. Ive already tried it and its 0% error as of now. That
external application will write the text file in drive c. For differentstructures, the contents of that text file will also be different. I want to
to create an compiled exe file that could read that text file and create
whats inside the text file inTeklaStructures.
Ah, that changes things. Since the code is being written by an
external application, CSharpCodeProvider seems the way to go.

http://msdn2.microsoft.com/en-us/lib...eprovider.aspx

As far as I understand it (remembering that I've never had to use it
before), you make a string containing your code, create a new
CSharpCodeProvider, create and modify a set of Compiler Parameters to
feed into your CSharpCodeProvider, then make a Compiler Results object
and call "CompileAssemblyFromSource".

string str = "MessageBox.Show(\"You should import your
code into this string.\")";
CSharpCodeProvider provider = new CSharpCodeProvider();
System.CodeDom.Compiler.CompilerParameters cp = new
System.CodeDom.Compiler.CompilerParameters();
cp.OutputAssembly = "Assem1";
CompilerResults cr =
provider.CompileAssemblyFromSource(cp, str);

Remember to add System.CodeDom.Compiler; and Microsoft.CSharp; to your
using statments

I can't really help you any further at the moment, because I'm not
sure how to call an assembly and don't have time to work it out. Good
luck, though.

Cheers,
Qu.
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by fabrice | last post: by
19 posts views Thread by Lionel B | last post: by
50 posts views Thread by Michael Mair | last post: by
2 posts views Thread by Sabin Finateanu | last post: by
4 posts views Thread by Amit Maheshwari | last post: by
3 posts views Thread by The Cool Giraffe | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.