J'ai ce bout de code qui fonctionne chez moi, vois au niveau de ta ligne boolstatus, dans la première partie. Je ne comprends pas le "/"... tu n'es pas en train d'éditer un composant?
Edit : Tu dois avoir : "Configuration@nomfichier.extension"
Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long
Dans ton code toi tu changes juste la config de ton assemblage ?
Pour ma part la structure de mon 3D est la suivante:
* Assemblage principal (.SLDASM)
* Sous ensemble (.SLDASM)
* composant (.part)
* composant (.part)
* composant(.part)
* divers composants (.part)
Moi j'aimerai que le code change la configuration d'un composant (.part) dans mon sous ensemble (.SLDASM) tout en étant dans mon assemblage principal (.SLDASM).
J'espère que mon explication est compréhensible...
Le code ci-dessous sélectionne un composant niveau -2 et modifie la configuration de celui-ci.
MAIS il y a un bug..... la configuration qu'il affiche n'est pas celle que je lui demande ??!?
Vois ce que ça donne chez toi avec les bons chemins et dis-moi. (c'est aussi le bazard dans les déclarations, pas pris le temps de faire le ménage....)
Dim swApp As SldWorks.SldWorks Dim swAssy As SldWorks.assemblyDoc Dim swSelMgr As SldWorks.selectionMgr Dim swModel As SldWorks.ModelDoc Dim swComp As SldWorks.Component Dim ConfigMgr As ConfigurationManager Dim instance As ISelectionMgr Dim Index As Integer Dim Mark As Integer Dim boolstatus As Boolean Dim modelDoc2 As SldWorks.modelDoc2 Dim assemblyDoc As SldWorks.assemblyDoc Dim featureMgr As SldWorks.FeatureManager Dim modelDocExt As SldWorks.ModelDocExtension Dim selectionMgr As SldWorks.selectionMgr Dim feature As SldWorks.feature Dim selObj As Object Dim feat As SldWorks.feature Dim folderFeat As SldWorks.feature Dim errors As Long Dim warnings As Long Dim status As Long Dim count As Long Dim Value As SldWorks.Component2 Dim componentsToMove() As Object Dim i As Long Dim retVal As Boolean Dim RefCfg As String
Sub main()
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swAssy = swModel Set swSelMgr = swModel.SelectionManager Set ConfigMgr = swModel.ConfigurationManager Set modelDoc2 = swApp.ActiveDoc Set assemblyDoc = modelDoc2
'Select component Set modelDocExt = modelDoc2.Extension Set selectionMgr = modelDoc2.SelectionManager status = modelDocExt.SelectByID2("testEUT15B0178'015 S-E VERIN D'APPUI-1@Assemblage1/testJOINT TORIQUE STD-2@testEUT15B0178'015 S-E VERIN D'APPUI", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0) Set selObj = selectionMgr.GetSelectedObject6(1, -1) Set Value = selectionMgr.GetSelectedObjectsComponent4(1, -1)
' Show Config1 and make it the active configuration Value.ReferencedConfiguration = "JOINT TORIQUE Ø24xØ1.5"
C'est presque ça mais il n'appelle pas la bonne configuration ...
Set swApp = CreateObject("SldWorks.Application") Set Part = swApp.ActiveDoc
Set swApp = _ Application.SldWorks
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swModelDocExt = swModel.Extension Set swSelMgr = swModel.SelectionManager
Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swAssy = swModel Set swSelMgr = swModel.SelectionManager Set ConfigMgr = swModel.ConfigurationManager Set ModelDoc2 = swApp.ActiveDoc Set AssemblyDoc = ModelDoc2
'Select component Set modelDocExt = ModelDoc2.Extension Set SelectionMgr = ModelDoc2.SelectionManager Status = modelDocExt.SelectByID2("CleanSeal COMPLETE-1@Assemblage1/Cxxx-x-2@CleanSeal COMPLETE", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0) Set selObj = SelectionMgr.GetSelectedObject6(1, -1) Set Value = SelectionMgr.GetSelectedObjectsComponent4(1, -1)
' Show Config1 and make it the active configuration Value.ReferencedConfiguration = "Cxxx-x C250-0"