I am getting few issues on running the below code, I want to export large assemblies out of TcE with the coordinates. I am using NX 7.5 an TcE 9.1.
I am getting
1. the memory access violation error
2. System handling error "Exception c0000005 occurred in unmanaged code".
(For this I added Do loop as suggested in previous post (Not tested yet))
3. Few of My lower level parts are corrupted, This causes the loading problem which will end up in High memory consumption and I need to force close the UG. Is there any possibility to skip that part. Which exception will catch such issues?
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Windows.Forms
Imports NXOpen.Annotations
Imports NXOpen.Utilities
Imports System.Collections.Generic
Imports NXOpen.UF.UFDraw
Imports NXOpen.Drawings
Module Stepexport
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI
Dim ufs As UFSession = UFSession.GetUFSession
Sub Main(ByVal args() As String)
Dim myPart As Part = Nothing
Dim lw As ListingWindow = theSession.ListingWindow
Dim PartNo As String = Nothing
lw.Open()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Open a Part")
theSession.SetUndoMarkName(markId1, "Open a Part")
PartNo = InputBox("Please enter the part No /Part rev to open", "Open Part", PartNo)
Dim Filename As String = Left(PartNo, 8)
theSession.Parts.SetNonmasterSeedPartData("@DB/" & PartNo)
Dim basePart1 As BasePart = Nothing
Try
Dim partLoadStatus1 As PartLoadStatus = Nothing
basePart1 = theSession.Parts.Open("@DB/" & PartNo, partLoadStatus1)
partLoadStatus1.Dispose()
Dim partLoadStatus2 As PartLoadStatus = Nothing
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(basePart1, False, True, partLoadStatus2)
partLoadStatus2.Dispose()
Catch exc As NXException
lw.WriteLine("NX Exception" & exc.Message)
Catch exc1 As AccessViolationException
lw.WriteLine("Access Violation" & exc1.Message)
Catch exc2 As ArgumentNullException
lw.WriteLine("NullException" & exc2.Message)
Catch exc3 As ArgumentOutOfRangeException
lw.WriteLine("Outof range" & exc3.Message)
End Try
Dim stepExportFileName As String = Environ("USERPROFILE") & "\Desktop\" & Filename & ".stp"
Dim step214Creator1 As Step214Creator
Do
step214Creator1 = theSession.DexManager.CreateStep214Creator()
With step214Creator1
.ExportFrom = Step214Creator.ExportFromOption.DisplayPart
.SettingsFile = "C:\apps\nx075\step214ug\ugstep214.def"
.ObjectTypes.Curves = False
.ObjectTypes.Surfaces = False
.ObjectTypes.Solids = True
.ObjectTypes.Csys = True
.ObjectTypes.ProductData = False
.ObjectTypes.Annotations = False
.ObjectTypes.Structures = False
.InputFile = "@DB/" & PartNo
.OutputFile = stepExportFileName
.FileSaveFlag = False
.BsplineTol = 0.001
.LayerMask = "1-256"
End With
Dim nXObject1 As NXObject
nXObject1 = step214Creator1.Commit()
Loop
step214Creator1.Destroy()
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
workPart = Nothing
displayPart = Nothing
End Sub
End Module
re: corrupt parts
I would suggest fixing the corrupt parts, or testing your code on a small assembly with known good parts. Get the code working with good parts first, then add error handling code for corrupt parts later.
Good parts
With good parts it is working fine. I tested in small assembly and it is giving me the output.
Regards,
Joe
re: corrupt parts
Do the corrupt parts give any errors when you open them?
If the parts open OK, there may be an error in the geometry of the part. Use "examine geometry" to find the error(s). It usually only takes some minor editing or reordering to eliminate the errors.
Corrupt parts
When the parts are corrupted I cant able to open the model. It will trough NXpav.xml error or Null tag error when I open normally from TcE. Most of my Assemblies will have more than 10,000 parts including hardware.
Regards,
Joe
re: corrupt parts
You should consider sending the corrupt parts to GTAC. They may have tools available to repair your parts.
Also, I see in your code that you try to open a part then set it as the display part. The NXOpen API offers the methods: OpenDisplay and OpenBaseDisplay that will open a part and set it as the display part in a single command. Using one of these methods may help to simplify your code a little.