Solved

Running script

Posted on 2013-01-26
19
217 Views
Last Modified: 2013-02-17
Hi,

How can I run attached c# code in page_load or form load event by proving the following STL file?

http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl

Please help.

ayha
script.txt
0
Comment
Question by:ayha1999
  • 11
  • 8
19 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38822626
Hello again.

Take the stlutil class and add it to your aspnet project.
If the file is on the server then put it in the physical directory where you deploy your web app.
In your form load use the same code from class main but pass the args array to IsValidated like thid:
var stlutils=new STLUtils();
If(stlutils.IsValidated(new string[]{filename,STLUtils.LengthType.inch.ToString()}));
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38822633
The filename argument is the location of the .stl file in the server.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 38823467
I will check it and come back.

Meantime, could u please have look the following question?

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28009868.html

Thanks
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 42

Expert Comment

by:sedgwick
ID: 38823536
U already got it answered
0
 
LVL 7

Author Comment

by:ayha1999
ID: 38835785
I tried the code but ended up with a syntax error.

ERROR: Possible mistaken empty statement at ';' in the end of the statement.

    protected void Page_Load(object sender, EventArgs e)
    {
        var stlutils = new STLUtils();
        if (stlutils.IsValidated(new string[] { Server.MapPath("~/website1/Part1_full tray..stl"), STLUtils.LengthType.inch.ToString() }));
    }

ayha
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38835876
U have 2 dots between the file name and the extension stl
0
 
LVL 7

Author Comment

by:ayha1999
ID: 38835885
I removed but still same error.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38835903
Debug the code and post the line that causes the error
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38835911
Also can u post the stlutil class here?
0
 
LVL 7

Author Comment

by:ayha1999
ID: 38835918
instead of red underline for syntax error it is green underline and when debugging, not showing error.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

/// </summary>
public class Triangle
{
    public double x; public double y; public double z;
}

public class STLUtils
{
    public enum LengthType { inch, cm } ;

    List<byte[]> _normals = new List<byte[]>();
    List<byte[]> _points = new List<byte[]>();
    List<Triangle> _triangles = new List<Triangle>();
    List<byte> _bytecount = new List<byte>();
    byte[] _fileBytes;
    LengthType _lengthType;
    string _filename;

    public bool IsValidated(string[] args)
    {
        if (args.Length != 2) return false;
        if (!Enum.TryParse<LengthType>(args[1], true, out _lengthType))
        {
            return false;
        }

        _filename = args[0];

        return File.Exists(_filename);
    }

    public double CalculateVolume()
    {
        //read binary file
        _fileBytes = File.ReadAllBytes(_filename);

        //reverse array if little indian
        if (BitConverter.IsLittleEndian)
            Array.Reverse(_fileBytes);

        //read length
        int length = ReadLength();

        double totalVol = 0;

        //skip 80(header) + 4(length)
        var bytes = _fileBytes.Skip(84);

        //loop through all triangles data
        for (int i = 0; i < length; i++)
        {
            _normals.Add(bytes.Take(12).ToArray());

            var p1 = bytes.Skip(12).Take(12).ToArray();
            var p2 = bytes.Skip(24).Take(12).ToArray();
            var p3 = bytes.Skip(36).Take(12).ToArray();
            var b = bytes.Skip(48).Take(2);

            var l = _points.Count;
            _points.Add(p1);
            _points.Add(p2);
            _points.Add(p3);
            _triangles.Add(new Triangle { x = l, y = l + 1, z = l + 2 });

            _bytecount.Add(b.First());
            totalVol += signedVolumeOfTriangle(p1, p2, p3);
            bytes = bytes.Skip(50);
        }

        //convert to required length type (cm/inch)
        return (_lengthType == LengthType.cm) ?
            totalVol / 1000 :
            cm3_To_inch3Transform(totalVol / 1000);
    }

    private double cm3_To_inch3Transform(double totalVol)
    {
        return totalVol * 0.0610237441;
    }

    private int ReadLength()
    {
        //skip 80 chars (header), read next 4 bytes to get length
        int length = BitConverter.ToInt32(_fileBytes.Skip(80).Take(4).ToArray(), 0);
        return length;
    }

    public double signedVolumeOfTriangle(byte[] p1, byte[] p2, byte[] p3)
    {
        double v321 = p3[0] * p2[1] * p1[2];
        double v231 = p2[0] * p3[1] * p1[2];
        double v312 = p3[0] * p1[1] * p2[2];
        double v132 = p1[0] * p3[1] * p2[2];
        double v213 = p2[0] * p1[1] * p3[2];
        double v123 = p1[0] * p2[1] * p3[2];
        return (1.0 / 6.0) * (-v321 + v231 + v312 - v132 - v213 + v123);
    }
}
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38836235
What is that mean?  do u get an error or not?
0
 
LVL 7

Author Comment

by:ayha1999
ID: 38836263
as I told you, a syntax error and when I run no result in the page. Actually I expect to execute CalculateVolume function and return result.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38836391
What is the error? Which line of code?
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38836464
ok i understand where the error came from, u left semicolon at the end of the if statement.
try this:

  var stlutils = new STLUtils();
        if (stlutils.IsValidated(new string[] { Server.MapPath("~/website1/Part1_full tray..stl"), STLUtils.LengthType.inch.ToString() })){



}

Open in new window

0
 
LVL 7

Author Comment

by:ayha1999
ID: 38851664
Now error but no result returned,
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38851691
Debug the code see if it calculates all data correctly
Ive no way of knowing what is wrong without a file
0
 
LVL 7

Author Comment

by:ayha1999
ID: 38851704
could u pls try this file

http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl

no error but no result.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38854072
i didn't realize it can be open in any text editor... (i wasn't familiar with the file type).
did u try it?
do you see the figures?
cause it would make it so much easier to process it as if it was a text file rather binary file like you had in php.
what do u think?
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 38898728
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Connection String through a VPN 8 55
LINQ Select all records by MAX data syntax help 1 17
Get month and date in a format 4 31
Amazon S3 .Net error 5 16
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question