Forums:
As part of a program that will WaveLink some geometry from one part in an assembly into a newly inserted component, I am having issues setting the newly inserted component as the WorkPart. I have attached a complete set of code that asks the user to select a component and inserts an existing prt file into it. It then tries to make the new component the workpart. Any ideas why the new component doesn't highlight after attempting to set it to work part? The wavelinking done later doesn't behave like it is work either.
Note: I wasn't sure If I should have stayed in the previous discussion about getting the component of the inserted file. I broke it out to a new subject for those looking to see how to set an inserted component to the work part.
PublicSharedSub Main(ByVal args()AsString) Gvars.m_ufs.Ui.ExitListingWindow() Gvars.lw.Open() '---------------------------------------------------------'// select host component'---------------------------------------------------------Dim compCupCrvUnit As Component Dim strPrompt AsString="Pick Curve Unit"If SelectComponent(strPrompt, m_compCupCrvUnit)= Selection.Response.CancelThen'// user cancelled the selectionExitSubEndIf m_strCurveUnitName = m_compCupCrvUnit.Name Gvars.lw.WriteLine("after select component. name: "& m_strCurveUnitName) '-------------------------------------' insert component'-------------------------------------Dim newComp As Component Dim strNewFnPath AsString="c:\test\TestPart5.prt" InsertPartAtOrigin(m_compCupCrvUnit.Prototype, strNewFnPath, "test5", newComp) '-------------------------------------'// set work part'-------------------------------------TryDim partLoadStatus1 As NXOpen.PartLoadStatus=Nothing Gvars.Session.Parts.SetWorkComponent(newComp, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1) Dim somepart As Part = Gvars.Session.Parts.Work Catch ex As Exception Gvars.lw.WriteLine("#### Error while setting work part to NewCurve start part "& ex.Message)EndTry '------------------------------------------------'// get the work part and find out who this is'------------------------------------------------TryDim tempWorkPart As Part tempWorkPart = Gvars.Session.Parts.Work Gvars.lw.WriteLine("workpart name: "& tempWorkPart.Name)Catch ex As Exception Gvars.lw.WriteLine("### error getting work part: "& ex.ToString)EndTry Gvars.lw.WriteLine("I'm expecting the inserted component to highlight as if it is the work part") EndSub '***************************************************************************************'// 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 tagNewInstance As NXOpen.TagDim layer AsInteger=-1' Original LayerDim LoadStatus As NXOpen.UF.UFPart.LoadStatusDim strNewRefSetName AsString="" '-------------------------------------------------------'-- insert the component'-------------------------------------------------------Dim dblInputMatrix(5)AsDouble dblInputMatrix(0)=1 dblInputMatrix(1)=0 dblInputMatrix(2)=0 dblInputMatrix(3)=0 dblInputMatrix(4)=1 dblInputMatrix(5)=0 '-------------------------------------------------------'add the component to the assembly'-------------------------------------------------------Dim 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, tagNewInstance, LoadStatus) Catch ex As Exception MsgBox("Insert failed: "& ex.ToString) Gvars.lw.WriteLine("AddPartToAssembly failed: "& ex.ToString)EndTry Try'-----------------------------------------------------'// get and return the componet'-----------------------------------------------------Dim newCompTag As Tag = NXOpen.Tag.Null newCompTag = Gvars.m_ufs.Assem.AskPartOccOfInst(Gvars.m_ufs.Assem.AskRootPartOcc(partDest.Tag), tagNewInstance) NewComponent = NXOpen.Utilities.NXObjectManager.Get(newCompTag) '-------------------------------------------------------'// test to see if the NewComponent is nothing'-------------------------------------------------------If NewComponent IsNothingThen Gvars.lw.WriteLine("## Error the NewComponent is nothing:")Else Gvars.lw.WriteLine("It worked! We have the new component: "& NewComponent.Name)EndIf Catch ex As Exception Gvars.lw.WriteLine("Getting componnent failed: "& ex.ToString)EndTry EndSub PublicSharedFunction SelectComponent(ByVal prompt AsString, ByRef oComp As Assemblies.Component)As NXOpen.Selection.Response Dim mask()As Selection.MaskTriple={New Selection.MaskTriple(UFConstants.UF_component_type, 0, 0)}Dim cursor As Point3d =NothingDim obj As TaggedObject =Nothing Dim resp As Selection.Response= UI.GetUI().SelectionManager.SelectTaggedObject(prompt, prompt, Selection.SelectionScope.AnyInAssembly, Selection.SelectionAction.ClearAndEnableSpecific, False, False, mask, obj, cursor) If resp = Selection.Response.ObjectSelectedOr resp = Selection.Response.ObjectSelectedByNameThen oComp =CType(obj, Assemblies.Component)Return NXOpen.Selection.Response.OkElseReturn NXOpen.Selection.Response.CancelEndIfEndFunction