Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Wavelinking faces vb

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
So I am trying to implement a solution posted in thread561-197154 but that was for a previous version of NX and I think the coding has changed.

I am receiving the same error as the original poster which reads:
"NXOpen.NXException: The second parameter passed in was invalid"

My code is as follows:
Code:
   Public Function link_faces( ByRef SelectFaces() As Face )

      Dim tagWorkPart As NXOpen.Tag = theSession.Parts.Work.Tag
      Dim tempBody As Body = SelectFaces(0).GetBody()
      Dim tempComp As Component = tempBody.OwningComponent
      Dim compPart As Part = tempComp.Prototype
      Dim linked_feature As NXOpen.Tag = NXOpen.Tag.Null
      Dim object_in_part As NXOpen.Tag = theSession.Parts.Work.Views.WorkView.Tag
      'Dim xform As NXOpen.Tag = NXOpen.Tag.Null
      Dim returnFace(selectFaces.Length-1) As NXOpen.Tag
      Dim i as Integer = 0

      For Each aFace As Face In selectFaces

         Dim xform As NXOpen.Tag = NXOpen.Tag.Null
         Dim face_tag As NXOpen.Tag = selectFaces(i).Tag
         face_tag = theUFSession.Assem.AskPrototypeOfOcc(selectFaces(i).Tag)
         theUfSession.So.CreateXformAssyCtxt( object_in_part, face_tag, NXOpen.Tag.Null, xform)
         'theUfSession.Wave.CreateLinkedface(aFace.Tag, xform, selectFaces(i).Tag, True, linked_feature)

         theUFSession.Wave.CreateLinkedFace(face_tag,xform, displayPart.tag, True, returnFace(i))
         theUfSession.Modl.Update()
         i = i + 1
      Next

  End Function

The solution center posts the following code, which I tried to base my code off of:

Code:
  Public Function link_bodies(ByRef comp As Assemblies.Component)

    Dim workPart As NXOpen.Tag = s.Parts.Work.Tag
    Dim compPart As Part = comp.Prototype
    Dim linked_feature As NXOpen.Tag = NXOpen.Tag.Null
    Dim object_in_part As NXOpen.Tag = s.Parts.Work.Views.WorkView.Tag
    Dim xform As NXOpen.Tag = NXOpen.Tag.Null

    For Each aBody As Body In compPart.Bodies
        ufs.So.CreateXformAssyCtxt(object_in_part, comp.Tag, NXOpen.Tag.Null, xform)
        ufs.Wave.CreateLinkedBody(aBody.Tag, xform, object_in_part, True, linked_feature)
        ufs.Modl.Update()
    Next

  End Function

The solution for the error from the above linked post was as follows:

Code:
        '............................................................

        '.....Wavelink objects.......

        Dim cur_part_tag As Part = nxs.Parts.Display

        Dim wave_objs(selectedobject.Length - 1) As Tag

        Dim index As Integer = 0

        For index = 0 To selectedobject.Length - 1

            Dim my_xform As Tag = Tag.Null
            Dim obj_tag As Tag = selectedobject(index).Tag

            ' / If you working in assembly context /
            If (ufs.Assem.IsOccurrence(selectedobject(index).Tag)) Then
                obj_tag = ufs.Assem.AskPrototypeOfOcc(selectedobject(index).Tag)
            End If

            ufs.Wave.CreateLinkedBody(obj_tag, my_xform, cur_part_tag.Tag, False, wave_objs(index))

            ufs.Modl.Update()

but with the solution I get an error stating that IsOccurrence is not a part of ufs.Assem. and even though I added the line to set obj_tag = ufs.Assem.IsOccurrence(selectedobject(index).Tag) I still get the error.

I appreciate any help.

 
Replies continue below

Recommended for you

I think I stumbled on the solution by modifying the command:
theUfSession.So.CreateXformAssyCtxt( object_in_part, face_tag, NXOpen.Tag.Null, xform)

To read:
theUfSession.So.CreateXformAssyCtxt( object_in_part, tempComp.Tag, NXOpen.Tag.Null, xform)

Now to figure out how to pass this face back as a face to be used later.
 
What would be the best way to excute the public function link_bodies inside a journal? I cannot seem to call it properly.

Code:
Public Function link_bodies(ByRef comp As Assemblies.Component)

    Dim workPart As NXOpen.Tag = s.Parts.Work.Tag
    Dim compPart As Part = comp.Prototype
    Dim linked_feature As NXOpen.Tag = NXOpen.Tag.Null
    Dim object_in_part As NXOpen.Tag = s.Parts.Work.Views.WorkView.Tag
    Dim xform As NXOpen.Tag = NXOpen.Tag.Null

    For Each aBody As Body In compPart.Bodies
        ufs.So.CreateXformAssyCtxt(object_in_part, comp.Tag, NXOpen.Tag.Null, xform)
        ufs.Wave.CreateLinkedBody(aBody.Tag, xform, object_in_part, True, linked_feature)
        ufs.Modl.Update()
    Next

  End Function

Denis Huskic
Data Prep
Kettering University
Class of '17
 
Dim linkMoldFace() As Face = link_faces( moldFace )

I use that simple callout. Define the face of arrays with the callout to ensure the new face array is the correct size.
 
I tried adapting that to components and bodies but was unsuccesful. Here is what I have. Do you see anything I should change?

Code:
...
Dim linkcomp() As assemblies.component = link_bodies(comp)
End Sub

Public Function link_bodies(ByRef comp As Assemblies.Component)
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
    Dim workPart As NXOpen.Tag = s.Parts.Work.Tag
    Dim compPart As Part = comp.Prototype
    Dim linked_feature As NXOpen.Tag = NXOpen.Tag.Null
    Dim object_in_part As NXOpen.Tag = s.Parts.Work.Views.WorkView.Tag
    Dim xform As NXOpen.Tag = NXOpen.Tag.Null
    For Each aBody As Body In compPart.Bodies
        ufs.So.CreateXformAssyCtxt(object_in_part, comp.Tag, NXOpen.Tag.Null, xform)
        ufs.Wave.CreateLinkedBody(aBody.Tag, xform, object_in_part, True, linked_feature)
        ufs.Modl.Update()
    Next
  End Function
End Module

Denis Huskic
Data Prep
Kettering University
Class of '17
 
Right off I don't notice anything off, but I adapted this code from one intended for components and bodies. It is listed in the second list of code in the first post. The full version of which is on the Solution center just search Wave.

You should be able to cut and paste that right in.

Unfortunately I am running for the day but will be back tomorrow and will follow up with you first thing.

Note: you will need a log in to access the GTAC Solution Center:
 
Yes, I found the full code, thank you for that! I still have an error that reads:

"System.NullReferenceException: Object reference not set to an instance of an object"

for this line

Code:
For Each MyComponent As Assemblies.Component In workPart.ComponentAssembly.RootComponent.GetChildren

I checked all my reference sets and everything is set to "Entire Part" at the moment. Maybe I am not executing it properly.
I have an Assembly file, with 1 parent, 6 children. I tried a child and a parent as the workpart but neither work. Nothing is suppressed as well. Any Ideas?

Denis Huskic
Data Prep
Kettering University
Class of '17
 
where you have workPart.ComponentAssembly.RootComponent.GetChildren, this needs to be an Array containing values. it will cycle through each array value.
 
Solved: For those who might need a solution later I am posting the entire Sub

Code:
   Public Function link_faces( ByRef SelectFaces() As Face )

      Dim tagWorkPart                      As NXOpen.Tag = theSession.Parts.Work.Tag
      Dim tempBody                         As Body = SelectFaces(0).GetBody()
      Dim tempComp                         As Component = tempBody.OwningComponent
      Dim compPart                         As Part = tempComp.Prototype
      Dim linked_feature                   As NXOpen.Tag = NXOpen.Tag.Null
      Dim object_in_part                   As NXOpen.Tag = theSession.Parts.Work.Views.WorkView.Tag
      Dim returnFace(selectFaces.Length-1) As NXOpen.Tag
      Dim i                                As Integer = 0

      '------------------------------------------------------------------------------------------
      '   Wavelink faces to allow for associative manipulation of faces.
      '   Original Example found on Siemens Solution center titled "Wave Link all bodies from 
      '      selected component"
      '------------------------------------------------------------------------------------------

      For Each aFace                       As Face In selectFaces

         Dim xform As NXOpen.Tag = NXOpen.Tag.Null
         Dim face_tag As NXOpen.Tag = selectFaces(i).Tag
         face_tag = theUFSession.Assem.AskPrototypeOfOcc(selectFaces(i).Tag)
         theUfSession.So.CreateXformAssyCtxt( object_in_part, tempComp.Tag, NXOpen.Tag.Null, xform)

         theUFSession.Wave.CreateLinkedFace(face_tag,xform, displayPart.tag, True, returnFace(i))
         theUfSession.Modl.Update()
         i = i + 1
      Next

      '------------------------------------------------------------------------------------------
      '   At this point the wavelinked-faces will show up in the part navigator, but need to convert 
      '      Xform to faces to pass back into the program to be used later
      '      Convert the Wavelinked face first to an extracted face, then use get face an an array
      '      List to finally convert the feature back into a face for later use
      '------------------------------------------------------------------------------------------
      Dim extractedFaces(selectFaces.Length-1) As Features.ExtractFace
      Dim faceArrayTemp()                      As Face
      Dim aLFinalFace                          As New ArrayList()

      i = 0
      For Each aFace2 As NXOpen.Tag in returnFace
         ExtractedFaces(i) = NXObjectManager.Get(aFace2)
         i = i + 1
      Next

      For Each aFace3 As Features.ExtractFace in ExtractedFaces
         ReDim faceArrayTemp( aFace3.GetFaces.Length-1)
         faceArrayTemp = aFace3.GetFaces()

         For Each aFace4 As Face in faceArrayTemp
            aLFinalFace.Add( aFace4 )
         Next
      Next

      Dim finalFace As Face() = CType(alFinalFace.ToArray(GetType(Face)), Face() )

      Return finalFace

   End Function

Some error handling should be added, but I used an ArrayList which I found to be a much easier way to manipulate arrays then the way I was attempting before. There are other methods to accomplish this same thing but I was unable to get them to work. One of which was to use askLinkedFeatureGeom but the only example of its use I could find was in C and I am not proficient enough to get it to work in vb.

Hope this helps someone in the future.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor