' Programm: ' Erstellt von : Mk223 ' Datum: ' Änderungen: Option Strict Off Imports System Imports NXOpen Imports NXOpen.UI Imports NXOpen.Utilities Imports NXOpen.Assemblies Imports NXOpen.Drawings Imports NXOpen.UF Module MK_ApiDrawing_objects_test Dim mView As DraftingView = Nothing Dim obj() As Tag Dim s As Session = Session.GetSession() Dim lw As ListingWindow = s.ListingWindow Dim wP As Part = s.Parts.Work Dim dp As Part = s.Parts.Display Dim theUI As UI = UI.GetUI() Dim ufs As UFSession = UFSession.GetUFSession() Dim edge As Edge = Nothing Dim nxobj As New Collections.Generic.Stack(Of NXObject) Sub Main() lw.Open() 'While select_an_edge_in_view("Select an edge", edge) = Selection.Response.Ok ' Dim v1, v2 As Point3d ' edge.GetVertices(v1, v2) ' lw.WriteLine("Selected edge: " & edge.ToString()) ' lw.WriteLine(" V1: " & v1.ToString()) ' lw.WriteLine(" V2: " & v2.ToString()) ' Dim vw As DraftingView ' If select_a_drawing_member_view(vw) = Selection.Response.Ok Then ' Dim pt1 As Double() = {v1.X, v1.Y, v1.Z} ' map_model_to_view(pt1, vw) ' lw.WriteLine(" Mapped X1: " & (pt1(0)).ToString()) ' lw.WriteLine(" Mapped Y1: " & (pt1(1)).ToString()) ' Dim pt2 As Double() = {v2.X, v2.Y, v2.Z} ' map_model_to_view(pt2, vw) ' lw.WriteLine(" Mapped X2: " & (pt2(0)).ToString()) ' lw.WriteLine(" Mapped Y2: " & (pt2(1)).ToString()) ' End If 'End While 'cycle_all() 'Dim c As Integer = 1 'For Each ojb As Object In nxobj ' Try ' Dim disob As DisplayableObject = ojb ' If disob.IsBlanked = False And disob.LineFont = DisplayableObject.ObjectFont.Solid Then ' lw.WriteLine(Str(c) & ". " & ojb.ToString) ' c = c + 1 ' disob.Highlight() ' End If ' Catch ex As Exception ' lw.WriteLine(ex.Message) ' End Try 'Next 'Dim c As Integer = 0 'Try ' For Each dwg As DrawingSheet In s.Parts.Display.DrawingSheets ' Dim viewtags() As NXOpen.Tag ' Dim numvies As Integer = 0 ' ufs.Draw.AskViews(dwg.Tag, numvies, viewtags) ' Next 'Catch ex As Exception 'End Try 'select_a_view("Select View", mView) 'Dim viewtag As Tag = mView.Tag 'Dim objcout As Integer = 0 'Try ' ufs.Draw.AskDisplayedObjects(viewtag, objcout, obj) 'Catch ex As Exception ' lw.Open() ' lw.WriteLine(ex.Message) 'End Try Dim mysheet As Drawings.DrawingSheet = Nothing mysheet = wP.DrawingSheets.CurrentDrawingSheet Dim c As Integer = 1 Dim allviews() As DraftingView = Nothing allviews = mysheet.GetDraftingViews For Each view As DraftingView In allviews mView = view mView.Expand() Try Dim visob As Integer = 0 Dim clippedinteg As Integer = 0 Dim visobtag() As NXOpen.Tag Dim clipobtag() As NXOpen.Tag ufs.View.AskVisibleObjects(mView.Tag, visob, visobtag, clippedinteg, clipobtag) For Each ojb As Tag In visobtag Try Dim disob As DisplayableObject = NXObjectManager.Get(ojb) Dim myobj As Object = disob If Not nxobj.Contains(myobj) Then If myobj.ToString.Contains("Component") Or myobj.ToString.Contains("Body") Or myobj.ToString.Contains("Face") Then Else lw.WriteLine(Str(c) & ". " & myobj.ToString) nxobj.Push(myobj) c = c + 1 disob.Highlight() End If End If Catch ex As Exception lw.WriteLine(ex.Message) End Try Next For Each clob As Tag In clipobtag Try Dim disob As DisplayableObject = NXObjectManager.Get(clob) 'lw.WriteLine(Str(c) & ". " & clob.ToString) Dim myobj As Object = disob If Not nxobj.Contains(myobj) Then If myobj.ToString.Contains("Component") Or myobj.ToString.Contains("Body") Or myobj.ToString.Contains("Face") Then Else lw.WriteLine(Str(c) & ". " & myobj.ToString) nxobj.Push(myobj) c = c + 1 disob.Highlight() End If End If Catch ex As Exception lw.WriteLine(ex.Message) End Try Next Catch ex As Exception lw.WriteLine(ex.Message) End Try Dim msg As String Dim title As String Dim style As MsgBoxStyle Dim response As MsgBoxResult msg = "OK?" ' Define message. style = MsgBoxStyle.YesNo title = " - " ' Define title. ' Display the dialog for the user response = MsgBox(msg, style, title) If response = MsgBoxResult.Yes Then Dim pcup As PartCleanup pcup = s.NewPartCleanup() pcup.TurnOffHighlighting = True pcup.PartsToCleanup = PartCleanup.CleanupParts.Work pcup.DoCleanup() pcup.Dispose() For Each obj As Object In nxobj If obj.ToString.Contains("Line") Then Dim myline As Line = CType(obj, Line) Dim laenge As Double = myline.GetLength Dim startpunkt As Point3d = myline.StartPoint Dim endpunkt As Point3d = myline.EndPoint lw.WriteLine(obj.ToString & " - " & laenge.ToString & " - " & "Start: " & startpunkt.ToString & " Endpunkt: " & endpunkt.ToString) lw.WriteLine("") Dim lstp(2) As Double lstp(0) = startpunkt.X + 0.1 lstp(1) = startpunkt.Y + 0.1 lstp(2) = startpunkt.Z + 0.1 Dim lendp(2) As Double lendp(0) = endpunkt.X + 0.1 lendp(1) = endpunkt.Y + 0.1 lendp(2) = endpunkt.Z + 0.1 create_line(lstp, lendp) End If If obj.ToString.Contains("Arc") Then Dim myarc As Arc = CType(obj, Arc) Dim centerpoint As Point3d = myarc.CenterPoint Dim Radius As Double = myarc.Radius Dim startangle As Double = myarc.StartAngle Dim endangle As Double = myarc.EndAngle Dim rotationangel As Double = myarc.RotationAngle lw.WriteLine(obj.ToString & " - " & "Radius: " & Radius.ToString & " - " & "Mitte: " & centerpoint.ToString & " Startwinkel: " & startangle.ToString & " Endwinkel: " & endangle.ToString & " Rotwinkel: " & rotationangel.ToString) lw.WriteLine("") Dim cp(2) As Double cp(0) = centerpoint.X + 0.1 cp(1) = centerpoint.Y + 0.1 cp(2) = centerpoint.Z + 0.1 create_arc(cp, Radius + 0.1, startangle, endangle) End If Next wP.Views.UnexpandWork() Else wP.Views.UnexpandWork() 'create_line() End If Next 'select_a_view("Select View", mView) End Sub Sub create_line(ByRef sp() As Double, ByRef ep() As Double) Dim uf_lin As UFCurve.Line 'Dim sp() As Double = {10, 0, 0} 'Dim ep() As Double = {10, 100, 0} uf_lin.start_point = sp uf_lin.end_point = ep Dim line_tag As Tag ufs.Curve.CreateLine(uf_lin, line_tag) ufs.Obj.SetName(line_tag, "prj_lin") ufs.Obj.SetColor(line_tag, 1) ufs.Obj.SetLineWidth(line_tag, 0.25) End Sub Sub create_arc(ByRef ac() As Double, ByRef r As Double, ByRef sa As Double, ByRef ea As Double) Try Dim uf_arc As UFCurve.Arc uf_arc.arc_center = ac uf_arc.radius = r uf_arc.start_angle = sa uf_arc.end_angle = ea Dim arc_tag As Tag ufs.Curve.CreateArc(uf_arc, arc_tag) ufs.Obj.SetName(arc_tag, "prj_lin") ufs.Obj.SetColor(arc_tag, 1) ufs.Obj.SetLineWidth(arc_tag, 0.25) Catch ex As Exception lw.WriteLine(ex.Message) End Try End Sub Private Sub cycle_all() Dim nx_tag As Tag = NXOpen.Tag.Null Dim cnt As Integer Dim objstr As String = "" lw.WriteLine("------ Objects in Work Part ------") Do cnt += 1 nx_tag = ufs.Obj.CycleAll(wp.Tag, nx_tag) If Not nx_tag = NXOpen.Tag.Null Then Try lw.WriteLine("object " & cnt & " " & NXObjectManager.Get(nx_tag).ToString) objstr = NXObjectManager.Get(nx_tag).ToString If objstr.Contains("Line") Then nxobj.Push(NXObjectManager.Get(nx_tag)) ElseIf objstr.Contains("Arc") Then nxobj.Push(NXObjectManager.Get(nx_tag)) ElseIf objstr.Contains("Spline") Then nxobj.Push(NXObjectManager.Get(nx_tag)) ElseIf objstr.Contains("Ellipse") Then nxobj.Push(NXObjectManager.Get(nx_tag)) End If Catch ex As Exception lw.WriteLine(ex.Message) End Try End If Loop Until nx_tag = NXOpen.Tag.Null lw.WriteLine("------ End of Listing ------") End Sub Function map_model_to_view(ByRef pt As Double(), ByVal vw As View) ' Inputs: ' pt(2) As Double -> x/y/z ' vw As View -> Drafting member view Dim theUFSession As UFSession = UFSession.GetUFSession() Dim vwname As String = vw.Name Dim vm As Matrix3x3 = vw.Matrix lw.WriteLine(" vw.Matrix: " & vw.Matrix.ToString()) Dim ref_csys As Double() = {0, 0, 0, 1, 0, 0, 0, 1, 0} Dim dest_csys As Double() = {0, 0, 0, vm.Xx, vm.Xy, vm.Xz, vm.Yx, vm.Yy, vm.Yz} Dim mx(11) As Double Dim status As Integer theUFSession.Trns.CreateCsysMappingMatrix(ref_csys, dest_csys, mx, status) theUFSession.Trns.MapPosition(pt, mx) End Function Function select_an_edge_in_view(ByVal prompt As String, ByRef obj As Edge) Dim ui As UI = GetUI() Dim mask(0) As Selection.MaskTriple With mask(0) .Type = UFConstants.UF_solid_type .Subtype = UFConstants.UF_solid_body_subtype .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_EDGE End With Dim cursor As Point3d = Nothing Dim ufs As UFSession = UFSession.GetUFSession() ufs.Ui.SetCursorView(0) Dim resp As Selection.Response = _ ui.SelectionManager.SelectObject(prompt, prompt, _ Selection.SelectionScope.AnyInAssembly, _ Selection.SelectionAction.ClearAndEnableSpecific, _ False, False, mask, obj, cursor) If resp = Selection.Response.ObjectSelected Or _ resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Function select_a_drawing_member_view(ByRef vw As View) Dim ui As UI = GetUI() Dim mask(0) As Selection.MaskTriple With mask(0) .Type = UFConstants.UF_view_type .Subtype = UFConstants.UF_view_imported_subtype .SolidBodySubtype = 0 End With Dim cursor As Point3d = Nothing Dim resp As Selection.Response = _ ui.SelectionManager.SelectObject("Select a drawing member view", _ "Select a drawing member view", _ Selection.SelectionScope.AnyInAssembly, _ Selection.SelectionAction.ClearAndEnableSpecific, _ False, False, mask, vw, cursor) If resp = Selection.Response.ObjectSelected Or _ resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Function select_a_view(ByVal Prompt As String, ByRef selview As View) As Selection.Response Dim theUI As UI = UI.GetUI Dim cursor As Point3d Dim mask(0) As Selection.MaskTriple With mask(0) .Type = UFConstants.UF_view_type .Subtype = 0 .SolidBodySubtype = 0 End With Dim resp As Selection.Response = _ theUI.SelectionManager.SelectObject( _ "Select a View", Prompt, _ Selection.SelectionScope.AnyInAssembly, _ Selection.SelectionAction.ClearAndEnableSpecific, _ False, False, mask, selview, cursor) If resp = Selection.Response.ObjectSelected Or _ resp = Selection.Response.ObjectSelectedByName Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If 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