pefnxudem
Aerospace
- Feb 19, 2013
- 2
Hello, I'm trying to call a face or a datum plane by its name, so that an assembly can re adjust by itself. This is the code that I've been using, its recorded from a journal of the assembly.
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Assemblies->Component Position->Assembly Constraints...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim componentPositioner1 As Positioning.ComponentPositioner
componentPositioner1 = workPart.ComponentAssembly.Positioner
componentPositioner1.ClearNetwork()
Dim arrangement1 As Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), Assemblies.Arrangement)
componentPositioner1.PrimaryArrangement = arrangement1
componentPositioner1.BeginAssemblyConstraints()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
theSession.SetUndoMarkName(markId1, "Assembly Constraints Dialog")
componentNetwork1.MoveObjectsState = True
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints Update")
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Constraint")
Dim constraint1 As Positioning.Constraint
constraint1 = componentPositioner1.CreateConstraint()
Dim componentConstraint1 As Positioning.ComponentConstraint = CType(constraint1, Positioning.ComponentConstraint)
componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.InferAlign
componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch
Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT COT-ENSAMBLE-100-00 1"), Assemblies.Component)
Dim datumPlane1 As DatumPlane = CType(component1.FindObject("PROTO#HANDLE R-17067"), DatumPlane)
Dim constraintReference1 As Positioning.ConstraintReference
constraintReference1 = componentConstraint1.CreateConstraintReference(component1, datumPlane1, False, False, False)
Dim helpPoint1 As Point3d = New Point3d(796.525636938759, -234.663075170038, 174.229229891471)
constraintReference1.HelpPoint = helpPoint1
Dim component2 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 5600-16_tope_B-B_2 8"), Assemblies.Component)
Dim face1 As Face = CType(component2.FindObject("PARTIAL_PROTO#.Bodies|Body8|HANDLE R-3959"), Face)
Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint1.CreateConstraintReference(component2, face1, False, False, False)
Dim helpPoint2 As Point3d = New Point3d(664.47546179753, 0.723173715489565, 88.9000000000001)
constraintReference2.HelpPoint = helpPoint2
constraintReference2.SetFixHint(True)
componentConstraint1.SetAlignmentHint(Positioning.Constraint.Alignment.ContraAlign)
componentNetwork1.Solve()
Dim face2 As Face = CType(component1.FindObject("PROTO#.Features|REVOLVED(3)|FACE [CURVE 2 0]"), Face)
Dim line1 As Line
line1 = workPart.Lines.CreateFaceAxis(face2, SmartObject.UpdateOption.AfterModeling)
Dim objects1(0) As NXObject
objects1(0) = line1
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints")
componentNetwork1.Solve()
componentPositioner1.ClearNetwork()
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)
componentPositioner1.DeleteNonPersistentConstraints()
Dim nErrs4 As Integer
nErrs4 = theSession.UpdateManager.DoUpdate(markId2)
theSession.DeleteUndoMark(markId4, Nothing)
theSession.SetUndoMarkName(markId1, "Assembly Constraints")
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
componentPositioner1.EndAssemblyConstraints()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.DeleteUndoMark(markId3, Nothing)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
The underlined parts are the ones that I want to call by their name, mainly the datum part.
Thanks
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: Assemblies->Component Position->Assembly Constraints...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim componentPositioner1 As Positioning.ComponentPositioner
componentPositioner1 = workPart.ComponentAssembly.Positioner
componentPositioner1.ClearNetwork()
Dim arrangement1 As Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), Assemblies.Arrangement)
componentPositioner1.PrimaryArrangement = arrangement1
componentPositioner1.BeginAssemblyConstraints()
Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning
Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()
Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)
componentNetwork1.MoveObjectsState = True
Dim nullAssemblies_Component As Assemblies.Component = Nothing
componentNetwork1.DisplayComponent = nullAssemblies_Component
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
theSession.SetUndoMarkName(markId1, "Assembly Constraints Dialog")
componentNetwork1.MoveObjectsState = True
componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints Update")
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Constraint")
Dim constraint1 As Positioning.Constraint
constraint1 = componentPositioner1.CreateConstraint()
Dim componentConstraint1 As Positioning.ComponentConstraint = CType(constraint1, Positioning.ComponentConstraint)
componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.InferAlign
componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch
Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT COT-ENSAMBLE-100-00 1"), Assemblies.Component)
Dim datumPlane1 As DatumPlane = CType(component1.FindObject("PROTO#HANDLE R-17067"), DatumPlane)
Dim constraintReference1 As Positioning.ConstraintReference
constraintReference1 = componentConstraint1.CreateConstraintReference(component1, datumPlane1, False, False, False)
Dim helpPoint1 As Point3d = New Point3d(796.525636938759, -234.663075170038, 174.229229891471)
constraintReference1.HelpPoint = helpPoint1
Dim component2 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 5600-16_tope_B-B_2 8"), Assemblies.Component)
Dim face1 As Face = CType(component2.FindObject("PARTIAL_PROTO#.Bodies|Body8|HANDLE R-3959"), Face)
Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint1.CreateConstraintReference(component2, face1, False, False, False)
Dim helpPoint2 As Point3d = New Point3d(664.47546179753, 0.723173715489565, 88.9000000000001)
constraintReference2.HelpPoint = helpPoint2
constraintReference2.SetFixHint(True)
componentConstraint1.SetAlignmentHint(Positioning.Constraint.Alignment.ContraAlign)
componentNetwork1.Solve()
Dim face2 As Face = CType(component1.FindObject("PROTO#.Features|REVOLVED(3)|FACE [CURVE 2 0]"), Face)
Dim line1 As Line
line1 = workPart.Lines.CreateFaceAxis(face2, SmartObject.UpdateOption.AfterModeling)
Dim objects1(0) As NXObject
objects1(0) = line1
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints")
componentNetwork1.Solve()
componentPositioner1.ClearNetwork()
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)
Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)
componentPositioner1.DeleteNonPersistentConstraints()
Dim nErrs4 As Integer
nErrs4 = theSession.UpdateManager.DoUpdate(markId2)
theSession.DeleteUndoMark(markId4, Nothing)
theSession.SetUndoMarkName(markId1, "Assembly Constraints")
Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement
componentPositioner1.EndAssemblyConstraints()
theSession.DeleteUndoMark(markId2, Nothing)
theSession.DeleteUndoMark(markId3, Nothing)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
The underlined parts are the ones that I want to call by their name, mainly the datum part.
Thanks