Modifying a manul dimension with a multiplier
Modifying a manul dimension with a multiplier
(OP)
OK, so here's the deal. We are using electrical routing for our wire harnessses. In our current version of NX (V9) the software is not handling applied slack very well.... in fact it is slowing us down by 10 or 20 times. We are looking for a workaround so that we don't need to apply slack to the actual cable. Our idea is to dimension our cable and then edit the selected dimensions to multiply them by a slack multiplier (eg length X 1.012). Does anyone have an idea how this might be done with minimal effort? An automated approach would be best since we can minimize errors that way.
Appreciate any comments or ideas you might have.
Thanks,
Gordon
Appreciate any comments or ideas you might have.
Thanks,
Gordon





RE: Modifying a manul dimension with a multiplier
If you are determined to override the dimension values as a workaround to this problem, at least you should have a tool to help minimize mistakes. The journal below will allow you to select a dimension, it will then multiply the computed length of the dimension by the factor that you specify and enter it as manual text. It will be rounded to the same number of decimal places as the original dimension, some attributes will be added to the dimension, and it will be colored "strong gold" so that you can visually discern which dimensions have 'slack' added (you may need to turn off monochrome drawing display to take advantage of this). If/when the wire length is modified, the dimension will NOT automatically update its value. However, subsequent runs of the journal will update the dimensions that have the attribute by checking the computed length and applying the slack factor. Because of this, if you later revert a dimension back to automatic text, be sure to delete the attributes associated with the dimension.
You are wading into dangerous waters, good luck.
CODE
'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 'http://www.eng-tips.com/viewthread.cfm?qid=373211 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 Modulewww.nxjournaling.com
RE: Modifying a manul dimension with a multiplier
Thank you very much for the journal file. It is just what we were looking for.
I am with you and generally would rather be beaten with a shovel than allow manual text but sometimes circumstances dictate some questionable directions. I have filed PR's with GTAC and we are pounding on them often for some resolution. Thank you again.... I wish I could return the favor. Maybe sometime.