API -Solidworks Usuń (usuń) wygląd według nazwy

Chcę usunąć wygląd (Indice-abc) według nazwy, znalazłem ten kod, ale na razie nie mogę znaleźć, jak wyświetlić te wyglądy według nazwy i usunąć jeden.

http://help.solidworks.com/2020/english/api/sldworksapi/get_appearance_filename_example_vb.htm?verRedirect=1

 

Właśnie znalazłam ten post zrobiony przed wyjazdem na wakacje, czy ktoś ma pomysł na wybór wyglądu po imieniu?

Oto wygląd "index-ABC" , który ma zostać usunięty:

Witam

 

Myślę, że znalazłem rozwiązanie Twojego problemu w tym makrze za pomocą tego stwierdzenia:

        Debug.Print "Nazwa pliku pierwszego pojawienia się: " & swRenderMaterial.fileName

 

Do usunięcia należy użyć tej metody z tego rodzaju deklaracją:

    swModelDocExt.DeleteDisplayStateSpecificRenderMaterial (materialID1_ToDelete), (materialID2_ToDelete)
 

1 polubienie

Dzięki za utwór @mandragore ale na razie nie rozumiem nazwy.

Jest coś, co mi umyka...

Załączam zmodyfikowany kod i zestaw testowy na wypadek, gdyby ktoś z was był bardziej zainspirowany.

 

 

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfig As SldWorks.Configuration
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swEntity As SldWorks.Entity
Dim swSelMgr As SldWorks.SelectionMgr
Dim swRenderMaterial As SldWorks.RenderMaterial
Dim displayStateNames As Variant
Dim status As Boolean
Dim modelName As String
Dim materialName As String
Dim errors As Long
Dim warnings As Long
Dim nbrDisplayStates As Long
Dim i As Long
Dim k As Long
Dim nbrMaterials As Long
Dim materialID1 As Long
Dim materialID2 As Long
Dim materialID1_ToDelete(0) As Long
Dim materialID2_ToDelete(0) As Long

Sub main()



    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    
    'modelName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\dimxpert\bracket_auto_manual.sldprt"
    'Set swApp = Application.SldWorks
    'Set swModel = swApp.OpenDoc6(modelName, swDocPART, swOpenDocOptions_Silent, "", errors, warnings)
    Set swModelDocExt = GetRenderCustomReferences(swModel.Extension)



    ' Get active configuration and create a new display
    ' state for this configuration
    Set swConfig = swModel.GetActiveConfiguration
    'status = swConfig.CreateDisplayState("Display State 2")
   

    'swModel.ForceRebuild3 True
   

    ' Get active configuration and create another new
    ' display state for this configuration
    Set swConfig = swModel.GetActiveConfiguration
    'status = swConfig.CreateDisplayState("Display State 3")
   

    'swModel.ForceRebuild3 True
   

    ' Create appearance
    'materialName = "C:\Program Files\SolidWorks Corp\SolidWorks\data\graphics\materials\metal\steel\stainless steel treadplate.p2m"
    Set swRenderMaterial = swModelDocExt.CreateRenderMaterial(materialName)
    
   

    ' Select a face and add the appearance to that face
    'status = swModelDocExt.SelectByID2("", "FACE", 0.07151920610502, 0.0952597996959, 0.009524999999996, False, 0, Nothing, 0)
    'Set swSelMgr = swModel.SelectionManager
    'Set swEntity = swSelMgr.GetSelectedObject6(1, -1)
    'status = swRenderMaterial.AddEntity(swEntity)
  

    ' Get the names of display states
    displayStateNames = swConfig.GetDisplayStates
    nbrDisplayStates = swConfig.GetDisplayStatesCount
    Debug.Print "This configuration's display states ="
    For i = 0 To (nbrDisplayStates - 1)
        Debug.Print "  Display state name = " & displayStateNames(i)
    Next i
   

    ' Add appearance to all of the display states
    status = swModelDocExt.AddDisplayStateSpecificRenderMaterial(swRenderMaterial, swAllDisplayState, displayStateNames, materialID1, materialID2)
   

    ' Get the appearance IDs and names
    swRenderMaterial.GetMaterialIds materialID1, materialID2
    Debug.Print "    Appearance IDs:"
    Debug.Print "      ID1 = " & materialID1
    Debug.Print "      ID2 = " & materialID2
    nbrMaterials = swModelDocExt.GetRenderMaterialsCount2(swAllDisplayState, Nothing)
    Debug.Print "    Number of appearances: " & nbrMaterials
    
    'Ajout SD
    If nbrMaterials > 0 Then
        swRenderMaterial.GetMaterialIds materialID1, materialID2
        Debug.Print "Material IDs returned by IModelDocExtension::GetMaterialIds: "
        Debug.Print "  ID1: " & materialID1
        Debug.Print "  ID2: " & materialID2
        Debug.Print "First appearance's file name: " & swRenderMaterial.fileName
    Else
        Debug.Print "No appearances applied to this model."
    End If
    'Ajout SD
    
    For k = 0 To (nbrMaterials - 1)
        Debug.Print "      Name of appearance " & (k + 1) & ": " & swModel.MaterialIdName & swRenderMaterial.fileName
    Next k
   

    Dim xcoord As Double
    Dim ycoord As Double
    Dim zcoord As Double
    swRenderMaterial.GetCenterPoint2 xcoord, ycoord, zcoord
    Debug.Print ""
    Debug.Print "Texture-based appearance data:"
    Debug.Print "X coordinate of center point: " & xcoord
    Debug.Print "Y coordinate of center point: " & ycoord
    Debug.Print "Z coordinate of center point: " & zcoord
   

    swRenderMaterial.GetUDirection2 xcoord, ycoord, zcoord
    Debug.Print "X coordinate of U direction: " & xcoord
    Debug.Print "Y coordinate of U direction: " & ycoord
    Debug.Print "Z coordinate of U direction: " & zcoord
       

    swRenderMaterial.GetVDirection2 xcoord, ycoord, zcoord
    Debug.Print "X coordinate of V direction: " & xcoord
    Debug.Print "Y coordinate of V direction: " & ycoord
    Debug.Print "Z coordinate of V direction: " & zcoord
    Debug.Print ""
  

    swModel.ClearSelection2 True
    swModel.ForceRebuild3 True
    

    Debug.Print "Model has an appearance: " & swModelDocExt.HasMaterialPropertyValues
   

    Dim dispStates As Variant
    status = swRenderMaterial.SetLinkedDisplayStates(swAllDisplayState, displayStateNames)
    dispStates = swRenderMaterial.GetLinkedDisplayStates
   

    Dim renderMaterials As Variant
    renderMaterials = swModelDocExt.GetRenderMaterials2(swAllDisplayState, Nothing)
    Stop
   

    ' Delete the appearance from the part
    materialID1_ToDelete(0) = materialID1
    materialID2_ToDelete(0) = materialID2
    swModelDocExt.DeleteDisplayStateSpecificRenderMaterial (materialID1_ToDelete), (materialID2_ToDelete)
    swModel.ForceRebuild3 True
   

    ' Examine the display states of the active configuration
    ' to ensure that the specified appearance was deleted from all
    ' display states (click the ConfigurationManager tab and switch
    ' display states at bottom of the Configuration pane)
    ' Continue running the macro after your examination
    Stop
   

    ' Close the part without saving changes
    modelName = swModel.GetTitle
    swApp.QuitDoc modelName
   

End Sub

 


as_000002.zip

Właśnie spędziłem na nim 3 godziny i nic nie znalazłem. W każdym razie odkryłem tę zakładkę i tę funkcję sortowania wyglądów. Poddaję się po swojej stronie, przepraszam.
 

Znalazłem rozwiązania, aby je zreorganizować itp., Ale żadne, aby dać mi nazwę, które drzwi w drzewie.

Mając nadzieję, że ktoś bardziej kompetentny przyjdzie Ci z pomocą.

1 polubienie

Witam;
Makro tego typu mnie interesuje, ale niestety nie mam zbyt wiele czasu, aby się temu poświęcić....
Oto trop do zbadania (prawdopodobnie): sldworksapi/Get_Material_Properties_Example_VB.htm
lub tutaj: sldworksapi/Get_Appearance_Filename_Example_VB.htm
Pozdrowienia.