Hello,
I need to perform an action similar to the interactive Sketch "Reattach" for multiple sketches in a model if the sketches exhibit a warning about "Referenced measure parent is missing associated parents and may be out of date".
We have found that performing a reattach interactively mends this issue, so we'd like to create a programmatic fix for this.
I have already set up a framework to cycle through all sketches of a model, check for its associative placement status and decide whether to try modifying it.
BUT: I have not succeeded in actually performing that "Reattach" action.
So, if anyone migth contribute this "bit", I would very much appreciate it.
Of course I recorded a journal of an interactive reattach action to see what gets recorded but what I get does not seem fit for reuse in a code. Not even for exactly the same sample sketch and even less for sketches being placed with all sorts of methods.
I will place my "framework" code here - of course you will see the "Try" part is not yet doint what a simple interactive "reattach" action without selecting anything and just clicking [OK] would do.
Hope someone knows how to achieve the result in question.
Thanks for supporting & best regards
/Udo
Option Strict Off Option Explicit On Imports System Imports NXOpen Imports NXOpen.UF Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim theUI As UI = UI.GetUI() Dim theUfSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() For Each sketch1 As Sketch In workPart.Sketches sketch1.Activate(Sketch.ViewReorient.False) Dim sketchInPlaceBuilder1 As SketchInPlaceBuilder sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(theSession.ActiveSketch) 'nur zum testen der Assoziativität mit dem deprecated-Befehl! 'lw.WriteLine("Sketch=" + sketch1.Name + " Associative Origin=" + sketchInPlaceBuilder1.MakeOriginAssociative.ToString()) Dim sketchInPlaceBuilder2 As SketchInPlaceBuilder sketchInPlaceBuilder2 = workPart.Sketches.CreateSketchInPlaceBuilder2(theSession.ActiveSketch) 'für plane-Zugriff! If sketchInPlaceBuilder1.MakeOriginAssociative = False Then lw.WriteLine("Sketch=" + sketch1.Name + " Associative Origin=" + sketchInPlaceBuilder1.MakeOriginAssociative.ToString()) 'mend sketch 'enter edit sketch environment theSession.BeginTaskEnvironment() 'try to apply reattach for XY plane Try Dim plane1 As NXOpen.Plane = Nothing plane1 = sketchInPlaceBuilder2.PlaneReference plane1.Evaluate() sketchInPlaceBuilder2.PlaneOption = NXOpen.Sketch.PlaneOption.ExistingPlane Dim sketchAlongPathBuilder1 As NXOpen.SketchAlongPathBuilder = Nothing sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(theSession.ActiveSketch) sketchAlongPathBuilder1.Section.PrepareMappingData() plane1.SetMethod(NXOpen.PlaneTypes.MethodType.Coincident) plane1.SetMethod(NXOpen.PlaneTypes.MethodType.Coincident) Dim geom1(0) As NXOpen.NXObject Dim datumPlane1 As NXOpen.DatumPlane = CType(workPart.Datums.FindObject("DATUM_CSYS(0) XZ plane"), NXOpen.DatumPlane) 'Skizzenebene auf Datum Plane 1 setzen 'ermitteln, auf welcher Ebene die aktuelle Skizze platziert ist Dim surface1 As ISurface = sketch1.AttachPlane geom1(0) = datumPlane1 'geom1(0) = surface1 plane1.SetGeometry(geom1) 'plane1.SetAlternate(NXOpen.PlaneTypes.AlternateType.One) plane1.Evaluate() Dim nXObject1 As NXOpen.NXObject = Nothing nXObject1 = sketchInPlaceBuilder2.Commit() Dim feature1 As NXOpen.Features.Feature = Nothing feature1 = theSession.ActiveSketch.Feature sketchInPlaceBuilder1.Destroy() sketchInPlaceBuilder2.Destroy() sketchAlongPathBuilder1.Destroy() Catch ex As Exception lw.WriteLine("Error:" + ex.Message) End Try 'finish sketch theSession.EndTaskEnvironment() End If Next End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination '----Other unload options------- 'Unloads the image immediately after execution within NX 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately 'Unloads the image explicitly, via an unload dialog 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly '------------------------------- End Function End Module