Submitted by Onur on Wed, 04/19/2017 - 01:23
Forums:
Hello,
I have an assembly drawing, and when I remove some components from the assembly, some dimensions/symbols/notes defining these components get broken as expected.
I want to find&delete whatever is broken in this multi sheet drawing automatically.
Is that possible?
Thanks,
Onur.
re: delete broken annotations
When using interactive NX, the default option is to retain the dimension when/if the associativity is broken. There is an option within the drafting preferences that will delete the retained annotations (general/setup -> retained annotations -> delete retained annotations). Alternatively, you can turn off the option to retain the annotations, in which case they will be deleted instead of kept in the "retained" state.
https://docs.plm.automation.siemens.com/tdoc/nx/10/nx_help/#uid:xid608304
If you would like to write code to do this, one strategy would be to iterate through the annotations, checking the value of the .IsRetained property and deleting the objects as necessary.
Thank you very much. After
Thank you very much. After your guidance, I realized NX allows a journal to be recorded for this operation.
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
workPart.DeleteRetainedDraftingObjectsInCurrentLayout()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Set General Drafting Preferences")
workPart.Preferences.Drafting.InitialSheetNumber = "1"
workPart.Preferences.Drafting.InitialSecondaryNumber = "A"
workPart.Preferences.Drafting.Delimiter = ""
workPart.Preferences.Drafting.Color = 193
workPart.Preferences.Drafting.Font = Preferences.PartDrafting.FontType.Dotted
workPart.Preferences.Drafting.Width = Preferences.PartDrafting.WidthType.Original
workPart.Preferences.Drafting.RetainAnnotations = True
workPart.Preferences.Drafting.ViewStyle = Preferences.PartDrafting.ViewStyleType.Wireframe
workPart.Preferences.Drafting.ViewTracking = False
workPart.Preferences.Drafting.DelayViewUpdate = False
workPart.Preferences.Drafting.DelayUpdateOnCreation = False
workPart.Preferences.Drafting.UpdateViewWithoutLwData = Preferences.PartDrafting.UpdateViewWithoutLwDataOption.Ignore
workPart.Preferences.Drafting.EnableSmoothEdgesForLWView = False
workPart.Preferences.Drafting.BorderColor = 159
workPart.Preferences.Drafting.DisplayBorders = False
workPart.Preferences.Drafting.ActiveViewColor = workPart.Colors.Find("SFT_Blue")
workPart.Preferences.Drafting.VersionObjects = True
workPart.Preferences.Drafting.Translucency = False
workPart.Preferences.Drafting.LineAntialiasing = False
workPart.Preferences.Drafting.ShowFacetEdges = False
theSession.Preferences.Drafting.GridObject = Preferences.SessionDrafting.GridObjectType.Drafting
workPart.Preferences.Drafting.BreakLineType = Preferences.PartDrafting.BreakLineStyle.Existing
workPart.Preferences.Drafting.BreakLineAmplitude = 6.0
workPart.Preferences.Drafting.BreakLineExtension = 3.0
workPart.Preferences.Drafting.BreakLineGap = 6.0
workPart.Preferences.Drafting.BreakLineWidth = 5
workPart.Preferences.Drafting.BreakLineColor = workPart.Colors.Find("Black")
workPart.Preferences.Drafting.PropagateBreakLines = True
workPart.Preferences.Drafting.BreakLinesVisibility = True
workPart.Preferences.Drafting.MinimumComponentsForLargeAssemblyOption = 500
workPart.Preferences.Drafting.AssociativeAlignment = True
theSession.Preferences.Drafting.LoadComponentOnFacetedViewSelection = True
theSession.Preferences.Drafting.LoadComponentOnFacetedViewUpdate = False
theSession.Preferences.Drafting.AutomaticCustomSymbolUpdate = True
theSession.Preferences.Drafting.DynamicAlignment = True
End Sub
End Module
I found out that the above
I found out that the above code cleans the broken dimensions on a single sheet, and for a multiple sheet drawing, it has to be run on each page. How can it be turned into a code that does the work for all the sheets of a drawing at once?
Early thanks for your support.
re: run on multiple sheets
The code below will cycle through the sheets in the current work part.
Option Strict Off
Imports System
Imports NXOpen
Module Module2
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workpart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each dwg As Drawings.DrawingSheet In workpart.DrawingSheets
dwg.Open()
workpart.DeleteRetainedDraftingObjectsInCurrentLayout()
'other code as necessary
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
Thank you very much.
Thank you very much.
Hello,
Hello,
the code works. One more please: We want to repair the retained objects. But its hard to find them when the drafting is complex.
Is there any option to highlight the retained objects or get an lw.writeline? For example: "4 Retained Objects found - please repair"?
Best regards!
re: retained dimensions
You can set the color for retained dimensions (I think the default is a light purple in recent releases of NX); if you turn off "monochrome display", the retained dimensions should stand out.
If you want a journal solution, the function below will turn on the highlighting for each retained dimension (you will probably need to use part cleanup to turn the highlighting off). This function does not report the number of retained dimensions, but a counter variable could be added and incremented for each retained dimension found.
Function RetainedDimensions() As Boolean
Dim retainedDimFound As Boolean = False
For Each tempDim As Annotations.Dimension In theSession.Parts.Work.Dimensions
If tempDim.IsRetained Then
tempDim.Highlight()
'lw.WriteLine("dim location: " & tempDim.AnnotationOrigin.ToString)
retainedDimFound = True
End If
Next
Return retainedDimFound
End Function
Thank you for the quick
Thank you for the quick answer!
your first suggestion is good. But we have so many different colors in the drawing that it quickly becomes confusing.
The code works. The first code also deletes balloons, notes or date feature symbols (all retained draftign objects).
Your new code only highlights dimensions. Can you change this for me? that the code highlights all objects? I've tried, but have been unsuccessful :/
re: retained annotations
Similar functions can be written like this:
Function RetainedIdSymbols() As Boolean
Dim retainedIdSymbol As Boolean = False
'Are any ID symbols retained?
For Each temp As Annotations.IdSymbol In theSession.Parts.Work.Annotations.IdSymbols
If temp.IsRetained Then
retainedIdSymbol = True
temp.Highlight()
End If
Next
Return retainedIdSymbol
End Function
Function RetainedNoteOrLabel() As Boolean
Dim retainedNote As Boolean = False
For Each tempNote As Annotations.Note In theSession.Parts.Work.Notes
If tempNote.IsRetained Then
retainedNote = True
tempNote.Highlight()
End If
Next
For Each tempLabel As Annotations.Label In theSession.Parts.Work.Labels
If tempLabel.IsRetained Then
retainedNote = True
tempLabel.Highlight()
End If
Next
Return retainedNote
End Function
Function RetainedSymbols() As Boolean
Dim retainedSymbol As Boolean = False
For Each tempSymbol As Annotations.CustomSymbol In theSession.Parts.Work.Annotations.CustomSymbols
If tempSymbol.IsRetained Then
retainedSymbol = True
tempSymbol.Highlight()
End If
Next
Return retainedSymbol
End Function