Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Parasolid export version

Status
Not open for further replies.

MCADTrans

Mechanical
Jun 26, 2007
19
0
0
US
Is it possible in NX9 to set a default parasolid export version?
I see customer defaults for everything except parasolid.
I am exporting parasolids quite often using an earlier version due to the capabilities of the software I am importing it in to.

Thanks,
Bart
 
Replies continue below

Recommended for you

Thank You.

I try this to be sure, if something is selected but I get an error:
Code:
	lw.open
	For each tempBody as Body in workpart.Bodies
 	   if tempBody.Layer = 1 then
 	       theBodies.Add(tempBody)
 	   end if
	Next 

        For Each temp As Body In theBodies  
            lw.WriteLine(temp.Tag.ToString)  
        Next

37441
*** ERROR ***
650004 : Incorrect object for this operation.


With best regards
Michael
 
The .net exception mechanism always reports the line(s) of code in which an unhandled error occurs. It would be helpful if you could clearly indicate which line of code was reported. Perhaps highlight the posted line of code in which the error occurred.

Also, it would be helpful to know how "theBodies" and "workPart" are defined in your code.

www.nxjournaling.com
 
This is error from listing window, so there wasn't any line no. It appears when I uncomment lw.writeline(temp.Tag.ToString).
Below is actual code:
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
 
Module NXJournal
    Sub Main()
 
       Dim theSession As Session = Session.GetSession()
       Dim ufs As UFSession = UFSession.GetUFSession()
       Dim workPart As Part = theSession.Parts.Work
       Dim displayPart As Part = theSession.Parts.Display
       Dim lw As ListingWindow = theSession.ListingWindow
     

'       Dim tagList() As NXOpen.Tag
       Dim exportFileName As String = Nothing
       Dim exportFileName1 As String = Nothing
       Dim nazwa as string
       Dim path As String 
       Dim PSversion as integer = 240
       Dim layerNumber as Integer = 1	
       Dim i As Integer = 0
       Dim theBodies As New List(Of Body) 
       Dim inx As Integer = 0

	lw.open

	For each tempBody as Body in workpart.Bodies
 	   if tempBody.Layer = 1 then
 	       theBodies.Add(tempBody)
 	   end if
	Next 

'        For Each temp As Body In theBodies  
'            lw.WriteLine(temp.Tag.ToString)  
'        Next 

    Dim bodyCount As Integer = thebodies.ToArray.Length
    Dim tagList(bodyCount - 1) As NXOpen.Tag

    Do
        tagList(inx) = workPart.Bodies.ToArray(inx).Tag
        inx = inx + 1

    Loop Until inx = bodyCount

'       ReDim tagList(thebodies.GetUpperBound(0))
'       For i = 0 To thebodies.GetUpperBound(0)
'           tagList(i) = thebodies(i).Tag
'       next

'*****************************************************************************************************************
       exportFileName = workPart.FullPath
       nazwa = workPart.Leaf
      
       path = IO.Path.Combine(IO.Path.GetDirectoryName(workPart.FullPath), "step")

	If(Not System.IO.Directory.Exists(Path)) Then
    		System.IO.Directory.CreateDirectory(Path)
	End If

	exportFileName = IO.Path.Combine(path, nazwa & ".x_t") 
	
       'if this file already exists, delete it
       If My.Computer.FileSystem.FileExists(exportFileName) Then
           My.Computer.FileSystem.DeleteFile(exportFileName)
       End If
        Dim numUnexported As Integer
       Try
       ufs.Ps.ExportLinkedData(Taglist, Taglist.Length, exportFileName, PSversion, Nothing, numUnexported, Nothing)
       Catch ex As NXException
           lw.WriteLine("*** ERROR ***")
           lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
       End Try
        lw.Close()
     End Sub
 End Module
It's working but not I desired. It's generating parasolid, but when I open It in NX I only see body from layer 99 (reference set "FALSE").
When I add another body on layer 1, then in imported parasolid I have assembly with 2 parts, one with false, and second with true (first body). I think the code which respond for taglist is broken.
I commented "Redim (..)" from the first code, because I received an error:
"Element '.GetUpperBound' is not the member of element 'system.collections.generic.list(of NXOpen.Body)' "

With best regards
Michael
 
If the error message shows up in the listing window (and not in a .net error message box) then it must be coming from this portion of your code:
Code:
Try
    ufs.Ps.ExportLinkedData(tagList, tagList.Length, exportFileName, PSversion, Nothing, numUnexported, Nothing)
Catch ex As NXException
    lw.WriteLine("*** ERROR ***")
    lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
End Try

The error is caught and handled in your code. The error occurs in the .ExportLinkedData function and your code responds by writing the error message to the listing window. The fact that the error occurred after you uncommented the "lw.writeline" code is most likely just coincidental.

Ultimately, the .ExportLinkedData function needs an array of body tags. Your code to retrieve the body tags is problematic. It ignores the bodies that you have found on layer 1 (if any) and indiscriminately uses the first n bodies that it finds in the body collection. Since we only need the body tags and not the bodies themselves, we can dispense with the list of Bodies and use a list of Tags instead.

