Cześć ludzie
gdy importuję i zapisuję złożenie *.step jako złożenie Solidworks, gdy wszystkie jego części są oddzielone w folderze, właściwości nie są edytowalne
Utworzyłem makro do kopiowania właściwości, usuwania właściwości, wklejania właściwości
Wszystko działa, chyba że typ właściwości jest równaniem typu formuła (jak na przykład materia)
oto mój kod, który uruchomiłbym za pomocą integracji z Mycadtool, aby zapętlić wszystkie pliki zespołów i części
Czy jest coś, czego bym przegapił w makrze, aby skopiować formułę, a nie wynik formuły
w kolorze szarym właściwości niemodyfikowalne
w kolorze białym ten, który dodałem
Jeśli dodam do testu (nie mam pliku z tym typem: formuła w krokach, robię to dla wszystkich przypadków) formułę, jej wynik jest kopiowany, ale nie formuła
C-HC (4)_Vis C-HC-M3-10.SLDPRT (137.4 KB)
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim Part As Object
Dim vPropNames As Variant
Dim vPropTypes As Variant
Dim vPropValues As Variant
Dim resolved As Variant
Dim linkProp As Variant
Dim i As String
Dim j As Integer
Dim Ligne As Integer
Dim custPropType As Long
Dim lRetVal As Long
Dim retval As Long
Dim Nb_espaces As Integer
Sub Step_proprietes()
'Les step importés ont des propriétés non modifiables
'01-Liste les propriétés et les copie
'02-Supprimme les propriétés
'03-Ajouter les propriétés
'https://help.solidworks.com/2023/english/api/sldworksapi/Get_Custom_Properties_of_Referenced_Part_Example_VB.htm?verRedirect=1
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
If Part.GetType = 3 Then Exit Sub '1 = Part, 2 = Assembly, 3 = Drawing
If swCustProp.Count = 0 Then Exit Sub
'01-Liste les propriétés et les copie
Ligne = swCustProp.Count
Debug.Print "Nb propriétés : " & Ligne
lRetVal = swCustProp.GetAll3(vPropNames, vPropTypes, vPropValues, resolved, linkProp)
Dim TABLEAU() As String
ReDim TABLEAU(1 To Ligne, 1 To 3) As String
Debug.Print "N° | Nom" & Space(16) & " | Type | Valeur"
For j = 0 To Ligne - 1
custPropType = swCustProp.GetType2(vPropNames(j))
If j + 1 < 10 Then i = "0" & j + 1
Debug.Print i & " | " & vPropNames(j) & Space(19 - (Len(vPropNames(j)))) & " | " & custPropType & Space(6 - (Len(custPropType))) & " | " & vPropValues(j)
TABLEAU(j + 1, 1) = vPropNames(j)
TABLEAU(j + 1, 2) = custPropType
TABLEAU(j + 1, 3) = vPropValues(j)
Next j
'02-Supprimme les propriétés
For j = 1 To Ligne
swCustProp.Delete TABLEAU(j, 1)
Next j
'03-Ajouter les propriétés
'Problème avec les équations seul le résultat est copié pas la formule
'swCustomInfoDate 64
'swCustomInfoDouble 5
'swCustomInfoNumber 3
'swCustomInfoText 30
'swCustomInfoUnknown 0
'swCustomInfoYesOrNo 11
For j = 1 To Ligne
retval = swCustProp.Add2(TABLEAU(j, 1), TABLEAU(j, 2), TABLEAU(j, 3))
Next j
'Supprime le tableau
Erase TABLEAU
End Sub