×
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

NX VB question

NX VB question

NX VB question

(OP)
i am trying to create a simple vb script to cycle through all the views in a drawing sheet and reset them to the customer defaults.

I have created the attached code, but it fails, and I cant work out why:- 'Object reference not set to an instance of object' so I think its something to do with the array of the views????

Any help or advice is welcomed,

Thanks in advance,

Nxj

Here is the code;-

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Drawings
Imports NXOpen.UI
Imports NXOpen.Utilities

Module ir_6775305

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
Dim dp As Part = s.Parts.Display()
s.ListingWindow.Open()
For Each dwg As DrawingSheet In dp.DrawingSheets
dwg.Open()
s.ListingWindow.WriteLine("Drawing: " & dwg.Name.ToString)
For Each thisView As DraftingView In dwg.GetDraftingViews()
s.ListingWindow.WriteLine(" " & thisView.Name.ToString)
Dim views() as view
Dim editViewSettingsBuilder1 As Drawings.EditViewSettingsBuilder
editViewSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder(views)
editViewSettingsBuilder1.InheritSettingsFromCustomerDefault()
thisView.UpdateDisplay()
Next
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module

RE: NX VB question

There is an array created to hold objects of type "view", but nothing is put into the array.

CODE

Dim views() as view 

The builder object later attempts to use this empty variable.

www.nxjournaling.com

RE: NX VB question

(OP)
Thanks Cowski,

I have tried this 'views(1) = thisview' but still have a issue :(

updated code:-

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Drawings
Imports NXOpen.UI
Imports NXOpen.Utilities

Module reset_views

Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Sub Main()
Dim dp As Part = s.Parts.Display()
s.ListingWindow.Open()
For Each dwg As DrawingSheet In dp.DrawingSheets
dwg.Open()
s.ListingWindow.WriteLine("Drawing: " & dwg.Name.ToString)
For Each thisView As DraftingView In dwg.GetDraftingViews()
s.ListingWindow.WriteLine(" " & thisView.Name.ToString)
Dim views() as view
views(1) = thisView
Dim editViewSettingsBuilder1 As Drawings.EditViewSettingsBuilder
editViewSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder(views)
editViewSettingsBuilder1.InheritSettingsFromCustomerDefault()
thisView.UpdateDisplay()
Next
Next
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module

RE: NX VB question

You already have a reference to all the views on the sheet with dwg.GetDraftingViews(), so really, you don't even need the views() variable.

A few other observations:
  • When using the edit view settings builder object, you will need to call the .Commit method to make your desired changes and you will need to call the .Destroy method to clean up the builder object. Using a builder object in a loop and not calling the .Destroy method will lead to errors.
  • The edit view settings builder allows you to pass in an array of views to edit; you can pass in the array of views on the sheet and update all of them at the same time. In the current code, it looks like you intend to update them one at a time; which is also a valid strategy, but it may be more efficient to update all the views at once.

www.nxjournaling.com

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