Witam
Szukam sposobu na edycję niestandardowych właściwości części z zespołu.
Znalazłem to małe makro w sieci, ale to tylko przeglądarka.
Mam też kilka szablonów makr, które otwierają lub zapisują wybrane komponenty.
Myślałem, że z łatwością znajdę w kodzie części "wybrany komponent" i "otwórz" lub "zapisz", aby zastąpić je "otwartymi właściwościami". spersonalizowane", ale są napisane inaczej, są liczniki, mnóstwo rzeczy, których nie rozumiem, w skrócie nie, nie jest łatwo...
view_properties_of_selected_component_from_assembly.swp
Witam
Oto mały przykład (wykonany w pośpiechu), który powinien Ci pomóc:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Model As ModelDoc2
Dim CompModel As ModelDoc2
Dim swChildComp As SldWorks.Component2
Dim SelectedObject As Object
Dim NbrSelections As Long
Dim i As Long
Dim lErrors As Long
Dim lWarnings As Long
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim myAssy As AssemblyDoc
Dim nInfo As Long
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim val As String
Dim valout As String
Sub main()
Set swApp = Application.SldWorks
Set Model = swApp.ActiveDoc
Set myAssy = Model
Dim SelMgr As SelectionMgr
Set SelMgr = Model.SelectionManager
NbrSelections = SelMgr.GetSelectedObjectCount2(-1)
Set SelectedObject = SelMgr.GetSelectedObject6(1, -1)
If NbrSelections = 1 Then
Set swChildComp = SelectedObject
Set CompModel = swChildComp.GetModelDoc2
bRet = myAssy.EditPart2(True, True, nInfo)
Set swModel = myAssy.GetEditTarget
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
bRet = swCustProp.Add3("MaPropriete", swCustomInfoType_e.swCustomInfoText, "Ma valeur 1", swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
bRet = swCustProp.Get4("MaPropriete", False, val, valout)
Debug.Print "valeur évaluée : " & valout
bRet = swCustProp.Set2("MaPropriete", "Ma valeur 3")
bRet = swCustProp.Get4("MaPropriete", False, val, valout)
Debug.Print "valeur évaluée : " & valout
bRet = swModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)
myAssy.EditAssembly
End If
End Sub
Aby przetestować, należy otworzyć złożenie, a następnie wybrać część w menedżerze funkcji przed uruchomieniem makra (do wykonania na częściach testowych).
Pozdrowienia
1 polubienie
Dziękuję d.roger
Wypróbowałem twoje makro, działa, ale nie jest to dokładnie to, czego się spodziewałem (w rzeczywistości idzie trochę za daleko)
w rzeczywistości twoje makro
- Aktywuj wybrany komponent: dla mnie ok
- Utworzono plik Propriété "Ma propriété", avec la vale " Ma valeur 1" : en fait je voudrais juste ouvrir la fenêtre de propriété personnalisés.
- enregistre (?) et ferme le composant pour retourner a l'assemblage : Idéalement cette opération peut être déclanché à la fermeture de la fenêtre de propriété personnalisés. si non, a faire manuellement, ça sera déjà bien.
Coś takiego:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Model As ModelDoc2
Dim CompModel As ModelDoc2
Dim swChildComp As SldWorks.Component2
Dim SelectedObject As Object
Dim NbrSelections As Long
Dim i As Long
Dim lErrors As Long
Dim lWarnings As Long
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim myAssy As AssemblyDoc
Dim nInfo As Long
Sub main()
Set swApp = Application.SldWorks
Set Model = swApp.ActiveDoc
Set myAssy = Model
Dim SelMgr As SelectionMgr
Set SelMgr = Model.SelectionManager
NbrSelections = SelMgr.GetSelectedObjectCount2(-1)
Set SelectedObject = SelMgr.GetSelectedObject6(1, -1)
If NbrSelections = 1 Then
Set swChildComp = SelectedObject
Set CompModel = swChildComp.GetModelDoc2
bRet = myAssy.EditPart2(True, True, nInfo)
Set swModel = myAssy.GetEditTarget
swModel.FileSummaryInfo
bRet = swModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)
myAssy.EditAssembly
End If
End Sub
Pozdrowienia
2 polubienia
ALLELUJA, ALLELUJA, ALLELUJA! Chwała Tobie, zarówno na lądzie, jak i na morzu!
Czuję, że moim kolegom się spodoba!
Miles, dziękuję D.Roger, zawsze tak wydajny
1 polubienie
Mam jeszcze bardzo małą uwagę: nie działa to poprawnie na podzespołach:
Wygląda na to, że nastąpiło odwrócenie między krokami "otwórz okno właściwości" i "aktywuj wybrany komponent"
Witam
Wypróbuj tę wersję makra:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Model As ModelDoc2
Dim CompModel As ModelDoc2
Dim swChildComp As SldWorks.Component2
Dim SelectedObject As Object
Dim NbrSelections As Long
Dim i As Long
Dim lErrors As Long
Dim lWarnings As Long
Dim swModel As Object
Dim bRet As Boolean
Dim myAssy As AssemblyDoc
Dim nInfo As Long
Sub main()
Set swApp = Application.SldWorks
Set Model = swApp.ActiveDoc
Set myAssy = Model
Dim SelMgr As SelectionMgr
Set SelMgr = Model.SelectionManager
NbrSelections = SelMgr.GetSelectedObjectCount2(-1)
Set SelectedObject = SelMgr.GetSelectedObject6(1, -1)
If NbrSelections = 1 Then
Set swChildComp = SelectedObject
Set CompModel = swChildComp.GetModelDoc2
If CompModel.GetType = swDocumentTypes_e.swDocASSEMBLY Then
myAssy.EditAssembly
End If
bRet = myAssy.EditPart2(True, True, nInfo)
Set swModel = myAssy.GetEditTarget
swModel.FileSummaryInfo
bRet = swModel.Save3(swSaveAsOptions_Silent, lErrors, lWarnings)
myAssy.EditAssembly
End If
End Sub
Pozdrowienia
1 polubienie