×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Import parasolid journal

Import parasolid journal

Import parasolid journal

(OP)
I've recorded a program that imports parasolids from a specific folder. Is it possible to add current date as a name to imported bodies names in part navigator

RE: Import parasolid journal

I think this will do what you want. You may need to edit the format string to get exactly what you want.

CODE

Imports System  
Imports System.IO  
Imports System.Windows.Forms  
Imports NXOpen  

Module Import  

    Sub Main  
		Dim theSession As Session = Session.GetSession()  
		Dim workPart As Part = theSession.Parts.Work  
		Dim myFeatures() as Features.Feature = workPart.Features.GetFeatures  
		Dim lastTimeStamp as integer = myFeatures(myFeatures.Length-1).Timestamp  
		  
		Dim time As DateTime = DateTime.Now  
		Dim format As String = "yyyyMMdd"  

		Dim displayPart As Part = theSession.Parts.Display  
        Try  
           Dim openFileDialog1 As New OpenFileDialog()  
         
            openFileDialog1.Filter = "Parasolid files (*.x_t)|*.x_t|All files (*.*)|*.*"  
            openFileDialog1.FilterIndex = 1  
            openFileDialog1.RestoreDirectory = True  
			openFileDialog1.InitialDirectory = "D:\Parasolid"  
         
            If openFileDialog1.ShowDialog() = DialogResult.OK Then  
                 Console.WriteLine(openFileDialog1.FileName)  
                Dim sr = openFileDialog1.FileName  
				  
				Dim importer1 As Importer  
				importer1 = workPart.ImportManager.CreateParasolidImporter()  

				importer1.FileName = sr  
				  
				Dim nXObject1 As NXObject  
				nXObject1 = importer1.Commit()  
				  
				For each feat as Features.Feature in workPart.Features  
					if feat.Timestamp > lastTimeStamp then  
						feat.SetName(time.ToString(format))  
					end if  
				Next  
				  
            End If  
        Finally  
        End Try  

    End Sub  
End Module 

www.nxjournaling.com

RE: Import parasolid journal

(OP)
I'm getting an error in line

CODE

Dim lastTimeStamp as integer = myFeatures(myFeatures.Length-1).Timestamp 

if the file doesn't contain any model history. When there's an object in model history every thing works great.

RE: Import parasolid journal

Try this one:

CODE

Imports System    
Imports System.IO    
Imports System.Windows.Forms    
Imports NXOpen    

Module Import    

    Sub Main    
		Dim theSession As Session = Session.GetSession()    
		Dim workPart As Part = theSession.Parts.Work    
		Dim myFeatures() as Features.Feature = workPart.Features.GetFeatures    
		Dim lastTimeStamp as integer = -1  
		if myFeatures.Length > 0 then  
			lastTimeStamp = myFeatures(myFeatures.Length-1).Timestamp    
		end if  
		    
		Dim time As DateTime = DateTime.Now    
		Dim format As String = "yyyyMMdd"    

		Dim displayPart As Part = theSession.Parts.Display    
        Try    
           Dim openFileDialog1 As New OpenFileDialog()    
           
            openFileDialog1.Filter = "Parasolid files (*.x_t)|*.x_t|All files (*.*)|*.*"    
            openFileDialog1.FilterIndex = 1    
            openFileDialog1.RestoreDirectory = True    
			openFileDialog1.InitialDirectory = "D:\Parasolid"    
           
            If openFileDialog1.ShowDialog() = DialogResult.OK Then    
                 Console.WriteLine(openFileDialog1.FileName)    
                Dim sr = openFileDialog1.FileName    
				    
				Dim importer1 As Importer    
				importer1 = workPart.ImportManager.CreateParasolidImporter()    

				importer1.FileName = sr    
				    
				Dim nXObject1 As NXObject    
				nXObject1 = importer1.Commit()    
				importer1.Destroy()  
				    
				For each feat as Features.Feature in workPart.Features    
					if feat.Timestamp > lastTimeStamp then    
						feat.SetName(time.ToString(format))    
					end if    
				Next    
				    
            End If    
        Finally    
        End Try    

    End Sub    
End Module 

www.nxjournaling.com

RE: Import parasolid journal

(OP)
Everything works great, Thanks again Cowski

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources