Submitted by quicova@gmail.com on Thu, 09/11/2014 - 06:01
Forums:
Hi,
I'm new to jornalling.
I'm creating a jornal to read an excel file, change the expressions and export a parasolid. Do this for every row in the excel file.
I managed to copy a lot of code from a lot of places (The record jornal specially) to make this happen, but I'm stock on how to select all solid objects automatically.
I don't want to have to select every object manually, I just need the script to do it by itself.
Anyone has any ideas how to achieve this
Thanks so much
Kiko
re: get all solids in part
Each part object contains a "bodies" collection which contains all of the bodies in the part (both solid and sheet). I'd suggest adding all the solid bodies to a list, then exporting all the bodies in the list. The code in the link below will show how to get all the solid bodies into a list.
http://nxjournaling.com/comment/180#comment-180
Hi, Thanks for the reply.
Hi, Thanks for the reply.
I'm new to this, I couldn't get it to work. get a error of NxOpen.tag....
here is the Code I have so far, I copied the export parasolid there is in the tutorial Sections, I just need to change to select all instead of using the manual selection.
Dim mySolids As List(Of Body) = New List(Of Body)
'workPart.Bodies collection contains both solid and sheet bodies
'filter out solid bodies and add them to the list
For Each solid As Body In workPart.Bodies
If solid.IsSolidBody Then
mySolids.Add(solid)
End If
Next
ReDim tagList(mySolids.GetUpperBound(0))
For i = 0 To mySolids
tagList(i) = mySolids(i).Tag
Next
'Create the Export File Name
exportFileName = strOutputFolder & "\test.x_t"
'if this file already exists, delete it
If My.Computer.FileSystem.FileExists(exportFileName) Then
My.Computer.FileSystem.DeleteFile(exportFileName)
End If
Try
ufs.Ps.ExportData(mySolids, exportFileName)
Catch ex As NXException
lw.WriteLine("*** ERROR ***")
lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
End Try
Really need some help with this
Sorry Here is the Code in a
Sorry Here is the Code in a better format
""
Dim mySolids As List(Of Body) = New List(Of Body)
'workPart.Bodies collection contains both solid and sheet bodies
'filter out solid bodies and add them to the list
For Each solid As Body In workPart.Bodies
If solid.IsSolidBody Then
mySolids.Add(solid)
End If
Next
ReDim tagList(mySolids.GetUpperBound(0))
For i = 0 To mySolids
tagList(i) = mySolids(i).Tag
Next
'Create the Export File Name
exportFileName = strOutputFolder & "\test.x_t"
'if this file already exists, delete it
If My.Computer.FileSystem.FileExists(exportFileName) Then
My.Computer.FileSystem.DeleteFile(exportFileName)
End If
Try"
ufs.Ps.ExportData(mySolids, exportFileName)
Catch ex As NXException
lw.WriteLine("*** ERROR ***")
lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
End Try
"
re: export parasolid
Let's improve on the 'export parasolid' code. We'll create a list of the solid body Tags, then use the .ToArray method in the export function. If you do not need to reference the solid bodies later in the journal, you can eliminate the "mySolids" list entirely.
Dim mySolids As List(Of Body) = New List(Of Body)
Dim tagList As New List(Of Tag)
'workPart.Bodies collection contains both solid and sheet bodies
'filter out solid bodies and add them to the list
For Each solid As Body In workPart.Bodies
If solid.IsSolidBody Then
mySolids.Add(solid)
tagList.Add(solid.Tag)
End If
Next
'Create the Export File Name
exportFileName = strOutputFolder & "\test.x_t"
'if this file already exists, delete it
If My.Computer.FileSystem.FileExists(exportFileName) Then
My.Computer.FileSystem.DeleteFile(exportFileName)
End If
Try
ufs.Ps.ExportData(tagList.ToArray, exportFileName)
Catch ex As NXException
lw.WriteLine("*** ERROR ***")
lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
End Try
re: export parasolid
Awesome,
Thanks so much
Re: Export Parasolid
Hi Cowski,
Long time lurker, your posts and resources around the web have always been a big help!
I'm working on a script that clones an assembly, opens the cloned assembly, then exports that assembly as a parasolid. Like Kiko, I'm trying to automate the export process.
Using the code above, I'm getting a "Empty link list" error message; it seems it's not adding the solids into the array. Is there any initial setup required for the For Each statement to pull solid bodies properly? I have the export function below:
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
basePart1 = theSession.Parts.OpenBaseDisplay((cloneDirectory & fileName), partLoadStatus1)
partLoadStatus1.Dispose()
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim exportFileName As String = Nothing
Dim mySolids As List(Of Body) = New List(Of Body)
Dim tagList As New List(Of Tag)
For Each solid As Body In workPart.Bodies
If solid.IsSolidBody Then
tagList.Add(solid.Tag)
End If
Next
exportFileName = cloneDirectory & fileName.Remove(fileName.Length - 4, 4) + ".x_t"
If My.Computer.FileSystem.FileExists(exportFileName) Then
My.Computer.FileSystem.DeleteFile(exportFileName)
End If
Try
ufs.Ps.ExportData(tagList.ToArray, exportFileName)
Catch ex As NXException
LW.WriteLine("*** ERROR ***")
LW.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
End Try
I tried learning about tags; is there a specific NXOpen namespace that should be used?
Thanks!
re: export parasolid
What is the exact error message returned? Does it specify the line of code where the error occurs?
I don't see anything obviously wrong with the code that uses the tagList; you might need the following line in the imports section of your code:
Imports System.Collections.Generic
The only other thing that jumps out at me is the following line:
exportFileName = cloneDirectory & fileName.Remove(fileName.Length - 4, 4) + ".x_t"
I'm not sure what value the "cloneDirectory" variable holds, but you may need to add a "\" between the directory and filename to specify a valid path. I like to use the IO.Path.Combine method as it will take care of the slashes in the path for you.
https://msdn.microsoft.com/en-us/library/fyy7a5kt(v=vs.110).aspx
Re: Export Parasolid
Hey, thanks for taking a look!
I do have Imports System.Collections.Generic at the top. Here's all the imports statements I have:
Imports System
Imports System.IO
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Layer
Also I did a LW.Writeline(exportFileName) and there seemed to be no issues with the path (currently cloneDirectory is a predefined string path with the '\' included at the end).
The error I'm getting is:
Runtime error:
NXOpen.NXException: Empty link list
at NXOpen.UF.UFPs.ExportData(Tag[] body_list, String file_name)
at this line of code:
ufs.Ps.ExportData(tagList.ToArray, exportFileName)
The test model is an assembly part with lower level components.
Let me know if you need any additional information on the environment!
re: export component bodies to parasolid
Sorry, on my first read through, I missed the fact that you are working with an assembly. You cannot access the component bodies through the .Body collection of the assembly; the component bodies are not owned by the assembly itself, but are owned by each individual component part. The current code returns an empty list because there are no bodies in the assembly's body collection. However, the .CycleObjsInPart function will return the component occurrence bodies from the assembly file. The code in the following link shows how to use it.
http://nxjournaling.com/comment/3297#comment-3297
Re: Export Component Bodies to Parasolid
That makes sense! The example function AskAllBodyTags you provided was very helpful; I was able successfully export the assembly as a parasolid this time.
Thank you for your help!