Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX 7.5 Journaling - Moving all Flat Pattern entities in to a layer

Status
Not open for further replies.

RAMNX

Mechanical
Dec 29, 2011
28
Hi All,
We have a requirement to move all flatpattern objects in to layer 151. This task need to be done for several part files.
I have created below journal to do this task. we need to open each part file and run this journal.

This code find outs all custome views and filters the views with "FLAT-PATTERN". After that it switches to each flat pattern view and moves the visible objects to layer 151. If the part file is not having flat pattern view it gives a message on the scrren.
This journal is moving all curves in to layer but excluding flat pattern annotations(labels).

Can someone help me in improving below code. Thank you in advance.



Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main


Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()

Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
Dim basepart As part = theSession.Parts.Work



Dim Vwlst As Array

Vwlst = Basepart.Views.GetCustomViews()

Dim b As Integer

b=0

Dim c As Integer

c=Vwlst.Length-1

Dim fviews As Integer

fviews = 0


If Vwlst.Length > 0 Then

For b=0 to c

Dim vn as String

vn=Vwlst(b).ToString()

Dim ff As String

ff=Left(vn,12)

If ff = "FLAT-PATTERN" Then

fviews = fviews+1


Dim layout1 As Layout = CType(workPart.Layouts.FindObject("L1"), Layout)

Dim modelingView1 As ModelingView = CType(workPart.ModelingViews.FindObject(vn), ModelingView)

layout1.ReplaceView(workPart.ModelingViews.WorkView, modelingView1, True)

workPart.ModelingViews.WorkView.Fit()

Dim wv As View
wv = Basepart.views.Workview



Dim ViewObj As Array

ViewObj = wv.AskVisibleObjects()



workPart.Layers.MoveDisplayableObjects(151, ViewObj)





msgBox("Moved all visible objects to layer 151 in view "&vn, ,"Flat Pattern Layer Move")


'lw.writeline("Cusom view name is = " &vn)

end if

Next b

If fviews = 0 then

msgbox("There is no flat pattern view", ,"Flat Pattern Layer Move")

end if

Else

MsgBox("There are no custom views", ,"Flat Pattern Layer Move")

end if




'Dim wv As tag
'wv = Basepart.views.Workview.tag
'lw.writeline(wv.ToString())





End Sub
End Module
























 
Replies continue below

Recommended for you

Try the following code; it iterates through the current work part's features looking for flat pattern features. When one is found it gets the curves and annotations and moves them to layer 151.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        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()

        Const undoMarkName As String = "move flat pattern objects"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Const flatPatternLayer As Integer = 151

        Dim flatPatternObjects As New List(Of DisplayableObject)

        For Each tempFeature As Features.Feature In workPart.Features

            If TypeOf (tempFeature) Is Features.FlatPattern Then

                Dim theFlatPattern As Features.FlatPattern = tempFeature

                Dim fpCurves() As NXObject = theFlatPattern.GetCurves
                For Each tempObj As DisplayableObject In fpCurves
                    flatPatternObjects.Add(tempObj)
                Next

                Dim fpAnnotations() As NXObject = theFlatPattern.GetAnnotations
                For Each tempObj As DisplayableObject In fpAnnotations
                    flatPatternObjects.Add(tempObj)
                Next

            End If

        Next

        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()
        displayModification1.NewLayer = flatPatternLayer

        displayModification1.Apply(flatPatternObjects.ToArray)
        displayModification1.Dispose()

        lw.Close()

    End Sub

End Module

www.nxjournaling.com
 
Excellent cowski, This code is working exactly what we need. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor