×
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

Wavelinking faces vb

Wavelinking faces vb

Wavelinking faces vb

(OP)
So I am trying to implement a solution posted in thread561-197154: Journal (.NET) Wavelink objects 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 --> vb

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 --> vb

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.

RE: Wavelinking faces vb

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

RE: Wavelinking faces vb

What would be the best way to excute the public function link_bodies inside a journal? I cannot seem to call it properly.

CODE --> vb

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

RE: Wavelinking faces vb

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

RE: Wavelinking faces vb

I tried adapting that to components and bodies but was unsuccesful. Here is what I have. Do you see anything I should change?

CODE --> vb

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

RE: Wavelinking faces vb

(OP)
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:
http://solutions.industrysoftware.automation.sieme...

RE: Wavelinking faces vb

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 --> vb

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

RE: Wavelinking faces vb

(OP)
where you have workPart.ComponentAssembly.RootComponent.GetChildren, this needs to be an Array containing values. it will cycle through each array value.

RE: Wavelinking faces vb

(OP)
Solved: For those who might need a solution later I am posting the entire Sub

CODE --> vb

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.

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