'NXJournaling.com
'October 15, 2014
'
'Multiply a chosen dimension by a 'slack' factor, this changes chosen dimension to manual text.
'Dimensions modified will be changed to color 'strong gold' (color 84) to help
'distinguish them from normal dimensions (turn off monochrome drawing display to see the colors).
' Preferences -> Visualization -> color/font -> drawing part settings -> monochrome display
'As the design changes, these dimensions will need to be updated either by running the journal
'again or changing the text value by hand.
'Two attributes will be added to the selected dimensions:
' "SlackAdded" (boolean), to signify the dimension has been modified - dims with this attribute
' will be updated automatically by the journal on subsequent runs
' "LastUpdated" (date/time), timestamp when the journal last updated the dimension - can be used
' to determine if the manual dimensions are out of sync with the latest design change.
'NX 8.5, not tested with dual dimensions
'[URL unfurl="true"]http://www.eng-tips.com/viewthread.cfm?qid=373211[/URL]
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ multiply the chosen dimension by the given factor
Const dimFactor As Double = 1.012
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Sub Main()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
lw.Open()
Const undoMarkName As String = "NXJournal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, undoMarkName)
Dim markid2 As Session.UndoMarkId
markid2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Update Slack Dimensions")
UpdateSlackDims()
Dim myDim As Annotations.Dimension
Do While select_a_dimension("Select dimension to add slack", myDim) = Selection.Response.Ok
AddSlack(myDim, True)
AddAttributes(myDim)
'color 84 = strong gold
ColorDim(myDim, 84)
Loop
lw.Close()
End Sub
Function select_a_dimension(ByVal prompt As String, ByRef obj As Annotations.Dimension) As Selection.Response
Dim ui As UI = ui.GetUI()
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_dimension_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject(prompt, prompt, _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, obj, cursor)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Sub UpdateSlackDims()
For Each tempDim As Annotations.Dimension In workPart.Dimensions
If tempDim.HasUserAttribute("SlackAdded", NXObject.AttributeType.Boolean, -1) Then
AddSlack(tempDim, False)
AddAttributes(tempDim)
ColorDim(tempDim, 84)
End If
Next
End Sub
Sub AddSlack(ByRef theDim As Annotations.Dimension, ByVal addUndo As Boolean)
Dim markId1 As Session.UndoMarkId
If addUndo Then
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add Dimension Slack")
End If
Dim decPlaces As Integer = theDim.NominalDecimalPlaces
Dim newText(0) As String
Dim calcDim As Double = theDim.ComputedSize * dimFactor
calcDim = Math.Round(calcDim, decPlaces, MidpointRounding.ToEven)
newText(0) = calcDim.ToString
theDim.SetDimensionText(newText)
theDim.RedisplayObject()
End Sub
Sub AddAttributes(ByVal theDim As Annotations.Dimension)
Dim objects1(0) As NXObject
objects1(0) = theDim
'add "SlackAdded" attribute
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
With attributePropertiesBuilder1
.IsArray = False
.SetAttributeObjects(objects1)
.Category = "SlackDim"
.Title = "SlackAdded"
.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Boolean
.BooleanValue = AttributePropertiesBaseBuilder.BooleanValueOptions.True
Dim nXObject1 As NXObject
nXObject1 = .Commit()
.Destroy()
End With
'add time attribute
Dim myDateTime As DateTime = Now
Dim attributePropertiesBuilder2 As AttributePropertiesBuilder
attributePropertiesBuilder2 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
With attributePropertiesBuilder2
.IsArray = False
.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Date
.Category = "SlackDim"
.Title = "LastUpdated"
.DateValue.DateItem.Day = myDateTime.Day - 1
.DateValue.DateItem.Month = myDateTime.Month - 1
.DateValue.DateItem.Year = myDateTime.Year.ToString
.DateValue.DateItem.Time = myDateTime.ToString("HH:mm:ss")
Dim nXObject7 As NXObject
nXObject7 = .Commit()
.Destroy()
End With
End Sub
Sub ColorDim(ByRef theDim As Annotations.Dimension, ByVal theColor As Integer)
Dim objects1(0) As DisplayableObject
objects1(0) = theDim
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
With displayModification1
.ApplyToAllFaces = True
.ApplyToOwningParts = False
.NewColor = theColor
.Apply(objects1)
.Dispose()
End With
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module