×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Is it possible to automate???

Is it possible to automate???

Is it possible to automate???

(OP)
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

RE: Is it possible to automate???

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)
www.solidCADworks.com
Tool and Die Designer
Siemens NX V9.0 + PDW
SWX 2013 SP3.0 X64
PDMWorks 2013
Logopress3
FastForm Advance
FormatWorks


RE: Is it possible to automate???

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

RE: Is it possible to automate???

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

RE: Is it possible to automate???

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( ...)

RE: Is it possible to automate???

(OP)
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.

RE: Is it possible to automate???

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 = "C:\temp\prtStockSize.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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources