.net语言 开发UG NX二次开发 NX12 (第五天)

1.定向转出dxf

  1 Imports NXOpen.UF
  2 
  3 Module NXJournal
  4     Sub Main(ByVal args() As String)
  5         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
  6         Dim workPart As NXOpen.Part = theSession.Parts.Work
  7         Dim TmpWorkViewName As String = workPart.ModelingViews.WorkView.Name
  8         Dim SavePath As String = Environ("USERPROFILE") & "\Desktop\" '把系统桌面路径设置为保存路径
  9         Dim tmpViewName As String = GetViewName()
 10         DxpDxf(tmpViewName, SavePath & GetFileName(".dxf"))
 11         ReworkView(TmpWorkViewName)
 12         DelView(tmpViewName)
 13 
 14     End Sub
 15     Function ReworkView(viewName As String)
 16         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
 17         Dim workPart As NXOpen.Part = theSession.Parts.Work
 18         Dim layout1 As NXOpen.Layout = CType(workPart.Layouts.FindObject("L1"), NXOpen.Layout)
 19 
 20         Dim modelingView1 As NXOpen.ModelingView = CType(workPart.ModelingViews.FindObject(viewName), NXOpen.ModelingView)
 21 
 22         layout1.ReplaceView(workPart.ModelingViews.WorkView, modelingView1, True)
 23     End Function
 24     Function GetViewName() As String
 25         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
 26         Dim workPart As NXOpen.Part = theSession.Parts.Work
 27         Dim displayPart As NXOpen.Part = theSession.Parts.Display
 28         Dim TmpViewName As String = SetTmpViewName()
 29         Dim view1 As NXOpen.View = Nothing
 30         view1 = workPart.Views.SaveAsPreservingCase(workPart.ModelingViews.WorkView, TmpViewName, True, False)
 31         Return TmpViewName
 32     End Function
 33     Function DelView(DelviewName As String)
 34 
 35 
 36         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
 37         Dim workPart As NXOpen.Part = theSession.Parts.Work
 38 
 39         Dim displayPart As NXOpen.Part = theSession.Parts.Display
 40 
 41         Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
 42         markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Delete")
 43 
 44         Dim notifyOnDelete1 As Boolean = Nothing
 45         notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
 46 
 47         theSession.UpdateManager.ClearErrorList()
 48 
 49         Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
 50         markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete")
 51 
 52         Dim objects1(0) As NXOpen.TaggedObject
 53         Dim modelingView1 As NXOpen.ModelingView = CType(workPart.ModelingViews.FindObject(DelviewName), NXOpen.ModelingView)
 54 
 55         objects1(0) = modelingView1
 56         Dim nErrs1 As Integer = Nothing
 57         nErrs1 = theSession.UpdateManager.AddObjectsToDeleteList(objects1)
 58 
 59         Dim notifyOnDelete2 As Boolean = Nothing
 60         notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
 61 
 62         Dim nErrs2 As Integer = Nothing
 63         nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
 64 
 65         theSession.DeleteUndoMark(markId1, Nothing)
 66 
 67         Return True
 68     End Function
 69     Function SetTmpViewName() As String
 70         Dim dt As Date = Now
 71         Return "tmp" & Format(dt, "_mmss")
 72     End Function
 73     Function DxpDxf(ViewName As String, OutputFile1 As String) As String
 74         Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
 75         Dim workPart As NXOpen.Part = theSession.Parts.Work
 76         Dim displayPart As NXOpen.Part = theSession.Parts.Display
 77         Dim dxfdwgCreator1 As NXOpen.DxfdwgCreator = Nothing
 78         Dim UFS As UFSession = UFSession.GetUFSession()
 79         Dim InputFile1 As String = ""
 80         UFS.Part.AskPartName(UFS.Part.AskDisplayPart(), InputFile1)    '获取当前路径
 81         dxfdwgCreator1 = theSession.DexManager.CreateDxfdwgCreator()
 82         dxfdwgCreator1.ExportData = NXOpen.DxfdwgCreator.ExportDataOption.Drawing
 83         dxfdwgCreator1.AutoCADRevision = NXOpen.DxfdwgCreator.AutoCADRevisionOptions.R2004
 84         dxfdwgCreator1.ViewEditMode = True
 85         dxfdwgCreator1.FlattenAssembly = True
 86         dxfdwgCreator1.ExportScaleValue = "1:1"
 87         dxfdwgCreator1.OutputFile = OutputFile1
 88         dxfdwgCreator1.ExportData = NXOpen.DxfdwgCreator.ExportDataOption.Modeling
 89         dxfdwgCreator1.FlattenAssembly = False
 90         dxfdwgCreator1.OverlappingEntities = True
 91         dxfdwgCreator1.InputFile = InputFile1
 92         dxfdwgCreator1.WidthFactorMode = NXOpen.DxfdwgCreator.WidthfactorMethodOptions.AutomaticCalculation
 93         dxfdwgCreator1.LayerMask = "1-256"
 94         dxfdwgCreator1.ViewList = ViewName
 95 
 96         Dim nXObject2 As NXOpen.NXObject = Nothing
 97         nXObject2 = dxfdwgCreator1.Commit()
 98         workPart = theSession.Parts.Work ' _model3
 99         displayPart = theSession.Parts.Display ' _model3
100         dxfdwgCreator1.Destroy()
101         Return ViewName
102     End Function
103     Function GetFileName(suffix As String) As String '
104         Dim tmpOutputFileName As String = ""
105         Dim UFS As UFSession = UFSession.GetUFSession()
106         Dim tmpInputFile As String = ""
107         UFS.Part.AskPartName(UFS.Part.AskDisplayPart(), tmpInputFile)    '获取当前路径
108         tmpOutputFileName = tmpInputFile.Replace(".prt", "")
109         tmpOutputFileName = Mid(tmpOutputFileName, InStrRev(tmpOutputFileName, "\") + 1, Len(tmpOutputFileName)) '截取文件名
110         Dim dt As Date
111         dt = Now '获取当前日期
112         tmpOutputFileName += Format(dt, "_mmss") & suffix
113         Return tmpOutputFileName
114     End Function
115 End Module

 

posted @ 2021-10-07 15:47  KingMAX(没事杀杀毒)  阅读(441)  评论(0)    收藏  举报