Ok, oto część, którą przetestowałem, a także makro:
TEST SŁUPA SZEŚCIOKĄTNEGO. SLDPRT (567.1 KB)
00-MASA-POWIERZCHNIA.swp (36 KB)
Nie ma problemu z mojej strony, niezależnie od wartości współczynnika (musisz postawić kropkę jako przecinek).
Może sprawdź w odwołaniach do projektu makra:
W przeciwnym razie może wystąpić subtelność po stronie ustawień regionalnych stacji i separatora dziesiętnego.
Spróbuj zastąpić przecinek kropką.
Witam @Cyril_f
Makro działa tylko wtedy, gdy utworzę właściwość SURFACE PIECE w F8.
Jeśli pole nie zostanie utworzone, nic się nie stanie.
Szukałem sposobu na automatyczne utworzenie pola, ale utknąłem.
Oto, co próbowałem majstrować bez powodzenia:
Opcja jawna
Dim swApp jako SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Słońce sMass jako ciąg
Dim sValout As String
Dim sVal As String
Dim bRet As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager(" PC ") 'Jeśli właściwość znajduje się na karcie dostosowywania, pozostaw to pole puste, zastępując ' PC ' przez ' '
bRet = swCustProp.Get6' , False, sValout, sMasse, False, False) 'Pobieranie właściwości mass, zmiana nazwy właściwości w celu dopasowania do Twojego modelu
sVal = CStr(CDec(sMass) * 2) 'Konwertuj tekst na wartość dziesiętną, pomnóż x RATIO i przekonwertuj na dane tekstowe
'bRet = swCustProp.Set2(" ELEMENT POWIERZCHNI ", sVal) 'Wypełnij właściwość SURFACE ELEMENT wartością przekształconą w tekst
bRet = swModel.AddCustomInfo3(" PC ", " ELEMENT POWIERZCHNI ", val)
Koniec subwoofera
Próbowałem z tą komendą, ale myślę, że coś jest nie tak:
bRet = swModel.AddCustomInfo3(" PC ", " ELEMENT POWIERZCHNI ", val)
Czy masz pomysł, aby to poprawić?
Zamiast:
'bRet = swCustProp.Set2("ELEMENT POWIERZCHNI", sVal)
Umieść coś takiego:
bRet = swCustPropMgr.Add3(" ELEMENT POWIERZCHNI ", swCustomInfoType_e.swCustomInfoDate, sVal, swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
Wydaje mi się, że ustawienie jest wtedy, gdy właściwość już istnieje.
Zobacz ten link:
https://help.solidworks.com/2020/English/api/sldworksapi/Add_and_Get_Custom_Properties_Example_VB.htm?verRedirect=1
Lub bardziej kompletne:
Zgadza się.
Jeśli właściwość nie istnieje, musisz ją utworzyć, jeśli istnieje, zdarza się również, że SW nie może zapisać (zdarzyło mi się to na starych plikach) i w takim przypadku musisz usunąć i ponownie utworzyć właściwość.
Odpowiadam sobie, jest to naprawione za pomocą Add3, który pozwala na nadpisanie, jeśli właściwość już istnieje.
Czyli zasadniczo:
swCustProp.Add3("SURFACE PIECE", 30, sVal, 1)
Witam, dziękuję za odpowiedzi.
Makro 00-MASS-SURFACE działa dobrze. Czy wiesz jednak, jak mieć tylko 3 miejsca po przecinku dla wartości obszaru?
00-MASA-POWIERZCHNIA.swp (45.5 KB)
I chciałbym zintegrować to makro z makro 00-MACRO HEXA poniżej:
00-MAKRO HEXA.swp (63.5 KB)
Testowałem, ale po uruchomieniu makra pojawia się ten błąd:
Debug daje mi to:
Czy wiesz, jak to naprawić?
Dziękuję
Witam
W przypadku błędu prawdopodobnie jest to zmienna swCustProp.Get6, która jest pusta, więc albo właściwość nie istnieje, albo występuje problem z deklaracją zmiennej.
Aby ograniczyć do 3 miejsc po przecinku, musisz użyć funkcji "Format":
sVal = CStr(Format(CDec(sMasse) * 0.0556, "0.000"))
Brakuje deklaracji dla swCustProp, dodanie 3 wierszy powyżej działa (uważaj, twój kod nadal wymaga dobrego czyszczenia (2x Set swModel...)
Oto kod do czyszczenia:
Dim swModelDocExt As ModelDocExtension
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager(tConfig(i))
bRet = swCustProp.Get6("POIDS", False, sValout, sMasse, False, False)
Odpowiadam sobie, brakuje zestawu zmiennej swCustProp stąd błąd:
Set swCustProp = swModelDocExt.CustomPropertyManager("POIDS") 'Propriété à changer si ce n'est pas celle-ci
Tak, potwierdzam, że trzeba trochę posprzątać.
To majsterkowanie, staram się to wszystko zrozumieć, nie jest łatwo
Posprzątałem i mam nowy alert dotyczący Dim i:
(tConfig(i)) czy to jest dobre dla wszystkich konfiguracji?
Witam
Dim i musi być zadeklarowane w innym miejscu kodu.
Zrozumienie tego wymagałoby pełnego kodu.
Tak więc problem polega na nadmiernym ustawieniu DIM i jako deklaracji liczb całkowitych.
Zasadniczo, ponieważ na początku makra znajduje się linia Set swCustProp = swModelDocExt.CustomPropertyManager(tConfig(i))
, vba inicjuje zmienną i samodzielnie.
W związku z tym uważa, że istnieje zduplikowana deklaracja zmiennej.
Ze swojej strony wolę mieć deklaracje zmiennych w global dla wszystkich Subs, niż deklarować je w każdej procedurze (zależy to w dużej mierze od użycia zmiennych i różnych procedur/funkcji w makrze)
Masz również deklarację swApp 2 razy, raz nad Sub i raz na samym początku Sub.
Przed złożeniem oświadczenia należy dowiedzieć się, czy już nie istnieje.
A jeśli chodzi o pomysł, składanie deklaracji na samym początku suba lub na zewnątrz (przed subem) jest moim zdaniem czystsze.
Coś takiego brzmi dla mnie lepiej:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim tConfig() As String
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim swCustProp As CustomPropertyManager
Dim vConfigName As Variant
Dim sSpecConfigNameArr(0) As String
Dim vSpecConfigNameArr As Variant
Dim dimValue As Variant
Dim stnameConfig As String
Dim boolstatus As Boolean
Dim sMasse As String
Dim sValout As String
Dim sVal As String
Dim bRet As String
Dim swModelDocExt As ModelDocExtension
Dim i As Integer
Dim swErrors As Long
Dim swWarnings As Long
Sub main()
Set swApp = Application.SldWorks
'on récupére le document actif
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
'on récupére la configuration active
Set swConfig = swConfigMgr.ActiveConfiguration
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager(tConfig(i))
stnameConfig = swConfig.Name
vConfigNameArr = swModel.GetConfigurationNames
'on boucle sur toutes les configurations
For Each vConfigName In vConfigNameArr
'on test si la configuration est différente de la configuration active et de la configuration Default
If vConfigName <> swConfig.Name And vConfigName <> "xx" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
If vConfigName <> swConfig.Name And vConfigName <> "Default" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
Next vConfigName
'on reconstruit la pièces
swModel.ForceRebuild3 False
'récupère le document actif dans SW
If Not swModel Is Nothing Then
'''-----------------------------------------------
''' lignes délplacées dans la boucle, de manière à ce que l'operation s'effectue sur tous les fichiers et pas juste le premier.
boolstatus = swModel.DeleteConfiguration2("Défaut")
boolstatus = swModel.DeleteConfiguration2("xx")
Set swPart = swModel
boolstatus = swPart.AddConfiguration2("00", "", "", True, False, False, True, 256)
boolstatus = swPart.AddConfiguration2("PC", "", "", True, False, False, True, 256)
boolstatus = swPart.AddConfiguration2("R6029", "", "", True, False, False, True, 256)
'''-----------------------------------------------
'Mise en place de la matière
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060"
'Boucle sur toutes les configurations
tConfig = swModel.GetConfigurationNames
For i = 0 To UBound(tConfig)
'ajoute un propriété personnalisée edition avec la valeur POTEAUXHEXA"
bRet = swModel.DeleteCustomInfo2(tConfig(i), "DESIGNATION 2")
bRet = swModel.DeleteCustomInfo2(tConfig(i), "PROFILS")
bRet = swModel.AddCustomInfo3(tConfig(i), "PROFILS", swCustomInfoText, "POTEAUXHEXA")
'ajoute un propriété personnalisée edition avec la valeur Masse
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "masse")
bRet = swModel.AddCustomInfo3(tConfig(i), "masse", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
'ajoute un propriété personnalisée edition avec la valeur Poids
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "POIDS")
bRet = swModel.AddCustomInfo3(tConfig(i), "POIDS", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
'ajoute un propriété personnalisée edition avec la valeur MATERIAUX
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "MATERIAUX")
bRet = swModel.AddCustomInfo3(tConfig(i), "MATERIAUX", swCustomInfoText, Chr(34) & "SW-Material" & Chr(34))
'Récupération de la propriété de masse, changer le nom de la propriété en fonction de votre modèle
bRet = swCustProp.Get6("POIDS", False, sValout, sMasse, False, False)
'Conversion du texte en valeur décimale, multiplication x RATIO et conversion en donné de type texte
sVal = CStr(CDec(sMasse) * 0.0556)
'Création de la propriété SURFACE PIECE avec la valeur sVal
bRet = swCustProp.Add3("SURFACE PIECE", 30, sVal, 1)
Next i
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator, 0, 0)
boolstatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearFeetAndInchesFormat, 0, False)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swMM)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearFractionDenominator, 0, 0)
boolstatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsDualLinearFeetAndInchesFormat, 0, False)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Meters3)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)
'Enregistre le docuement actif en mode silencieux
bRet = swModel.Save3(swSaveAsOptions_Silent, swErrors, swWarnings)
'Ferme le document actif
swApp.CloseDoc swModel.GetPathName
End If
End Sub
Za pomocą edytora kodu łatwiej jest wizualizować kod niż dołączać plik swp w celu uzyskania informacji.
Witam @Cyril_f @Lynkoa15 i dziękuję za odpowiedzi,
Ponownie zajmuję się moim problemem, którym dzisiaj ponownie się zajmuję.
Zrobiłem trochę porządków w moim kodzie. To był bałagan!
Ale kończy się na kodzie błędu 91:
Debug daje mi tę linię:
Oto mój kod, jeśli masz pojęcie, gdzie jest błąd:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim vConfigName As Variant
Dim sSpecConfigNameArr(0) As String
Dim vSpecConfigNameArr As Variant
Dim dimValue As Variant
Dim stnameConfig As String
Dim boolstatus As Boolean
Dim i As Integer
Dim swErrors As Long
Dim swWarnings As Long
Dim swPart As SldWorks.PartDoc
Dim tConfig() As String
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim sMasse As String
Dim sValout As String
Dim sVal As String
Sub main()
'''-----------------------------------------------
Set swApp = Application.SldWorks
'on récupére le document actif
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
'on récupére la configuration active
Set swConfig = swConfigMgr.ActiveConfiguration
stnameConfig = swConfig.Name
vConfigNameArr = swModel.GetConfigurationNames
Set swModelDocExt = swModel.Extension
'Set swCustProp = swModelDocExt.CustomPropertyManager(tConfig(i))
Set swCustProp = swModelDocExt.CustomPropertyManager("00")
'''-----------------------------------------------
'on boucle sur toutes les configurations
For Each vConfigName In vConfigNameArr
'on test si la configuration est différente de la configuration active et de la configuration Default
If vConfigName <> swConfig.Name And vConfigName <> "xx" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
If vConfigName <> swConfig.Name And vConfigName <> "Défaut" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
Next vConfigName
'on reconstruit la pièces
swModel.ForceRebuild3 False
Do
'récupère le document actif dans SW
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
''' lignes déplacées dans la boucle, de manière à ce que l'operation s'effectue sur tous les fichiers et pas juste le premier.
Set swPart = swModel
boolstatus = swPart.AddConfiguration2("00", "", "", True, False, False, True, 256)
boolstatus = swModel.DeleteConfiguration2("Défaut")
boolstatus = swModel.DeleteConfiguration2("xx")
'''-----------------------------------------------
'Mise en place de la matière
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060"
'Boucle sur toutes les configurations
tConfig = swModel.GetConfigurationNames
For i = 0 To UBound(tConfig)
'ajoute une propriété personnalisée edition avec la valeur POTEAUXHEXA"
bRet = swModel.DeleteCustomInfo2(tConfig(i), "DESIGNATION 2")
bRet = swModel.DeleteCustomInfo2(tConfig(i), "PROFILS")
bRet = swModel.AddCustomInfo3(tConfig(i), "PROFILS", swCustomInfoText, "POTEAUXHEXA")
'ajoute un propriété personnalisée MASSE avec la valeur Masse
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "masse")
bRet = swModel.AddCustomInfo3(tConfig(i), "masse", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
'ajoute un propriété personnalisée POIDS avec la valeur Masse
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "POIDS")
bRet = swModel.AddCustomInfo3(tConfig(i), "POIDS", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
'ajoute un propriété personnalisée edition avec la valeur MATERIAUX
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "MATERIAUX")
bRet = swModel.AddCustomInfo3(tConfig(i), "MATERIAUX", swCustomInfoText, Chr(34) & "SW-Material" & Chr(34))
'Récupération de la propriété de masse, changer le nom de la propriété en fonction de votre modèle
bRet = swCustProp.Get6("POIDS", False, sValout, sMasse, False, False)
'Conversion du texte en valeur décimale, multiplication x RATIO et conversion en donné de type texte
sVal = CStr(Format(CDec(sMasse) * 0.0556, "0.000"))
'Renseignement de la propriété SURFACE PIECE avec la valeur "sVal"
bRet = swCustProp.Add3("SURFACE PIECE", 30, sVal, 1)
Next i
'Préférences SolidWorks
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator, 0, 0)
boolstatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearFeetAndInchesFormat, 0, False)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swMM)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearFractionDenominator, 0, 0)
boolstatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsDualLinearFeetAndInchesFormat, 0, False)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Meters3)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)
'Enregistre le docuement actif en mode silencieux
bRet = swModel.Save3(swSaveAsOptions_Silent, swErrors, swWarnings)
'Ferme le document actif
swApp.CloseDoc swModel.GetPathName
End If
'boucle jusqu'a ce qu'il n'y ai plus de fichier ouvert dans SW
Loop While Not swModel Is Nothing
End Sub
Dziękuję bardzo
Odpowiadam sobie. Szukałem i szukałem...
Kiedy po raz pierwszy uruchomiłem moje makro, utknęło na tej linii:
Zrobiłem polecenie END i we właściwościach F8 mogłem zobaczyć, że PROFILE/masa/WAGA i MATERIAŁY były dobrze poinformowane. W związku z tym brakowało SURFACE PIECE
Uruchomiłem ponownie i makro działało do końca, dobrze wypełniając SURFACE PIECE.
Tak jakby przy pierwszym uruchomieniu makra nie było w stanie pobrać wartości WEIGHT, która jest obliczana tuż przed.
Dodałem więc częściową rekonstrukcję między MATERIAŁAMI a masowym odzyskiwaniem nieruchomości i to działa.
Przetestowałem moje makro z pojedynczym tworzeniem konfiguracji i SURFACE PIECE był poprawny.
Następnie przetestowałem moje makro, integrując tworzenie 3 konfiguracji: 00 / PC / R1018.
SURFACE PIECE jest dobrze stworzony w 3 konfiguracjach, ale dobry wynik obliczeń otrzymuję tylko na jednej konfiguracji.
Czy masz pojęcie o problemie?
Oto kod:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Dim vConfigName As Variant
Dim sSpecConfigNameArr(0) As String
Dim vSpecConfigNameArr As Variant
Dim dimValue As Variant
Dim stnameConfig As String
Dim boolstatus As Boolean
Dim i As Integer
Dim swErrors As Long
Dim swWarnings As Long
Dim swPart As SldWorks.PartDoc
Dim tConfig() As String
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim sMasse As String
Dim sValout As String
Dim sVal As String
Sub main()
'''-----------------------------------------------
Set swApp = Application.SldWorks
'on récupére le document actif
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
'on récupére la configuration active
Set swConfig = swConfigMgr.ActiveConfiguration
stnameConfig = swConfig.Name
vConfigNameArr = swModel.GetConfigurationNames
Set swModelDocExt = swModel.Extension
'''-----------------------------------------------
'on boucle sur toutes les configurations
For Each vConfigName In vConfigNameArr
'on test si la configuration est différente de la configuration active et de la configuration Default
If vConfigName <> swConfig.Name And vConfigName <> "xx" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
If vConfigName <> swConfig.Name And vConfigName <> "Défaut" Then
boolstatus = swModel.DeleteConfiguration2(vConfigName)
End If
Next vConfigName
'on reconstruit la pièces
swModel.ForceRebuild3 False
Do
'récupère le document actif dans SW
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
''' lignes déplacées dans la boucle, de manière à ce que l'operation s'effectue sur tous les fichiers et pas juste le premier.
Set swPart = swModel
boolstatus = swPart.AddConfiguration2("00", "", "", True, False, False, True, 256)
boolstatus = swPart.AddConfiguration2("PC", "", "", True, False, False, True, 256)
boolstatus = swPart.AddConfiguration2("R1018", "", "", True, False, False, True, 256)
boolstatus = swModel.DeleteConfiguration2("Défaut")
boolstatus = swModel.DeleteConfiguration2("xx")
'''-----------------------------------------------
'Mise en place de la matière
swModel.SetMaterialPropertyName2 "", "X:\DONNEES BE\DAO\BUREAU ETUDES\BIBLI SOLIDWORKS\MATERIAUX\MATERIAUX QUALI-CITE/QUALI-CITE.sldmat", "ALUMINIUM 6060"
'Boucle sur toutes les configurations
tConfig = swModel.GetConfigurationNames
For i = 0 To UBound(tConfig)
'ajoute une propriété personnalisée edition avec la valeur POTEAUXHEXA"
bRet = swModel.DeleteCustomInfo2(tConfig(i), "DESIGNATION 2")
bRet = swModel.DeleteCustomInfo2(tConfig(i), "PROFILS")
bRet = swModel.AddCustomInfo3(tConfig(i), "PROFILS", swCustomInfoText, "POTEAUXHEXA")
'ajoute un propriété personnalisée MASSE avec la valeur Masse
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "masse")
bRet = swModel.AddCustomInfo3(tConfig(i), "masse", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
'ajoute un propriété personnalisée POIDS avec la valeur Masse
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "POIDS")
bRet = swModel.AddCustomInfo3(tConfig(i), "POIDS", swCustomInfoText, Chr(34) & "SW-Mass" & Chr(34))
'ajoute un propriété personnalisée edition avec la valeur MATERIAUX
'Chr(34) permet d'ajouter le caractère "
bRet = swModel.DeleteCustomInfo2(tConfig(i), "MATERIAUX")
bRet = swModel.AddCustomInfo3(tConfig(i), "MATERIAUX", swCustomInfoText, Chr(34) & "SW-Material" & Chr(34))
'on reconstruit la pièces
swModel.ForceRebuild3 False
Set swCustProp = swModelDocExt.CustomPropertyManager(tConfig(i))
'Récupération de la propriété de masse, changer le nom de la propriété en fonction de votre modèle
bRet = swCustProp.Get6("POIDS", False, sValout, sMasse, False, False)
'Conversion du texte en valeur décimale, multiplication x RATIO et conversion en donné de type texte
sVal = CStr(Format(CDec(sMasse) * 0.0556, "0.000"))
'Renseignement de la propriété SURFACE PIECE avec la valeur "sVal"
bRet = swCustProp.Add3("SURFACE PIECE", 30, sVal, 1)
Next i
'Préférences SolidWorks
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinearFractionDenominator, 0, 0)
boolstatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsLinearFeetAndInchesFormat, 0, False)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinear, 0, swLengthUnit_e.swMM)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsDualLinearFractionDenominator, 0, 0)
boolstatus = swModel.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swUnitsDualLinearFeetAndInchesFormat, 0, False)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropVolume, 0, swUnitsMassPropVolume_e.swUnitsMassPropVolume_Meters3)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsLinear, 0, swLengthUnit_e.swMM)
boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropLength, 0, swLengthUnit_e.swMM)
'Enregistre le docuement actif en mode silencieux
bRet = swModel.Save3(swSaveAsOptions_Silent, swErrors, swWarnings)
'Ferme le document actif
swApp.CloseDoc swModel.GetPathName
End If
'boucle jusqu'a ce qu'il n'y ai plus de fichier ouvert dans SW
Loop While Not swModel Is Nothing
End Sub
Odpowiadam sobie znowu!
Zmodyfikowałem makro tworząc na początku tylko config 00, a następnie wypełniając wszystkie właściwości.
Na koniec tworzę wszystkie inne konfiguracje, które przejmują właściwości konfiguracji początkowej.
YIPPEE!!!
Dziękuję za pomoc. Udało mi się skorzystać z twojej rady.