Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Is it possible to automate??? 1

Status
Not open for further replies.

Santhosh_94

Mechanical
Dec 16, 2014
25
Here is my case, I have a number of part files in the iges file format for which i have to get the raw material size for material ordering for carrying out the further manufacturing operations.
Now as for me i am doing like importing each iges files and measuring the size using the stock size command and preparing a list of part name and raw material size in an excel is there a possible way to automate these functions cause these takes up lot more time in selecting, dragging, copying, pasting, etc.
Is there any program available or to learn such kind of stuffs guide me i ain't know anything about programming....
Thanks in advance
Santhosh
 
Replies continue below

Recommended for you

RMB your NX BOM and export it to a file (.csv or .txt) with format Tabs between Columns (check your Excel/windows default settings)

To import the BOM to Excel Sheet select DATA->From Text and browse to your exported csv or text file and select.


Michael Fernando (CSWE)
Tool and Die Designer
Siemens NX V9.0 + PDW
SWX 2013 SP3.0 X64
PDMWorks 2013
Logopress3
FastForm Advance
FormatWorks
 
Getting the raw material size of a model without having to manually measure it can be automated but do not expect to do it out of a journal because it involves scanning the model and findind out its geometry type and dimensions which involves thousand of lines of code.
There is an old and rather extreme example here:

Link
 
It really depends on the shape of the parts that you are dealing with. I've seen a journal that works fairly well with prismatic, machined parts. It works by moving the WCS XY plane to the largest planar face of the part and aligning the X axis parallel to the longest edge of the face before measuring the bounding box. As daluigi mentions, this isn't guaranteed to be the smallest possible bounding box, but it's usually a good estimate.

www.nxjournaling.com
 
I think you would typically know how the bounding box should be oriented, because the orientation of the raw material has many implications for machining setup, tool accessibility, and so on. Then, if you assume that the orientation is known, finding the minimum bounding box is easy. With SNAP, it's just myBody.Box. With NX/Open, it's NXOpen.UF.UFModl.AskBoundingBoxExact( ...)
 
Thanks for your kind reply's,
Here i have attached a picture of a stock size measurement of a random part using stock size command i just have to extract the dimensions given in the stock size and blank size text boxes into an excel.
 
 http://files.engineering.com/getfile.aspx?folder=f0d7a5f8-a913-456a-80ee-3eb82c4d8b88&file=3-17-2015_8-49-19_PM.jpg
Regarding orientation as similar to cowski mentioned if the part is tilted or something with respect to any axis then the WCS has to be oriented as he said, Before using the stock size command.
 
I had some time to look at this today.

Journal to measure the stock size of a solid body and write the info to a .csv file. The journal will prompt you to select a solid body then it will prompt to specify a csys (the dynamic csys tool will default to the WCS orientation). The edges of the "stock" will be aligned to the axes of the chosen csys. Change the orientation if needed and press OK. The measured size will be written to the specified file. The output will be in the format: "file name, X dimension, Y dimension, Z dimension". The X, Y, and Z directions will be according to the csys you specified.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Sub Main()

        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        '$$$ file to output measurements, change this before running journal
        Dim outputFile As String = "[highlight #FCE94F]C:\temp\prtStockSize[/highlight].csv"
        '$$$

        Dim bodyToMeasure As Body = Nothing

        If SelectSolid("Select a solid body to measure", bodyToMeasure) = Selection.Response.Cancel Then
            Return
        End If

        If Not OrientWCS() Then
            Return
        End If

        Dim stkSize As String = MeasureBody(bodyToMeasure)
        Dim output As String = workPart.Leaf & ", " & stkSize

        AppendToTextFile(outputFile, output)

        lw.Close()

    End Sub

    Function SelectSolid(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a solid body"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Function OrientWCS() As Boolean

        Dim theUISession As UI = UI.GetUI()

        '9 element orientation matrix of specified csys
        'arrays are zero based
        Dim myCsys(8) As Double

        '3 element array: origin point of specified csys
        Dim myOrigin(2) As Double

        'tag variable used as input/output for the .SpecifyCsys method
        'passing a null tag into the function uses the current WCS as the starting csys
        Dim newCsysTag As Tag = Tag.Null

        'variable to hold the user specified coordinate system
        Dim newCsys As CartesianCoordinateSystem

        Dim response As Integer

        theUISession.LockAccess()
        response = theUfSession.Ui.SpecifyCsys("Specify Desired Orientation", 5, myCsys, myOrigin, newCsysTag)
        theUISession.UnlockAccess()

        If response = Selection.Response.Ok Then
            'get CartesianCoordinateSystem object from tag
            newCsys = Utilities.NXObjectManager.Get(newCsysTag)
            'orient WCS to specified coordinate system
            theSession.Parts.Work.WCS.SetCoordinateSystemCartesianAtCsys(newCsys)
            Return True

        Else
            'user pressed back or cancel or the system was in a state that could not allow the dialog to be shown
            '1 = back
            '2 = cancel
            '3 = OK
            '7 = no active part
            '8 = disallowed state, unable to bring up dialog
            Return False
        End If

    End Function

    Function MeasureBody(ByVal theBody As Body) As String

        Dim minCorner(2) As Double
        Dim boxDirections(2, 2) As Double
        Dim boxDistances(2) As Double

        Dim boundX As Double
        Dim boundY As Double
        Dim boundZ As Double

        'get solid body bounding box extents aligned to work csys (pass null tag to use work csys)
        theUfSession.Modl.AskBoundingBoxAligned(theBody.Tag, Tag.Null, expand:=False, min_corner:=minCorner, directions:=boxDirections, distances:=boxDistances)

        boundX = boxDistances(0)
        boundY = boxDistances(1)
        boundZ = boxDistances(2)

        Return boundX.ToString & ", " & boundY.ToString & ", " & boundZ.ToString

    End Function

    Sub AppendToTextFile(ByVal textFilePath As String, ByVal textLine As String)

        'pass False to overwrite existing file, True to append existing file
        'if file does not exist, a new file will be created and the True/False value will be ignored
        Using myWriter As New IO.StreamWriter(textFilePath, True)

            myWriter.WriteLine(textline)

        End Using

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor