jiloebel
Mechanical
- Aug 7, 2012
- 14
Hi all,
I've done quite a bit of searching on this, and read through the help files, but can't seem to get this to work. I am trying to make a (simple for now) program to select components and add them to a component group. (I know this can be easily done without a journal, but this will eventually be merged into a journal that will be doing several other things.)
I started of by using an example code for selecting objects and tried adding the component group in. Here's what I have so far:
There issue I'm having is I'm not sure how to initialize the ComponentGroup (group1), so the line "Group1.AddComponent(myselectedobject,0)" is just giving an error.
Any help would be appreciated.
Thanks!
I've done quite a bit of searching on this, and read through the help files, but can't seem to get this to work. I am trying to make a (simple for now) program to select components and add them to a component group. (I know this can be easily done without a journal, but this will eventually be merged into a journal that will be doing several other things.)
I started of by using an example code for selecting objects and tried adding the component group in. Here's what I have so far:
Code:
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelectedObject As Assemblies.Component
Dim Group1 As Assemblies.ComponentGroup
lw.Open()
'Continue prompting for a selection until the user
' presses Cancel or Back.
Do Until SelectAnObject("Hey, select something", _
mySelectedObject) = Selection.Response.Cancel
lw.WriteLine("Object Tag: " & mySelectedObject.Tag)
lw.WriteLine("object Name: " & mySelectedObject.Name)
lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
lw.WriteLine("")
Group1.AddComponent(mySelectedObject, 0)
Loop
' The close method closes the text stream to the window,
' it does not close the window itself
' (use the .CloseWindow() method for that).
' Also, if you are using the listing window to write
' to a file, the close method will clean up and close the file.
lw.Close()
End Sub
Function SelectAnObject(ByVal prompt As String, _
ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All, _
Selection.SelectionType.Faces, _
Selection.SelectionType.Edges, _
Selection.SelectionType.Features}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
There issue I'm having is I'm not sure how to initialize the ComponentGroup (group1), so the line "Group1.AddComponent(myselectedobject,0)" is just giving an error.
Any help would be appreciated.
Thanks!