activating an assembly

can anybody help me and let me know what's wrong with my code.. i am getting an error as number of indices is less than the number of dimensions of the indexed array.. this is my code





Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Collections.Generic
Imports NXOpen.Assemblies
Imports NXOpenUI

Module NXJournal
Public Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()

Dim mySelectedObjectsa() As Assemblies.Component 'NXObject '
Dim body1 As body

If getpart("Select Addendum Faces", mySelectedObjectsa) = Selection.Response.Cancel Then 'selectbody
Exit Sub
End if

Dim component1 As Assemblies.Component '= CType(workPart.ComponentAssembly.RootComponent.findobject("COMPONENT TOOL 1"), Assemblies.Component)
component1 = mySelectedObjectsa()
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(component1, partLoadStatus1)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")
workPart = theSession.Parts.Work
partLoadStatus1.Dispose()
theSession.SetUndoMarkName(markId3, "Make Work Part")

end sub

Function getpart (ByVal prompt As String, byRef selObj() as NXObject ) As Selection.Response 'Assemblies.Component selectbody

Dim theUI As UI = UI.GetUI
Dim title As String = "Select Addendum Face"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific

Dim scope As Selection.SelectionScope = Selection.SelectionScope.anyinassembly
Dim selectionMask_array(1) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
With selectionMask_array(1)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = 0
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, selObj)

If resp = Selection.Response.Ok
Return resp
Else
Return Selection.Response.Cancel
End If

End Function
End Module

There are a few issues with the code.

  • mySelectedObjectsa is declared as an array of components, the selection function returns NXObjects (or TaggedObjects depending on the version you use)
  • mySelectedObjectsa is declared as an array; later in the code, it is attempted to assign this array to an object (non-array) variable
  • the selection mask is set for solid bodies when it appears that you really want to select a component



Below is code to address the above issues.


Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Collections.Generic
Imports NXOpen.Assemblies
Imports NXOpenUI

Module Module14
Public Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()

Dim mySelectedObjectsa As TaggedObject 'NXObject '
Dim body1 As Body

If SelectComponent("Select Addendum Faces", mySelectedObjectsa) = Selection.Response.Cancel Then 'selectbody
Exit Sub
End If

Dim component1 As Assemblies.Component '= CType(workPart.ComponentAssembly.RootComponent.findobject("COMPONENT TOOL 1"), Assemblies.Component)
component1 = mySelectedObjectsa
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(component1, partLoadStatus1)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")
workPart = theSession.Parts.Work
partLoadStatus1.Dispose()
theSession.SetUndoMarkName(markId3, "Make Work Part")

End Sub

Function getpart(ByVal prompt As String, ByRef selObj() As NXObject) As Selection.Response 'Assemblies.Component selectbody

Dim theUI As UI = UI.GetUI
Dim title As String = "Select Addendum Face"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific

Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(1) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
With selectionMask_array(1)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = 0
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, selObj)

If resp = Selection.Response.Ok Then
Return resp
Else
Return Selection.Response.Cancel
End If

End Function

Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a component"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_component_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

End Module