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

No, there is no way to preset the default version on an exported Parasolid file. Perhaps a journal or macro could be written to take care of that.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Hello everyone.

I have similar problem with NX 9. Not every software can read parasolid from NX 9or above. Sometimes there is also need to import something to earlier version of NX. So I wanna use this function:

Code:
 ufs.Ps.ExportLinkedData(taglist, n_tags, exportFileName, 240, link_fnc , n_unexported, unexported_tags)

but I don't now what use for:
[ul]
[li]n_tags[/li]
[li]link_fnc[/li]
[li]n_unexported[/li]
[li]unexported_tags [/li]
[/ul]

When I use 0 I receive an error. I using modified code from this site:Link

anyone can help me solve this problem?

With best regards
Michael
 
[ul]
[li]n_tags = the number of items in the tag list[/li]
[li]link_fnc = Nothing (VB) or Null (C#)[/li]
[li]n_unexported = declare a variable of type integer and pass it in, the function will use it as output[/li]
[li]unexported_tags = Nothing (or Null) if you do not need error info, otherwise pass in an array of UF_PS_unexported_t structures (the function will use the array as output)[/li]
[/ul]


Below is a simplified version of a subroutine that I use.

Code:
    Sub PsExport(ByVal theBodies As List(Of Body), ByVal PsVersion As Integer, ByVal exportFileName As String)

        'parasolid export
        Dim exportTags(theBodies.Count - 1) As NXOpen.Tag
        For i As Integer = 0 To theBodies.Count - 1
            exportTags(i) = theBodies.Item(i).Tag
        Next

        Dim numUnexported As Integer

        Try
            theUfSession.Ps.ExportLinkedData(exportTags, exportTags.Length, exportFileName, PsVersion, Nothing, numUnexported, Nothing)

        Catch ex As NXException
            MsgBox(ex.Message)

        End Try

    End Sub

www.nxjournaling.com
 
Thank Cowski for Your support. I have adopted Your code but it doesn't create the parasolid file. Below is my updated code.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports Microsoft.VisualBasic
 
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 mySelectedObjects() As NXObject
       Dim myResponse As Selection.Response
 
       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 i As Integer = 0
 
       lw.Open()
       myResponse = SelectObjects(mySelectedObjects)
       If (myResponse = Selection.Response.Cancel) OrElse (myResponse = Selection.Response.Back) Then
           'user canceled selection, exit journal
           Exit Sub
       End If
 
       ReDim tagList(mySelectedObjects.GetUpperBound(0))
       For i = 0 To mySelectedObjects.GetUpperBound(0)
           tagList(i) = mySelectedObjects(i).Tag
       Next
 
       'return the full path of the work part

       exportFileName = workPart.FullPath
       nazwa = workPart.Leaf
      
        exportFileName = exportFileName.Remove(exportFileName.Length - (workPart.Leaf.length + 4))

	path = exportfilename + "step"

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

        exportFileName = "step\" + nazwa + ".x_t"

	'msgbox(exportFileName)

       '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.ExportData(tagList, exportFileName)
	   ufs.Ps.ExportLinkedData(Taglist, Taglist.Length, exportFileName, 220, Nothing, numUnexported, Nothing)

       Catch ex As NXException
           lw.WriteLine("*** ERROR ***")
           lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
       End Try
 
       lw.Close()
 
    End Sub
 
   Function SelectObjects(ByRef selobj() As NXObject) As Selection.Response
 
       Dim theUI As UI = UI.GetUI
       Dim prompt as String = "Select Solid Bodies"
       Dim title As String = "Selection"
       Dim includeFeatures As Boolean = False
       Dim keepHighlighted As Boolean = False
       Dim selAction As Selection.SelectionAction = _
           Selection.SelectionAction.ClearAndEnableSpecific
 
       Dim scope As Selection.SelectionScope = _
           Selection.SelectionScope.AnyInAssembly
       Dim selectionMask_array(0) As Selection.MaskTriple
 
       With selectionMask_array(0)
           .Type = UFConstants.UF_solid_type
           .Subtype = 0
           .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
       End With
 
       Dim resp As Selection.Response = _
           theUI.SelectionManager.SelectObjects( _
           prompt, title, scope, selAction, _
            includeFeatures, keepHighlighted, _
            selectionMask_array, selobj)
 
       Return resp
 
   End Function
 
End Module

It create the folder but nothing else. Do You have any suggestions?


With best regards
Michael
 
Code:
    exportFileName = exportFileName.Remove(exportFileName.Length - (workPart.Leaf.length + 4))

	path = exportfilename + "step"

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

    exportFileName = "step\" + nazwa + ".x_t"

The "path" variable is created from "exportFileName", but then most of the directory information is removed from "exportFileName" before the export happens. If you are not getting any error messages from the code, I'd assume that the files are being exported, just not to the location that you expect.

Perhaps something like this would work:
Code:
	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")

www.nxjournaling.com
 
Thanks Cowski, Your code work perfect. I looked for error in function not in my code. I looked in my code once more and I think used older version of my code, where export of parasolid was not solved yet.
I'm thinking to write journal which will process whole assembly and in each part select all solid bodies on layer 1 and then export this part to parasolid. Have You ever tried \thought about it?


With best regards
Michael
 
I have made some changes in code, but I receive an error. I think the problem is with taglist.
I changed:

Code:
  myResponse = SelectObjects(mySelectedObjects)
       If (myResponse = Selection.Response.Cancel) OrElse (myResponse = Selection.Response.Back) Then
           'user canceled selection, exit journal
           Exit Sub
       End If
 
       ReDim tagList(mySelectedObjects.GetUpperBound(0))
       For i = 0 To mySelectedObjects.GetUpperBound(0)
           tagList(i) = mySelectedObjects(i).Tag
       Next

To:

Code:
       allObjects = workPart.Layers.GetAllObjectsOnLayer(1)
	 for each someObject as NXObject in allObjects
	    if someObject.GetType.ToString = "NXOpen.BODY" then
  		redim preserve taglist(i)
                i += 1
   	 end if
        Next

Do You have any suggestions?


With best regards
Michael
 
niedzviedz said:
I have made some changes in code, but I receive an error.

It always helps to know the nature of the error. Is a specific error code/message returned or is the code just not doing what you expect it to?

In the code that you posted, it doesn't look like the body tag is added to the array. If this is the case, I'd expect nothing gets exported...

To make the programming easier, I'd suggest using a list object in this case. It would avoid the "redim preserve" calls and eliminate the need for the element counter variable "i". The list .Add method will handle resizing the list for you and you can use the .ToArray method when you need an array instead of a list (in the .ExportLinkedData function).

www.nxjournaling.com
 
Thanks Cowski, it solve one problem but there still is "system.nullreferenceexception object reference not set to an instance of an object (...) line 85"

Which is:
ufs.Ps.ExportLinkedData(Taglist, Taglist.Length, exportFileName, PSversion, Nothing, numUnexported, Nothing)

What is Taglist in this command?


With best regards
Michael
 
Thank Cowski, I have made some changes. Now it select all bodies in part, but there are 2 problems:
[ul]
[li]It's works for all layers, not only for layer 1[/li]
[li]After import parasolid, I receive many parts, so it's useless[/li]
[/ul]
Here is my 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 mySelectedObjects() As NXObject
       Dim myResponse As Selection.Response
       

      ' 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 n As String = vbCrLf

    Dim bodies As BodyCollection = workPart.Bodies
    Dim bodyCount As Integer = bodies.ToArray.Length
    Dim tagList(bodyCount - 1) As NXOpen.Tag
       
    Do
        tagList(inx) = workPart.Bodies.ToArray(inx).Tag
        inx = inx + 1

    Loop Until inx = bodyCount

       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

With best regards
Michael
 
niedzviedz said:
It's works for all layers, not only for layer 1

Not surprising, since nowhere in the code do you check the layer of the body...
There are at least two ways to get the bodies on a particular layer.
[ul]
[li]iterate through the body collection, check the layer of the body, if it is on the desired layer, add it to the list[/li]
[li]use .GetAllObjectsOnLayer (as in a previous snippet you posted), then look for objects of type "Body", add those to the list[/li]
[/ul]

www.nxjournaling.com
 
Thank Cowski. I have question, how to check if body is on desired layer?
I also tried second option but with no results. It seems that body wasn't selected, because I received an error in part of code which is respond to export parasolid. I'm not sure, because I don't now how to check this.
I also tried this:
Code:
    allObjects = workPart.Layers.GetAllObjectsOnLayer(1) 
   	For Each temp As body In allObjects
            theBodies.Add(temp) 
	 Next
And got an error: "System.invalidcastexeption: You cannot project type of object 'NXOpen.face' to type 'NXOpen.body' (...) line 48" Which is "for each temp As body In allObjects"

Any suggestion?



With best regards
Michael
 
If you iterate through the body collection, the code might look like this:
Code:
For each tempBody as Body in part.Bodies
    if tempBody.Layer = 1 then
        theBodies.Add(tempBody)
    end if
Next

We can define tempBody as type of Body because we know there are only body objects in the body collection. The body collection contains both solid and sheet bodies, we can differentiate between the two with the .IsSolidBody or .IsSheetBody properties of the body object.



If you use the .GetAllObjectsOnLayer command, the code might look like:
Code:
For each temp as DisplayableObject in allObjects
    if TypeOf(temp) is Body then
        theBodies.Add(temp)
    end if
Next

In this case, various object types can be returned (anything that can be shown on a layer); all of the objects shown in the graphics window derive from the DisplayableObject type, so we use that in the For each loop. We can test for the specific object type with the TypeOf command.

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top