Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slowing Journal 2

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
0
0
US
I have written a program which uses a datum to place two intersection curves and measures the distance between these curves. Using an expression the datum is moved along a central spline and measurements taken each time. These numbers are put in a csv file to be perused later. As the program runs it get visibly slower and slower, mind you it moves 300+ times but I don't understand the slow down.

I have gone through the code and made sure the builders are destroyed when I am done with them. So I wonder if it is the update process or the fact that the csv file being created is at size 0 until the program completes and closes the file.

Ultimately the program never goes so slow that it is a detriment unless someone requires a massive number of checks, but I wish to improve my skills and am not sure if this a fault of sloppy programming or something inherent in UG.

Any help would be appreciated.

Here is the loop in the code I can post the subs if anyone thinks they may be necessary.

Code:
      While( boolMoldSurface = True )
         markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Take Measurements")

         strStation = Convert.ToString(intStation)

         'Measure length of intersectionCurve on MoldSurface

         MeasureLineLength( moldInterLine, strMoldLength, boolLength, unitMM )

         'Measure minimum distance from moldInterLine to LoftInterLine

         MeasureMinDistance( moldInterLine, loftInterLine, strMinDistance,unitMM )

         'Measure minimum distance from moldInterLine startpoint to LoftInterLine
         
         Dim moldCurves() As NXObject = moldInterLine.GetEntities()

         scrMoldStart = workPart.Scalars.CreateScalar( 0.0, Scalar.DimensionalityType.None, _
            SmartObject.UpdateOption.AfterModeling )

         ptMoldStart = workPart.Points.CreatePoint( MoldCurves(0), scrMoldStart, _
            SmartObject.UpdateOption.AFterModeling )

         MeasureMinPtDistance( loftInterLine, ptMoldStart, strStrtpt )

         'Measure minimum distance from moldInterLine endpoint to LoftInterLine

         scrMoldEnd = workPart.Scalars.CreateScalar( 1.0, Scalar.DimensionalityType.None, _
            SmartObject.UpdateOption.AfterModeling )

         ptMoldEnd = workPart.Points.CreatePoint( MoldCurves(0), scrMoldEnd, _
            SmartObject.UpdateOption.AFterModeling )

         MeasureMinPtDistance( loftInterLine, ptMoldEnd, strEndpt )

         'Write in file ("Station", "length", "Minimum", "startpoint", "endpoint\n")

         wrtData.Write( strStation & "," & strMoldLength & "," & strMinDistance & "," & _
            strStrtPt & "," & strEndPt & Environment.NewLine )

         boolMoldSurface = True

         Try

            'Move Datum
            intStation = intStation + intInterval
            expDatum.RightHandSide = intStation

            theSession.UpdateManager.DoUpdate(markId3)
         Catch

            boolMoldSurface = False

         End Try

      End  While
 
Replies continue below

Recommended for you

There are 3 Things you can do to improve the performance of this program( well 3 that I can think of ):
1.This is a general programming advise, not specific to NX: You can store all the data you are collecting during the while loop in a data structure. Only when the loop is done, creating/ accessing the csv file and updating it. It is not written in your sample how you access the file, and maybe it is done not in efficient way, so accessing it only once is better.
2.I think you can move the creation of the markID3 object out of the while loop.
3.You can probably refactor your program so it will work from a stand alone "exe" application and not launched from with in NX. You will gain Less work for the Graphic card and better performance.
 
You can actually turn off the display updating. Here is the info from user function

Overview

Sets the display status. You can use UF_DISP_set_display to turn
off the graphics display before executing a long series of graphics
intensive operations such as manipulations of views, layouts, or
drawings. You must call UF_DISP_regenerate_display to update the
display after turning it back on.
Note that there are limitations to this function in conjunction with
layout and drawing changes. If you open a layout or drawing, the
display will change to show the outlines of the views in the layout
or drawing, even though the suppress state is enabled; the contents
of the views will not be shown however.


Environment

Internal


Required License(s)

gateway

int UF_DISP_set_display
(

int display_code

)

int display_code Input display code:
UF_DISP_SUPPRESS_DISPLAY- set display off
UF_DISP_UNSUPPRESS_DISPLAY- set display on

Hope this helps.

Frank Swinkels
 
Tomerl:

I am accessing the output file with the following:

Code:
      dim outputCSV As New FileStream(strPartName, FileMode.Create)
      dim wrtData As New StreamWriter(outputCSV)
      wrtData.Write("S-Location,Width of Mold,Minimum Distance,Start Pt Distance, End Pt Distance" _
         & Environment.NewLine)

Then towards the end of the above loop you can see the data gathered in that loop being written into the file with the command:

Code:
         wrtData.Write( strStation & "," & strMoldLength & "," & strMinDistance & "," & _
            strStrtPt & "," & strEndPt & Environment.NewLine )

Are you saying that it might run faster if I created and re-sized an array each loop to hold the data and wrote it into the file after the run was completed?

FrankSwinks:

I have tried to use commands like this before, specifically UF_CFI_MAX_FILE_NAME_LEN and have not had any success. I can find examples of them used in C, bit I have not been able to adapt them to Visual basic.

Thanks both of you for your advice.
 
OK The equivalent in VB is

Wrapper method for UF_DISP_set_display
Declaration Syntax
C# Visual Basic Visual C++

public void SetDisplay(
int display_code
)
Public Sub SetDisplay ( _
display_code As Integer _
)
public:
void SetDisplay(
int display_code
)

Parameters
display_code (Int32)
Remarks
Refer to UF_DISP_set_display for documentation

Regards

Frank Swinkels
 
The way you are accessing the file looks ok (i don't think it is the cause of the performance problem). Having said that, i think my suggestion is more a style issue.
I think the suggestion about UF_DISP_set_display is very easy to implement and can boost your application.
For better understanding how come the application is becoming slower in each iteration you should try to figure out:
1. Do you really need to create all the points/scalars in each iteration, or maybe you can just change their position from one iteration to the next without creating new objects.
2. Measure the time your application spend on each section of the iteration , google for "dotnet stopwatch", it will help you understand how to measure time.
 
Status
Not open for further replies.
Back
Top