×
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

NX9 - Combine two VB Codes?

NX9 - Combine two VB Codes?

NX9 - Combine two VB Codes?

(OP)
I have CODE-1 that someone here helped me start and I have added to over the last couple of years (I trimmed a bunch of commands out of it to make it easier to work with for now). I was just given this CODE-2 and asked to implement it into the first code. Can someone tell me how to splice these together correctly? It seems no matter what I try, I either get an error or it only runs one of them.


CODE-1

' NX 9.0.2.5
' Journal created by kschonmeier HMS Company
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal

Sub Main(ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim preferencesBuilder1 As Drafting.PreferencesBuilder
preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()
preferencesBuilder1.ViewStyle.ViewStyleGeneral.Silhouettes = True
preferencesBuilder1.ViewStyle.ViewStyleGeneral.Centerlines = False

'find closest NX color in display part color table
'Dark Gray (R,G,B) = 40, 40, 40
Dim colorValues(2) As Double
colorValues(0) = 40 / 255
colorValues(1) = 40 / 255
colorValues(2) = 40 / 255

Dim closeColor As Integer
theUfSession.Disp.AskClosestColor(UFConstants.UF_DISP_rgb_model, colorValues, UFConstants.UF_DISP_CCM_EUCLIDEAN_DISTANCE, closeColor)

Dim myBorderColor As NXColor
myBorderColor = workPart.Colors.Find(closeColor)

'preferencesBuilder1.ViewWorkflow.BorderColor = workPart.Colors.Find("Dark Gray")
preferencesBuilder1.ViewWorkflow.BorderColor = myBorderColor

preferencesBuilder1.ViewWorkflow.PreviewStyle = Drawings.ViewWorkflowBuilder.Style.Shaded

'Dim fontIndex1 As Integer
'fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)

preferencesBuilder1.TableCellStyle.BorderColor = 173
preferencesBuilder1.ViewStyle.ViewStyleGeneral.ExtractedEdges = Preferences.GeneralExtractedEdgesOption.None
preferencesBuilder1.ViewStyle.ViewStyleGeneral.ViewRepresentation = Preferences.GeneralViewRepresentationOption.PreNx85Exact

preferencesBuilder1.ViewWorkflow.DisplayBorders = True
preferencesBuilder1.CommonWorkflow.DynamicAlignmentInGlobalSelection = True

Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)

preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextFont = fontIndex1

Dim nXObject1 As NXObject
nXObject1 = preferencesBuilder1.Commit()

theSession.SetUndoMarkName(markId1, "Drafting Preferences")

preferencesBuilder1.Destroy()
' ----------------------------------------------
' Menu: Edit->Sheet...
' ----------------------------------------------
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim drawingSheet1 As Drawings.DrawingSheet = CType(workPart.DrawingSheets.FindObject("SHT1"), Drawings.DrawingSheet)
Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(drawingSheet1)
drawingSheetBuilder1.ProjectionAngle = Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third
Dim nXObject2 As NXObject
nXObject2 = drawingSheetBuilder1.Commit()
theSession.SetUndoMarkName(markId4, "Sheet")
drawingSheetBuilder1.Destroy()
End Sub
End Module




CODE-2

Option Strict Off
Imports System
Imports NXOpen
Imports System.Collections.Generic

Module GMOutsourceAttributes
'Created By: xxxxxxxx
'Company: xxxxxx
'Date: 04/22/16
'Description
' Adds all the attributes in the dictionary (Attributes) to the current file
' overwriting any existing attributes.

Dim TheSession As Session = Session.GetSession()
Dim WorkPart As Part = TheSession.Parts.Work

Sub Main(ByVal args() As String)
Call Initialize()
End Sub

Public Sub Initialize()
For Each KP As KeyValuePair(Of String, String) In Attributes
If Not TheSession.Parts.Work.HasUserAttribute(KP.Key, NXObject.AttributeType.Any, -1) Then
TheSession.Parts.Work.SetUserAttribute(KP.Key, -1, KP.Value, Update.Option.Now)
TheSession.ListingWindow.Open()
TheSession.ListingWindow.WriteFullline(String.Format("Creating / Writing Attribute: {0} = {1}", KP.Key, KP.Value))
End If

Next
End Sub

Public ReadOnly Property Attributes As Dictionary(Of String, String)
Get
Dim Dict As New Dictionary(Of String, String)
Dict.Add("P_ITEM_NUMBER", "")
Dict.Add("P_TOOL_CLASS", "")
Dict.Add("RAW_MATERIAL", "")
Dict.Add("RAW_MATERIAL_QTY", "")
Dict.Add("PAINT_CODE", "")
Dict.Add("JOB_NUMBER", "")

Return Dict
End Get
End Property

End Module

RE: NX9 - Combine two VB Codes?

(OP)
To be clear, I dont have any programs available to me at this time to work with VB code. I simply look at it through Notepad. Im planning on changing that soon. lol

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