Hello,
I'm trying to delete some assembly constraints by name but I can't accomplish this.
I read this post http://www.nxjournaling.com/?q=content/regard-sketch-constraints it helped me to understand somethings, but still my modifications were useless.
I also have this, but it doesn't delete the constraint.
Sub Main()
If (dp Is Nothing) Then
msg.Show("", NXOpen.NXMessageBox.DialogType.Error, "No Display Part !!!")
Return
End If
Try ' return a collection of all the sub_assembly in the displayed part
Lsub_assembly.Add(dp, dp.ToString)
Scan_Assembly(dp.ComponentAssembly.RootComponent, Lsub_assembly)
Catch e As Exception
End Try
Dim nom As String
Dim comp, parent As Component
For Each part As Part In Lsub_assembly
nom = Descriptive_Part_Name(part)
Echo("Part = " & nom)
Try
Dim save_arrangement = part.ComponentAssembly.ActiveArrangement
Dim marque As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Visible, "Delete Constraints")
For Each a As Arrangement In part.ComponentAssembly.Arrangements
part.ComponentAssembly.ActiveArrangement = a
Echo(vbTab & "Arrangement = " & a.Name)
For Each c As ComponentConstraint In part.ComponentAssembly.Positioner.Constraints
' This name is given at the constraint's information screen
If c.Name.Equals("Assembly Constraint - Touch (MORDAZA_621, Assembly_623)") Then
s.UpdateManager.AddToDeleteList(c)
End If
Echo(vbTab & vbTab & "Constraint deleted = " & c.Name)
Next
s.UpdateManager.DoAssemblyConstraintsUpdate(marque)
Next
part.ComponentAssembly.ActiveArrangement = save_arrangement
Catch ex As Exception
End Try
Next
ufs.Modl.Update()
Can someone help me.
Regards.
David Mendez
DELETE ASSEMBLY CONSTRAINTS BY NAME
I resolved this by deleting first the components that I didn't need anymore and the delete the unresolved constraints.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Positioning
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Module Erase_Component_Constraint
Public s As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = s.ListingWindow
Public dp As Part = s.Parts.Display
Public wp As Part = s.Parts.Work
Public msg As NXMessageBox = UI.GetUI().NXMessageBox
' Here set the elements you won't be needing
Public element() As String
Sub Main()
Dim mark_componet As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Invisible, "COMPONENTS")
Dim mark_constraints As Session.UndoMarkId = s.SetUndoMark(Session.MarkVisibility.Invisible, "CONSTRAINTS")
Dim objects1(0) As NXObject
Dim component1 As Assemblies.Component
s.UpdateManager.ClearErrorList()
' ITS IMPORTANT TO UPDATE THE ERASED COMPONENTS, IF NOT UPDATED THE ERASE CONSTRAINT CODE WON'T WORK
For Each component As String In element
component1 = CType(wp.ComponentAssembly.RootComponent.FindObject(component), Assemblies.Component)
objects1(0) = component1
s.UpdateManager.AddToDeleteList(objects1)
s.UpdateManager.DoUpdate(mark_componet)
Next
'ERASE UNRESOLVED CONSTRAINTS
For Each c As ComponentConstraint In dp.ComponentAssembly.Positioner.Constraints
If c.GetConstraintStatus = Constraint.SolverStatus.CannotSolve Then
s.UpdateManager.AddToDeleteList(c)
End If
Next
' UPDATE CONSTRAINTS, IF THE NEXT LINE IS INSIDE THE LAST FOR, IT WON'T WORK
s.UpdateManager.DoUpdate(mark_constraints)
' UNCOMMENT NEXT LINE TO ERASE ALL UNDO MARKS
's.DeleteAllUndoMarks()
End Sub
End Module
Thanks you.
Automative