Use this code and change it. I want that evry plane of the parts which are in the open…
- User
Use this code and change it. I want that evry plane of the parts which are in the open assembly are hidden. Here the Code:
Sub Main() ' Path to the status file Dim statusFilePath As String = "C:\Progress\BauteilFullFileName.txt"
' Check if the status file exists If Not System.IO.File.Exists(statusFilePath) Then' MessageBox.Show("Status file not found. Please run the first rule first.", "Error")
'_______ ' Prompt the user to select a part Try ' Set the selection filter for part occurrences within an assembly Dim oFilter As SelectionFilterEnum = SelectionFilterEnum.kAssemblyLeafOccurrenceFilter
' Prompt the user to select a part occurrence Dim oInput As Object = ThisApplication.CommandManager.Pick(oFilter, "Please select a part") If TypeOf oInput Is ComponentOccurrence Then Dim oOcc As ComponentOccurrence = oInput ' Retrieve the document of the selected occurrence Dim oDoc As Document = oOcc.Definition.Document If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then ' If it is a part Dim oPartDoc As PartDocument = oDoc Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition ' Make all work planes visible For Each oWorkPlane As WorkPlane In oPartDef.WorkPlanes oWorkPlane.Visible = True Next ' Update the document (optional) oPartDoc.Update() ' Execute the AssemblyHalfSectionViewCmd' ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyHalfSectionViewCmd").Execute()
' Save the full file path of the part Dim bauteilFullFileName As String = oPartDoc.FullFileName ' Ensure the folder exists If Not System.IO.Directory.Exists("C:\Progress") Then System.IO.Directory.CreateDirectory("C:\Progress") End If System.IO.File.WriteAllText(statusFilePath, bauteilFullFileName) ' Notify the user ' MessageBox.Show("The work planes have been made visible. Please execute the half section command and then start the second rule to hide the work planes again.", "Notice") Else MessageBox.Show("The selected item is not a part.", "Error") End If Else MessageBox.Show("Please select a valid part.", "Error") End If Catch ex As Exception MessageBox.Show("Selection canceled or an error occurred: " & ex.Message, "Error") End Try'____________
hide(statusFilePath)
Exit Sub End If hide(statusFilePath) End SubSub hide(statusFilePath As String) Try ' Read the full file path of the part from the file Dim bauteilFullFileName As String = System.IO.File.ReadAllText(statusFilePath).Trim()
' Open or reference the part document Dim oPartDoc As PartDocument = Nothing For Each doc As Document In ThisApplication.Documents If doc.FullFileName = bauteilFullFileName Then oPartDoc = doc Exit For End If Next ' If the document is not open, open it If oPartDoc Is Nothing Then oPartDoc = ThisApplication.Documents.Open(bauteilFullFileName, True) End If If oPartDoc IsNot Nothing Then Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition ' Hide all work planes For Each oWorkPlane As WorkPlane In oPartDef.WorkPlanes oWorkPlane.Visible = False Next ' Update the document (optional) oPartDoc.Update() ' Delete the status file System.IO.File.Delete(statusFilePath) - Assistant