Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Changing the Part Color in assembly file.

Experimenter
Experimenter

I need help in Changing the Face Style of a part in the assembly document using dot net.

 

ScreenShot "face style" Option in Solid Edge is attached bellow.

 

 

3 REPLIES

Re: Changing the Part Color in assembly file.

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

I prepared the following code sample, which sets the face style of all part occurrences in an assembly to "Steel" and then resets it again.

'----------------------------------------------------------------------
' ASM: Change the face style of all assembly occurrences to "Steel"
'----------------------------------------------------------------------
Private objApp As SolidEdgeFramework.Application = Nothing

Sub Main()
  objApp = Marshal.GetActiveObject("SolidEdge.Application")
  
  Dim strStyleName As String = "Steel"
  Dim objDoc As SolidEdgeAssembly.AssemblyDocument = objApp.Documents.Open("S:\Training\Coffee Pot.asm")
  ' Check if the style name exists
  Dim objStyles As FaceStyles = objDoc.FaceStyles
  Try
    Dim objSteel As FaceStyle = objStyles.Item(strStyleName)
  Catch ex As Exception
    MessageBox.Show("The face style [" & strStyleName & "] does not exist in the active assembly!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Exit Sub
  End Try

  Dim bRecurse As Boolean = True
  SetStyleInAsm(objDoc, strStyleName, bRecurse)
  MsgBox("Click OK to reset all face styles", Microsoft.VisualBasic.MsgBoxStyle.OkOnly)
  SetStyleInAsm(objDoc, strStyleName, bRecurse, True)
End Sub

Sub SetStyleInAsm(ByVal objDoc As AssemblyDocument, ByVal styleName As String, ByVal bRecurse As Boolean, Optional ByVal bResetStyle As Boolean = False)
  For Each objOcc As Occurrence In objDoc.Occurrences
    If objOcc.Subassembly And bRecurse Then
      ' Set the face style for each individual subpart recursively
      SetStyleInSubOccs(objOcc.SubOccurrences, styleName, bResetStyle)
    Else
      ' To reset the face style, set it to an empty string
      objOcc.Style = IIf(bResetStyle, String.Empty, styleName)
    End If
  Next
End Sub

Sub SetStyleInSubOccs(ByVal objSubOccs As SubOccurrences, ByVal styleName As String, ByVal bResetStyle As Boolean)
  For Each objSubOcc As SubOccurrence In objSubOccs
    If objSubOcc.Subassembly Then
      SetStyleInSubOccs(objSubOcc, styleName, bResetStyle)
    Else
      ' To set the style in a suboccurrence, we need to access a reference to it
      ' To reset the face style, set it to an empty string
      objSubOcc.Reference.Style = IIf(bResetStyle, String.Empty, styleName)
    End If
  Next
End Sub

Re: Changing the Part Color in assembly file.

Creator
Creator

@MartinBernhard I can Change the face style of a part using above method but in big assembly it takes a lot time.

is there a way that i can change face style like we can do manually in solid edge selecting all occurances and then selecting the face style, Please See Attached file

Kind Regards
Deepak

Re: Changing the Part Color in assembly file.

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Try to encapsulate your code by the following application property changes. This should be the first thing to do to improve the performance of display intensive tasks:

' Improve execution performance
objApp.ScreenUpdating = False
objApp.Interactive = False
'objApp.DisplayAlerts = False ' Optional, to avoid message boxes appear during the macro execution
Try
   '... put your code here ...
Catch ex As Exception
   MessageBox.Show("Macro execution failed!" & vbCrLf & ex.Message)
End Try
' Reset the application properties
objApp.ScreenUpdating = True
objApp.Interactive = True
'objApp.DisplayAlerts = True