cancel
Showing results for 
Search instead for 
Did you mean: 

How does UFSession.Modl.CopyPasteFeatures work?

Builder
Builder

Does anybody know how UFSession.Modl.CopyPasteFeatures work?

I am trying to use it but I keep getting a MemoryAccessException.

It seems to copy the first two features or so into the new Part fle, but I get the exception and the NX Session crashes.

Can anyone explain exactly what each parameter in the method header is expecting?

Thank you.

6 REPLIES

Re: How does UFSession.Modl.CopyPasteFeatures work?

Esteemed Contributor
Esteemed Contributor

Ae you trying to copy feature one at a time or a bunch at a time?

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: How does UFSession.Modl.CopyPasteFeatures work?

Esteemed Contributor
Esteemed Contributor

Assuming this finctionality is journaled...Have you tried recording a journal?

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: How does UFSession.Modl.CopyPasteFeatures work?

Builder
Builder
I guess either or.
With my current instance I am trying to do a bunch, but there would be times when I am copying one at a time.

Re: How does UFSession.Modl.CopyPasteFeatures work?

Builder
Builder
Yes, but I found the UFSession method and it looks a lot cleaner and wanted to know how it worked.

Re: How does UFSession.Modl.CopyPasteFeatures work?

Esteemed Contributor
Esteemed Contributor

If you have multiple features to ocpy/paste - I would suggest trying to do them one-by-one (not as a set)

 

It may work better (or it may not, but you don't know until you try)

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: How does UFSession.Modl.CopyPasteFeatures work?

Siemens Phenom Siemens Phenom
Siemens Phenom

 

This works, as long as I select features that have no parents, or if they do have parents, I have to select the parents as well as the feature I want to paste.

 

For example, if I select a primitive Block Feature, and a Cylinder and a Sphere, it works fine.

 

If I select an Edge Blend feature on the Block, but not the Block itself, there is nothing in the oldParents array, so it fails - there is no designation for the body the Blends live on.

 

But if you carefully specify the proper oldParents and newParents, you should be able to use it for much more complex transactions than this simple demo.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.UF
Imports NXOpen.UI

Module demonstrate_wrapper_for_uf_modl_copy_paste_features

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

    Sub Main()

        Dim dp As Part = theSession.Parts.Display

        Dim origFeatures() As Feature = selectFeatures("Features to Copy/Paste:")

        Dim featCount As Integer = origFeatures.Length()

        Dim numParents As Integer = 0

        Dim oldParents() As NXOpen.Tag = {}
        Dim newParents() As NXOpen.Tag = {}
        Dim NewFeatureTags() As NXOpen.Tag = {}

        Dim inx As Integer = 0

        Dim origFeatTagArray(featCount - 1) As NXOpen.Tag

        For Each thisFeat As Feature In origFeatures
            origFeatTagArray(inx) = thisFeat.Tag
            inx += 1
        Next

        Dim theUnits As Integer = -1

        ufs.Part.AskUnits(dp.Tag, theUnits) ' get units of existing part

        Dim theNewPart As NXOpen.Tag = NXOpen.Tag.Null

        ufs.Part.[New]("NewPartForPasting.prt", _
            theUnits, theNewPart) 'create new part and switch to it

        ufs.Modl.CopyPasteFeatures(origFeatTagArray, featCount, _
            oldParents, newParents, _
            numParents, 0, 0, NewFeatureTags) ' paste the features

        theSession.Parts.Work.Views.WorkView.Fit()

    End Sub

    Function selectFeatures(ByVal prompt As String) As Features.Feature()
        Dim theUI As UI = UI.GetUI
        selectFeatures = Nothing
        theUI.SelectionManager.SelectFeatures(prompt, _
            Selection.SelectionFeatureType.Browsable, selectFeatures)
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module