Code:
Dim theBodyTags as New List(Of Tag)

For Each tempBody As Body In workPart.Bodies
    If tempBody.Layer = 1 Then
        theBodyTags.Add(tempBody.Tag)
    End If
Next

lw.WriteLine("number of bodies found: " & theBodyTags.Count.ToString)

if theBodyTags.Count = 0 then
    'no bodies to export
    return
end if

Then in the .ExportLinkedData function, we can use:
Code:
ufs.Ps.ExportLinkedData(theBodyTags.ToArray, theBodyTags.Count, exportFileName, PSversion, Nothing, numUnexported, Nothing)



p.s. Don't run this code in an assembly file; it won't run as you expect. First get it working in a part file.

www.nxjournaling.com
 
Thanks Cowski, You are Great, now it's wok perfect. Now I start with whole assembly journal.

I wish I could know VB like You know. I bought book "Beginning Visual Basic 2005" Thearon Wills, but I haven't much time to study it.

With best regards
Michael
 
Ok, here is my code, maybe it will be useful to someone else in the future:
Code:
'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012
 
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow


    Sub Main()

    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    lw.Open
    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

            ReportComponentChildren(c.RootComponent, 0)
        else

            lw.WriteLine("Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    lw.Close
 
    End Sub
 
'**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, _
        ByVal indent As Integer)

	Dim dispPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow

       Dim tagList() As NXOpen.Tag
       Dim exportFileName As String = Nothing
       Dim exportFileName1 As String = Nothing
       Dim nazwa as string
       Dim path As String 
       Dim PSversion as integer = 240
       Dim layerNumber as Integer = 1	
       Dim i As Integer = 0
       Dim theBodies As New List(Of Body) 
       Dim inx As Integer = 0
       Dim theBodyTags as New List(Of Tag)

	
        For Each child As Component In comp.GetChildren()
	
             If LoadComponent(child) Then

		Dim MyPart As Part = child.Prototype.OwningPart 

	lw.open

	theBodyTags.clear()

	For each tempBody as Body in mypart.Bodies
 	  if tempBody.Layer = 1 then
 	       theBodytags.Add(tempBody.tag)
	   end if
	Next 

 

'	lw.WriteLine("number of bodies found: " & theBodyTags.Count.ToString)


	if theBodyTags.Count = 0 then
	    lw.writeline("no bodies to export")
	    return
	end if 
    
	exportFileName = myPart.FullPath
        nazwa = myPart.Leaf
      
       path = IO.Path.Combine(IO.Path.GetDirectoryName(myPart.FullPath), "step")


	If(Not System.IO.Directory.Exists(Path)) Then
    		System.IO.Directory.CreateDirectory(Path)
	End If

	exportFileName = IO.Path.Combine(path, nazwa & ".x_t") 
	

       'if this file already exists, delete it
       If My.Computer.FileSystem.FileExists(exportFileName) Then
           My.Computer.FileSystem.DeleteFile(exportFileName)
       End If
 
       Dim numUnexported As Integer

       Try

       ufs.Ps.ExportLinkedData(theBodyTags.ToArray, theBodyTags.Count, exportFileName, PSversion, Nothing, 

numUnexported, Nothing) 

       Catch ex As NXException
           lw.WriteLine("*** ERROR ***")
           lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
       End Try
 
       lw.Close()
 	 		
		
  	            Else

                'component could not be loaded

            End If

            reportComponentChildren(child, indent + 1)
        Next
    End Sub

    Private Function LoadComponent(ByVal theComponent As Component) As Boolean
 
        Dim thePart As Part = theComponent.Prototype.OwningPart
 
        Dim partName As String = ""
        Dim refsetName As String = ""
        Dim instanceName As String = ""
        Dim origin(2) As Double
        Dim csysMatrix(8) As Double
        Dim transform(3, 3) As Double
 
        Try
            If thePart.IsFullyLoaded Then
                'component is fully loaded
            Else
                'component is partially loaded
            End If
            Return True
        Catch ex As NullReferenceException
            'component is not loaded
            Try
                ufs.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, 

csysMatrix, transform)
 
                Dim theLoadStatus As PartLoadStatus
                theSession.Parts.Open(partName, theLoadStatus)
 
                If theLoadStatus.NumberUnloadedParts > 0 Then
 
                    Dim allReadOnly As Boolean = True
                    For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1
                        If theLoadStatus.GetStatus(i) = 641058 Then
                            'read-only warning, file loaded ok
                        Else
                            '641044: file not found
                            lw.WriteLine("file not found")
                            allReadOnly = False
                        End If
                    Next
                    If allReadOnly Then
                        Return True
                    Else
                        'warnings other than read-only...
                        Return False
                    End If
                Else
                    Return True
                End If
 
            Catch ex2 As NXException
                lw.WriteLine("error: " & ex2.Message)
                Return False
            End Try
        Catch ex As NXException
            'unexpected error
            lw.WriteLine("error: " & ex.Message)
            Return False
        End Try
 
    End Function

'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************
 
End Module


With best regards
Michael
 
Status
Not open for further replies.
Back
Top