Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 783

How to get component after inserting part

$
0
0

Hi all,

I'm trying to create a subroutine that inserts a part into an assembly using the "AddPartToAssembly" ufunc. The sub will insert the part just fine. However, I need to return the Component that is created upon insertion. As I understand it, the 2nd from the last parameter should be the tag of the component. Either I'm misunderstanding what that really is or am having trouble converting from Tag to Component. The line where the sub crashes is:
NewComponent =CType(taggedObj1, Component)

Here is my subroutine:

'***************************************************************************************'// partDest: part where you want to insert the new component'// strPartFnPath: the file name and path to the part being inserted'// strComponentName: the name assigned to the new component'// the component created by the insertion.'***************************************************************************************PublicSharedSub InsertPartAtOrigin(ByVal partDest As Part,
                                         ByVal strPartFnPath AsString,
                                         ByVal strComponentName AsString,
                                         ByRef NewComponent As Component) 
 
        Dim dblCsysMatrix(8)AsDoubleDim dblXVec(2)AsDoubleDim dblYVec(2)AsDouble 
        Dim tagCsysMatrix As NXOpen.TagDim tagCsys As NXOpen.Tag 
        Dim tagNewComp As NXOpen.TagDim layer AsInteger=-1' Original LayerDim LoadStatus As NXOpen.UF.UFPart.LoadStatusDim tagParentPart As NXOpen.Tag 
        Dim strNewRefSetName AsString="" 
        '-------------------------------------------------------'-- Define position matrix'-------------------------------------------------------Dim dblInputMatrix(5)AsDouble
        dblInputMatrix(0)=1
        dblInputMatrix(1)=0
        dblInputMatrix(2)=0
        dblInputMatrix(3)=0
        dblInputMatrix(4)=1
        dblInputMatrix(5)=0 
 
        '// Note: the instance name will show up as "Component Name" in the assembly browserDim strInstanceName AsString= strComponentName
        Dim dblCompOrigin(2)AsDouble
        dblCompOrigin(0)=0
        dblCompOrigin(1)=0
        dblCompOrigin(2)=0 
        Try
            Gvars.m_ufs.Assem.AddPartToAssembly(partDest.Tag,
                    strPartFnPath,
                    strNewRefSetName,
                    strInstanceName,
                    dblCompOrigin,
                    dblInputMatrix,
                    layer,
                    tagNewComp,
                    LoadStatus) 
 
            '---------------------------------------------------'// get the part and return it'---------------------------------------------------Dim taggedObj1 As NXOpen.TaggedObject= NXOpen.Utilities.NXObjectManager.Get(tagNewComp)
            NewComponent =CType(taggedObj1, Component) 
        Catch ex As Exception
            MsgBox("insert failed")EndTry 
    EndSub

Viewing all articles
Browse latest Browse all 783

Trending Articles