Een weergave toepassen op een lichaam (macro)

Hallo

Ik ben op zoek naar het toepassen van een materiaal en een uiterlijk via een macro. Inderdaad, ik heb een macro opgenomen om een achtergrondverhaal te hebben. Helaas wordt er geen rekening gehouden met het veranderen van het uiterlijk van een lichaam. Heb je enig idee van de code? Ik ben op zoek naar het uiterlijk van "transparant plastic".

Dank u voor uw hulp.

"Doorschijnend plastic" uiterlijk

Voor mij hoef je alleen maar het materiaal te maken met de transparante eigenschap en vervolgens het bestaande materiaal te vervangen door het nieuwe.

Enkele voorbeelden gevonden:

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

Anders heb ik ook deze macro in mijn bibliotheek (niet getest):

'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 Hoe creëer je materie met de eigenschap transparant?

Volg het advies in deze link:

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

Of nog een keer:

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

Dan moet je naar het tabblad uiterlijk gaan en de gewenste verschijningen plaatsen. (transparantie)

Of anders kopieer je een bestaand transparant materiaal zoals solidworks-materialen/Andere niet-metalen/Glas (en verander je de eigenschappen moduluselasticiteit...)

Verschillende oplossingen om uit te kiezen.

 

Het probleem is dat hoeveel ik een transparant materiaal ook kopieer, zodra ik het hernoem en de mechanische eigenschappen verander, de transparantie verdwijnt... Het is triest :'( 

Het is oké vond ik, het is een beetje ingewikkelder dan een copy-paste , maar het werkt

Dank u voor uw antwoord in ieder geval