Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

visula basic problem

Status
Not open for further replies.

studiotreccani

Mechanical
Nov 28, 2012
80
I was try to obtain a program:
select a component
the component will be copy in the other three position on the xy plane,
but it doesn't work at all. any tips?

Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports System.Collections.Generic

Module Module1
Sub Main()
' Ottieni la sessione e il part attuale
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim ui As UI = UI.GetUI()

' Chiedi all'utente di selezionare un componente
Dim selection As TaggedObject = Nothing
Try
' Utilizza la selezione dell'oggetto per ottenere un componente
Dim mask(0) As Selection.MaskTriple
mask(0).Type = UFConstants.UF_component_type
selection = ui.SelectionManager.SelectObject("Seleziona il componente da copiare", "Component", mask)
Catch ex As NXException
' Nessun componente selezionato, terminare il programma
ui.NXMessageBox.Show("Errore", NXMessageBox.DialogType.Information, "Nessun componente selezionato. Uscita.")
Exit Sub
End Try

' Assicurati che sia stato selezionato un componente
If selection Is Nothing OrElse Not TypeOf selection Is Component Then
ui.NXMessageBox.Show("Errore", NXMessageBox.DialogType.Information, "Selezione non valida. Uscita.")
Exit Sub
End If

' Ottieni il componente selezionato
Dim component As Component = CType(selection, Component)

' Ottieni la posizione e l'orientamento del componente
Dim position As New Point3d()
Dim orientation As New Matrix3x3()
component.GetPosition(position, orientation)

' Definisci una lista di segni per cambiare le coordinate X e Y
Dim signs As New List(Of Tuple(Of Integer, Integer)) From {
Tuple.Create(1, -1),
Tuple.Create(-1, 1),
Tuple.Create(-1, -1)
}

' Funzione per creare la nuova trasformazione
For Each sign In signs
Dim newOrientation As Matrix3x3 = CreateTransformation(orientation, sign.Item1, sign.Item2)
Dim newPosition As New Point3d(position.X * sign.Item1, position.Y * sign.Item2, position.Z)

' Aggiungi il nuovo componente con la nuova trasformazione
workPart.ComponentAssembly.AddComponent(component.Prototype, newPosition, newOrientation)
Next
End Sub

' Funzione che crea una nuova matrice di trasformazione cambiando i segni delle coordinate
Function CreateTransformation(ByVal orientation As Matrix3x3, ByVal newXSign As Integer, ByVal newYSign As Integer) As Matrix3x3
Dim transform As New Matrix3x3()
transform.Xx = orientation.Xx * newXSign
transform.Xy = orientation.Xy * newXSign
transform.Xz = orientation.Xz
transform.Yx = orientation.Yx * newYSign
transform.Yy = orientation.Yy * newYSign
transform.Yz = orientation.Yz
transform.Zx = orientation.Zx
transform.Zy = orientation.Zy
transform.Zz = orientation.Zz

Return transform
End Function
End Module



I actualy work with NX 2007
and soon NX 2406


 
Replies continue below

Recommended for you

Write down the Journal with the necessary manipulations, and you may find the answer in it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor