Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX9 - Combine two VB Codes?

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
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
 
Replies continue below

Recommended for you

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor