Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX VB question

Status
Not open for further replies.

NXJockey

Automotive
Feb 9, 2009
104
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
 
Replies continue below

Recommended for you

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
 
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
 
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:
[ul]
[li]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.[/li]
[li]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.[/li]
[/ul]

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

Part and Inventory Search

Sponsor