Dear Cubalibre00,
If you would like to play: The horizontal aligning works.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
'Imports NXOpen.UI
Imports NXOpen.Utilities
Module Module1
' Explicit Activation
' This entry point is used to activate the application explicitly
Public theSession As Session = Session.GetSession()
Public theUI As UI = UI.GetUI()
Public theUfSession As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Sub Main()
' id_symbol listazasanak meghivasa, ami tartamaz egy x koordinata szerinti rendezest es symbol mozgatas alfuggvenyeket
id_lista()
End Sub
' Rajz nezet lekerdezese, hogy hany darab nezet van, felhasznaljuk az id_symbols nezetenkenti kezelesekor
Function rajz_hatar() As Array
Try
Dim dp As Integer = 0
'dp = check_for_missing_display_part()
'If dp = 1 Then
'Return 0
' End If
Dim currentDrawing As NXOpen.Tag = NXOpen.Tag.Null
Dim dwgViews() As NXOpen.Tag
Dim numViews As Integer = 0
Dim viewName As String = ""
Dim vwBrdr(3) As Double
'Dim nezetek As ArrayList
theUfSession.Draw.AskCurrentDrawing(currentDrawing)
theUfSession.Draw.AskViews(currentDrawing, numViews, dwgViews)
lw.Open()
For Each currentView As NXOpen.Tag In dwgViews
theUfSession.Obj.AskName(currentView, viewName)
'lw.WriteLine("View Name: " & viewName)
'lw.WriteLine("View Name tag: " & currentView.ToString)
theUfSession.Draw.AskViewBorders(currentView, vwBrdr)
'nezetek.Add(currentView.ToString)
'Nezethatar bal also es jobb felso sarkanak koordinatainak lekerdezese
'lw.WriteLine("vwBrdr = " & vwBrdr(0).ToString() & ", " _
'& vwBrdr(1).ToString() & ", " _
'& vwBrdr(2).ToString() & ", " _
'& vwBrdr(3).ToString())
Next
For hh As Integer = 0 To numViews - 1
'lw.WriteLine(dwgViews(hh).ToString)
Next
Return dwgViews
Catch ex As NXOpen.NXException
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.[Error], ex.Message)
End Try
End Function
' Van-e megjelenitett alkatresz
Public Function check_for_missing_display_part() As Integer
Dim dispPart As Part = Nothing
Try
dispPart = theSession.Parts.Display
Catch ex As Exception
lw.Open()
lw.WriteLine("+++Error: " & ex.ToString())
End Try
If dispPart Is Nothing Then
lw.Open()
lw.WriteLine("There is no current Displayed Part")
theUfSession.UF.PrintSyslog("+++ERROR: There is no current Displayed Part", _
False)
Return 1
End If
Return 0
End Function
' id_symbols arraylist-be masolasa nezetenkent
Function id_lista() As ArrayList
'Dim symbol_tags As New ArrayList
Dim ossze_nezet As Integer = 0
'lw.WriteLine(rajz_hatar.Length)
If rajz_hatar() IsNot Nothing Then
If rajz_hatar().Length <> 0 Then
'lw.WriteLine(rajz_hatar.Length) 'Hany darab nezet van a rajzon
For osszes_nezet = 0 To rajz_hatar().Length - 1
lw.WriteLine("---------itt kezdodik--------") 'id_symbol-ok kezelese nezetenkent itt kezdödik
lw.WriteLine("Nezet neve" & rajz_hatar(osszes_nezet).ToString)
'Ebbe kerulnek a id_symbol-ok tag-jei, anyiszor fut ahany rajzi nezet van
Dim symbol_tags As New ArrayList
Dim idcol As Annotations.IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
Dim ids As Annotations.IdSymbol
Dim iEnum1 As IEnumerator = idcol.GetEnumerator()
iEnum1.Reset()
Dim parent_view As New ArrayList
Dim koztes As Integer = 0
'Addig megy meg vegig nem jarja az osszes nezeten levo, osszes id_symbol-t
While iEnum1.MoveNext()
ids = DirectCast(iEnum1.Current, Annotations.IdSymbol)
lw.Open()
'id_symbol tag-jenek kiiratasa
lw.WriteLine("Symbol: " & ids.Tag.ToString())
Dim idsb As Annotations.IdSymbolBuilder = idcol.CreateIdSymbolBuilder(ids)
'lw.WriteLine(" Text: " + idsb.UpperText) 'id_symbol-ban levo szoveg
'lw.WriteLine(" Origin: " & idsb.Origin.OriginPoint.ToString()) 'id_symbol(karika) kozepe
'lw.WriteLine(" Size: " & idsb.Size) 'id_symbol (karika) atmeroje
Dim lb As Annotations.LeaderBuilder = idsb.Leader
Dim ldl As Annotations.LeaderDataList = lb.Leaders
'lw.WriteLine(" Number of LeaderData: " + ldl.Length.ToString())
Dim selection1 As DisplayableObject
Dim view1 As View
Dim hatar(3) As Double
'id_symbol mutatovonalainak kezelese
For i As Integer = 0 To ldl.Length - 1
Dim ld As Annotations.LeaderData = ldl.FindItem(i)
'lw.WriteLine(" LeaderData No." & i & ": " & ld.ToString())
'lw.WriteLine(" Stub Size: " & ld.StubSize.ToString()) 'Mutatovonal tulnyulasa
'lw.WriteLine(" Stub Side: " & ld.StubSide.ToString()) 'Mutatovonal merre all
' Perpendicular as of NX7
' lw.WriteLine(" Perpendicular: " + ld.Perpendicular.ToString()); 'Mutatovonal meroleges-e
'lw.WriteLine(" Arrowhead: " & ld.Arrowhead.ToString()) 'Mutatovonal nyilveg
'Melyik nezetre mutat az id_symbol
Dim point1 As Point3d
'lw.WriteLine(ld.Leader.Tag)
ld.Leader.GetValue(selection1, view1, point1)
'lw.WriteLine(" Leader view: " & view1.Name)
'lw.WriteLine(" Leader view type: " + view1.GetType().ToString())
'lw.WriteLine(" Leader point: " & point1.ToString())
'Ha a mutatovonal nezete megegyezik a rajz_hatar-ban levo nezettel, akkor beleteszi
If view1.Tag = rajz_hatar(osszes_nezet).ToString Then
symbol_tags.Add(ids.Tag.ToString())
End If
'id_symbol melyik koordinatara mutat
If (view1.GetType().ToString() <> "NXOpen.View") Then
Dim model_pt(2) As Double
model_pt(0) = point1.X
model_pt(1) = point1.Y
model_pt(2) = point1.Z
Dim map_pt(1) As Double
theUfSession.View.MapModelToDrawing(view1.Tag, model_pt, map_pt)
'lw.WriteLine(" Mapped Leader point: X=" & map_pt(0).ToString() & " ,Y= " & map_pt(1).ToString())
End If
'id_symbol-nak hany torese van és hol
'lw.WriteLine(" Number of jogs: " & ld.Jogs.Size.ToString())
Dim jogs As SelectObject() = ld.Jogs.GetSelectObjectArray()
For Each jog As SelectObject In jogs
'lw.WriteLine(" Jog: " & jog.ToString())
Dim selection2 As TaggedObject
Dim view2 As View
Dim point2 As Point3d
jog.GetValue(selection2, view2, point2)
'lw.WriteLine(" Jog point: " & point2.ToString())
Next
Next
idsb.Destroy()
'lw.WriteLine(" Number of Associativities: " + ids.NumberOfAssociativities.ToString())
For i As Integer = 1 To ids.NumberOfAssociativities
Dim assoc As Annotations.Associativity = ids.GetAssociativity(i)
'lw.WriteLine(" Assoc No." & i & ": " & assoc.ToString())
'lw.WriteLine(" ObjectView : " + assoc.ObjectView.Name)
Dim obj As NXObject = assoc.FirstObject
If obj Is Nothing Then
'lw.WriteLine(" FirstObject : null")
Else
'lw.WriteLine(" FirstObject : " & obj.ToString())
'lw.WriteLine(" Owning Part: " + obj.OwningPart.FullPath)
If obj.IsOccurrence Then
'lw.WriteLine(" Owning Component: " + obj.OwningComponent.Name)
End If
End If
Next
End While
'Ez csak egy visszaellenorzes lenne, hany eleme van a tombnek
Dim ii As Integer
For ii = 0 To symbol_tags.Count - 1
'lw.WriteLine(symbol_tags(ii).ToString)
Next
'rendezes alfuggveny meghivasa: symbol_tags elemeit rendezi azok map_x-e alapjan
rendezes(symbol_tags)
lw.WriteLine("----------------itt a vege------------------------")
Next
Else
'Hiba kezeles
Dim ex As String = "There is no drawing view"
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.[Error], ex)
Return Nothing
End If
End If
End Function
'symbol_tags arraylist elemeinek rendezese, azok map_x ertekei szerint novekvoben
Public Function rendezes(ByRef rend As ArrayList) As ArrayList
If rend.Count <> 0 Then
'Csak ellenorzesre, mennyi tomb elem van
lw.WriteLine("id_lista hossza: " & rend.Count)
' Tipusanak, altipusanak lekerdezese
'Dim type As Integer
'Dim subtype As Integer
'theUfSession.Obj.AskTypeAndSubtype(rend_elem, Type, subtype)
'lw.WriteLine(" Type: " & Type.ToString())
'lw.WriteLine(" Subtype: " & subtype.ToString())
Dim map_x As New ArrayList
Dim origin_x As New ArrayList
Dim rend_elem As NXOpen.Tag
For rend_c As Integer = 0 To rend.Count - 1
'String konvertálása Tag-ge
rend_elem = CType(rend.Item(rend_c), NXOpen.Tag)
Dim idcol As Annotations.IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
'Tag konvertalasa Nxobject-te
Dim ids As Annotations.IdSymbol = NXObjectManager.Get(rend_elem)
Dim idsb As Annotations.IdSymbolBuilder = idcol.CreateIdSymbolBuilder(ids)
lw.WriteLine(" Rend Text: " + idsb.UpperText) 'id_symbol szovege
lw.WriteLine(" Rend Origin: " & idsb.Origin.OriginPoint.ToString()) 'id_symbol (karika) kozepe
'lw.WriteLine(" Rend Size: " & idsb.Size) 'id_symbol (karika) merete
'Kozeppontokat beleteszi egy tombe, nincs ra szukseg
'origin_x.Add(idsb.Origin.OriginPoint.X.ToString())
Dim lb As Annotations.LeaderBuilder = idsb.Leader
Dim ldl As Annotations.LeaderDataList = lb.Leaders
Dim selection1 As DisplayableObject
Dim view1 As View
'Mutatovonal lekerdezese
For i As Integer = 0 To ldl.Length - 1
Dim ld As Annotations.LeaderData = ldl.FindItem(i)
Dim point1 As Point3d
ld.Leader.GetValue(selection1, view1, point1)
'lw.WriteLine(" Leader view: " & view1.Name) 'Nezet neve
lw.WriteLine("---Leader view tag: " & view1.Tag) 'Nezet tag-je
lw.WriteLine("Stub size: " & ld.StubSize.ToString()) 'Mutatovonal tulnyulasa
If (view1.GetType().ToString() <> "NXOpen.View") Then
Dim model_pt(2) As Double
model_pt(0) = point1.X
model_pt(1) = point1.Y
model_pt(2) = point1.Z
Dim map_pt(1) As Double
theUfSession.View.MapModelToDrawing(view1.Tag, model_pt, map_pt)
'Melyik pontra mutat a mutatovonal
lw.WriteLine(" Mapped Leader point: X=" & map_pt(0).ToString() & " ,Y= " & map_pt(1).ToString())
'A pontok x koordinatait teszi egy tombe, e szerint lesz majd a rendezes
map_x.Add(map_pt(0).ToString)
End If
Next
Next
'Csak ellenorzeskent, x koordinatak es hozzatartozo id_symbol tag-ek kiirasa
For mx As Integer = 0 To rend.Count - 1
lw.WriteLine("mx lista rendezesnel: " & map_x.Item(mx))
lw.WriteLine("rend lista rendezesnel: " & rend.Item(mx))
Next
lw.WriteLine("----------------")
'rendezes: mapped pontoke es a rend tombe
Dim v, vv As Integer
Dim temp, wtemp As Double
vv = 0
'temp = 0
For v = 0 To rend.Count - 2
For vv = v + 1 To rend.Count - 1
lw.WriteLine(vv & "----" & map_x.Item(v) & "---" & map_x.Item(vv))
If CDbl(map_x.Item(v)) > CDbl(map_x.Item(vv)) Then 'Ha nem CDbl, akkor nem rendez jól
'x koordinatak rendezese
temp = map_x.Item(v).ToString
map_x.Item(v) = map_x.Item(vv).ToString
map_x.Item(vv) = temp
'id_symbol tag-ek rendezese a fentivel parhuzamosan
wtemp = rend.Item(v).ToString
rend.Item(v) = rend.Item(vv).ToString
rend.Item(vv) = wtemp
End If
Next
Next
'Csak ellenorzesre, hogy mindket tombe megtortent a rendezes
For ww As Integer = 0 To rend.Count - 1
lw.WriteLine("--------------")
lw.WriteLine(map_x.Item(ww))
lw.WriteLine("rend lista: " & rend.Item(ww))
Next
lw.WriteLine("----------------")
'Szerettem volna nezet jobb oldala menten lefele is rendezni
'rendezes_plusz(rend)
'A berendezett id_symbolok nezet tetejere mozgatasa
mozgatas(rend)
Return rend
Else
'Hibakezeles
Dim ex As String = "There is no id symbol."
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.[Error], ex)
'MsgBox("na")
End If
End Function
'Szerettem volna nezet jobb oldala menten lefele is rendezni, most nem kel
Public Function rendezes_plusz(ByRef rend As ArrayList) As ArrayList
Dim map_x_p As New ArrayList
Dim origin_x_p As New ArrayList
Dim idsb_p_size As New ArrayList
Dim stub_size As New ArrayList
Dim rend_elem_p As NXOpen.Tag
For rend_c_p As Integer = 0 To rend.Count - 1
'String konvertálása Tag-ge
rend_elem_p = CType(rend.Item(rend_c_p), NXOpen.Tag)
Dim idcol As Annotations.IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
'Tag konvertalasa Nxobject-te
Dim ids As Annotations.IdSymbol = NXObjectManager.Get(rend_elem_p)
Dim idsb As Annotations.IdSymbolBuilder = idcol.CreateIdSymbolBuilder(ids)
lw.WriteLine(" Rend plusz Text: " + idsb.UpperText)
lw.WriteLine(" Rend plusz Origin: " & idsb.Origin.OriginPoint.ToString())
lw.WriteLine(" Rend plusz Size: " & idsb.Size)
origin_x_p.Add(idsb.Origin.OriginPoint.X.ToString())
idsb_p_size.Add(idsb.Size.ToString)
Dim lb As Annotations.LeaderBuilder = idsb.Leader
Dim ldl As Annotations.LeaderDataList = lb.Leaders
Dim selection1 As DisplayableObject
Dim view1 As View
For i As Integer = 0 To ldl.Length - 1
Dim ld As Annotations.LeaderData = ldl.FindItem(i)
Dim point1 As Point3d
ld.Leader.GetValue(selection1, view1, point1)
'lw.WriteLine(" Leader view: " & view1.Name)
lw.WriteLine("---Plusz Leader view tag: " & view1.Tag)
'lw.WriteLine("Stub size: " & ld.StubSize.ToString())
stub_size.Add(ld.StubSize.ToString)
If (view1.GetType().ToString() <> "NXOpen.View") Then
Dim model_pt_p(2) As Double
model_pt_p(0) = point1.X
model_pt_p(1) = point1.Y
model_pt_p(2) = point1.Z
Dim map_pt_p(1) As Double
theUfSession.View.MapModelToDrawing(view1.Tag, model_pt_p, map_pt_p)
lw.WriteLine(" Plusz Mapped Leader point: X=" & map_pt_p(0).ToString() & " ,Y= " & map_pt_p(1).ToString())
map_x_p.Add(map_pt_p(0).ToString)
End If
Next
Next
Dim csere As Double
Dim rend_c_p_w As Integer = 0
'While rend_c_p_w < rend.Count - 1
For rend_c_p As Integer = 0 To rend.Count - 2
lw.WriteLine("rend__p: " & rend_c_p)
If map_x_p.Item(rend_c_p + 1) < origin_x_p.Item(rend_c_p) + idsb_p_size.Item(rend_c_p) / 2 + stub_size.Item(rend_c_p) Then
lw.WriteLine("c_p_1: " & map_x_p.Item(rend_c_p + 1) & "--------" & "rend_c_p: " & map_x_p.Item(rend_c_p))
csere = rend.Item(rend_c_p + 1)
rend.Item(rend_c_p + 1) = rend.Item(rend_c_p)
rend.Item(rend_c_p) = csere
End If
Next
'End While
For ww As Integer = 0 To rend.Count - 1
lw.WriteLine("rend plusz lista: " & rend.Item(ww))
Next
mozgatas(rend)
End Function
'id_symbols mozgatasa nezetenek bal felso sarkatol x menten
Public Function mozgatas(ByRef rend As ArrayList)
'Csak ellenorzesre, hogy mi van a tombe
lw.WriteLine("id_lista hossza: " & rend.Count)
For ww As Integer = 0 To rend.Count - 1
lw.WriteLine("rend lista mozgatasnal: " & rend.Item(ww))
Next
Dim mozgat_elem As NXOpen.Tag
Dim koztes As Integer = 0
Dim parent_view As New ArrayList
Dim osszes_nezet As Integer = 0
Dim mozgat_c_y As Integer = 0
'Dim k As Integer = 0
lw.WriteLine("----------------")
For mozgat_c As Integer = 0 To rend.Count - 1
'String konvertálása Tag-ge
mozgat_elem = CType(rend.Item(mozgat_c), NXOpen.Tag)
lw.WriteLine("mozgatas_elem ctype_nal: " & "mozgat_elem: " & mozgat_elem & "mozgat_c: " & mozgat_c)
Dim idcol As Annotations.IdSymbolCollection = theSession.Parts.Work.Annotations.IdSymbols
'Tag konvertalasa Nxobject-te
Dim ids_m As Annotations.IdSymbol = NXObjectManager.Get(mozgat_elem)
Dim idsb_m As Annotations.IdSymbolBuilder = idcol.CreateIdSymbolBuilder(ids_m)
Dim lb As Annotations.LeaderBuilder = idsb_m.Leader
Dim ldl_m As Annotations.LeaderDataList = lb.Leaders
'lw.WriteLine(" Number of LeaderData: " + ldl.Length.ToString())
Dim selection1 As DisplayableObject
Dim view1 As View
Dim hatar(3) As Double
Dim meret_a As Double = 0
Dim id_meret As Double = 0
For i As Integer = 0 To ldl_m.Length - 1
Dim ld As Annotations.LeaderData = ldl_m.FindItem(i)
Dim point1 As Point3d
lw.WriteLine(ld.Leader.Tag)
ld.Leader.GetValue(selection1, view1, point1)
lw.WriteLine(" Leader view: " & view1.Name)
lw.WriteLine("---Leader view tag: " & view1.Tag)
'Rosszat olvas view scale-be, id meretet a scale aranyaban szerettem volna csokkenteni
'id_meret = idsb_m.Size
'lw.WriteLine("id_meret" & id_meret & "scale " & view1.Scale)
'meret_a = view1.Scale
'idsb_m.Size = id_meret * meret_a
'lw.WriteLine("id_size" & idsb_m.Size)
'view1.SetScale(1)
parent_view.Add(view1.Tag.ToString())
lw.WriteLine("parent_view tomb:" & parent_view.Count)
'rajz nezethataranak lekerdezese
theUfSession.Draw.AskViewBorders(view1.Tag, hatar)
' Erre a pontra igazítja az összeset kell a Commit, hogy végrehajtsa
Dim tav As Integer
tav = idsb_m.Size * 1.7
Dim ox As Point3d
ox.Z = 0
ox.X = hatar(0) + tav * mozgat_c
ox.Y = hatar(3) + idsb_m.Size / 2
idsb_m.Origin.Origin.SetValue(selection1, view1, ox)
If ld.StubSide.ToString() = "Left" Then
ld.StubSide = Annotations.LeaderSide.Right
End If
'Ami nem fér el a nezet felett, az menne a jobb oldalán lefelé
'If ox.X > idsb_m.Origin.OriginPoint.X.ToString() Then
'lw.WriteLine("y-ba" & ox.X & "--" & idsb_m.Origin.OriginPoint.X.ToString())
'ox.X = hatar(2) + idsb_m.Size / 3 * 4
'ox.Y = hatar(3) - idsb_m.Size * 1.2 * mozgat_c_y
'idsb_m.Origin.Origin.SetValue(selection1, view1, ox)
'lw.WriteLine("oy: " & ox.Y)
'mozgat_c_y = mozgat_c_y + 1
'If ld.StubSide.ToString() = "Right" Then
'ld.StubSide = Annotations.LeaderSide.Left
'End If
'End If
'lw.WriteLine("szoveg: " & idsb_m.UpperText)
'Ez kell, hogy mozgassa is
Dim nXObject1 As NXObject
nXObject1 = idsb_m.Commit()
idsb_m.Destroy()
lw.WriteLine("----------------")
Next
Next
Return 0
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'----Other unload options-------
'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module
Attila Szepesi
support engineer
graphIT Ltd.