Stosowanie wyglądu do bryły (makro)

Witam

 Chcę zastosować materiał i wygląd za pomocą makra. Rzeczywiście, nagrałem makro, aby mieć historię. Niestety, zmiana wyglądu karoserii nie jest brana pod uwagę. Czy masz jakieś pojęcie o kodzie? Chcę wpłynąć na wygląd "przezroczystego plastiku".

Dziękuję za pomoc.

Wygląd "półprzezroczystego plastiku"

Dla mnie wszystko, co musisz zrobić, to stworzyć materiał z właściwością transparent, a następnie zmienić istniejący materiał na nowy.

Znaleziono kilka przykładów:

http://help.solidworks.com/2021/English/api/sldworksapi/Set_Material_Example_VB.htm?verRedirect=1

https://r1132100503382-eu1-3dswym.3dexperience.3ds.com/#community:yUw32GbYTEqKdgY7-jbZPg/iquestion:xuqdxleds8qsyxdrksn6ua

Poza tym mam też to makro w swojej bibliotece (nie testowane):

'Cette macro recharge l'une des 3 matières au choix  si détecté dans la pièce

Option Explicit


Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim myMatVisProps As SldWorks.MaterialVisualPropertiesData
Dim orgBlend As Boolean
Dim orgApply As Boolean
Dim orgAngle As Double
Dim orgScale As Double
Dim longstatus As Long
Dim bRet As Boolean
Dim i As Long
Dim Assembly As ModelDoc2
Dim myAssy As AssemblyDoc
Dim myCmps As Variant
Dim myCmp As Component2
Dim nInfo As Long

Sub main()
    Set swApp = Application.SldWorks
    Set Assembly = swApp.ActiveDoc
    Set myAssy = Assembly

    myCmps = myAssy.GetComponents(False)
    For i = 0 To UBound(myCmps)
        Set myCmp = myCmps(i)
        If (myCmp.GetSuppression = 3) Or (myCmp.GetSuppression = 2) Then
            bRet = myCmp.Select2(False, 0)
            bRet = myAssy.EditPart2(True, True, nInfo)
            Set swModel = myAssy.GetEditTarget

            If swModel.GetType = 1 Then
                Dim result As String
                Dim Mat As String
                Dim configName As String
                configName = "Défaut"
                Dim databaseName As String
                'nom de la base des matériaux
                databaseName = "C:/Program Files/SOLIDWORKS Corp/SOLIDWORKS/lang/french/sldmaterials/solidworks materials.sldmat"

                Dim searchPropName1 As String
                Dim searchPropName2 As String
                Dim searchPropName3 As String
                Dim searchPropName4 As String
                'Noms des matériaux à recharger
                searchPropName1 = "Soudure inox"
                searchPropName2 = "Stellite Grade 21 (RC)"
                searchPropName3 = "Stellite Grade 12 (RB)"
                searchPropName4 = "Stellite Grade 6 (RA)"

                Dim myPart As SldWorks.PartDoc
                Set myPart = swModel
                result = myPart.GetMaterialPropertyName2(configName, Mat)

                If result = searchPropName1 Then
                    myPart.SetMaterialPropertyName2 configName, databaseName, searchPropName1
                    Set myMatVisProps = myPart.GetMaterialVisualProperties()
                    Call apply_material_visual_properties(myMatVisProps, myPart)
                ElseIf result = searchPropName2 Then
                    myPart.SetMaterialPropertyName2 configName, databaseName, searchPropName2
                    Set myMatVisProps = myPart.GetMaterialVisualProperties()
                    Call apply_material_visual_properties(myMatVisProps, myPart)
                ElseIf result = searchPropName3 Then
                    myPart.SetMaterialPropertyName2 configName, databaseName, searchPropName3
                    Set myMatVisProps = myPart.GetMaterialVisualProperties()
                    Call apply_material_visual_properties(myMatVisProps, myPart)
                ElseIf result = searchPropName4 Then
                    myPart.SetMaterialPropertyName2 configName, databaseName, searchPropName4
                    Set myMatVisProps = myPart.GetMaterialVisualProperties()
                    Call apply_material_visual_properties(myMatVisProps, myPart)
                End If
            End If

            myAssy.EditAssembly
        End If
    Next i

    Assembly.ForceRebuild3 False

End Sub


Private Sub apply_material_visual_properties(myMatVisProps As SldWorks.MaterialVisualPropertiesData, myPart As SldWorks.PartDoc)
    If Not myMatVisProps Is Nothing Then
        orgAngle = myMatVisProps.Angle
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)

        orgScale = myMatVisProps.Scale2
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)

        If myMatVisProps.BlendColor = 0 Then
            orgBlend = False
        Else
            orgBlend = True
        End If
        myMatVisProps.BlendColor = Not orgBlend
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)
        myMatVisProps.BlendColor = orgBlend
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)

        If myMatVisProps.ApplyMaterialColorToPart = 0 Then
            orgApply = False
        Else
            orgApply = True
        End If
        myMatVisProps.ApplyMaterialColorToPart = Not orgApply
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)
        myMatVisProps.ApplyMaterialColorToPart = orgApply
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)

        If myMatVisProps.ApplyMaterialHatchToSection = 0 Then
            orgApply = False
        Else
            orgApply = True
        End If
        myMatVisProps.ApplyMaterialHatchToSection = Not orgApply
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)
        myMatVisProps.ApplyMaterialHatchToSection = orgApply
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)

        If myMatVisProps.ApplyAppearance = 0 Then
            orgApply = False
        Else
            orgApply = True
        End If
        myMatVisProps.ApplyAppearance = Not orgApply
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)
        myMatVisProps.ApplyAppearance = orgApply
        longstatus = myPart.SetMaterialVisualProperties(myMatVisProps, swThisConfiguration, Nothing)
    End If
End Sub

 

@sbadenis Jak tworzyć materię za pomocą właściwości transparent?

Postępuj zgodnie z poradami zawartymi w tym linku:

http://help.solidworks.com/2020/French/SolidWorks/sldworks/t_custom_material_creating.htm?verRedirect=1

Albo znowu:

https://www.visiativ-solutions.fr/personnaliser-materiau-solidworks/

Następnie musisz przejść do zakładki wyglądu i umieścić żądane wyglądy. (przejrzystość)

Albo kopiujesz istniejący przezroczysty materiał, taki jak materiały solidworks/Inne niemetale/Szkło (i zmieniasz właściwości, moduł, sprężystość...)

Kilka rozwiązań do wyboru.

 

Problem polega na tym, że bez względu na to, jak bardzo kopiuję przezroczysty materiał, gdy tylko zmienię jego nazwę i zmienię jego właściwości mechaniczne, przezroczystość znika... To smutne :'( 

W porządku, znalazłem, jest to trochę bardziej skomplikowane niż kopiowanie i wklejanie , ale działa

W każdym razie dziękuję za odpowiedź