I was wondering if anyone had a macro that could dig through an assembly and delete all mates of all parts and subassemblies and then add a fixed mate to everything.
I need it in my simplification process.
Check this macro: Remove all mates and fix components in SOLIDWORKS assembly. It removes the mates and suppresses all children on the top assembly, but you can run it through xBatch to repeat for sub-assemblies.
I don't have a macro that does the job you specifically need, but I have a couple that could be modified. I don't delete the mates when I fix an item since they get suppressed, but a good starting point would be listing all the items in the feature tree. Sometimes I include the type if that will help with the selection manager.
Set swApp = Application.SldWorksSet swModeler = swApp.GetModelerSet swModel = swApp.ActiveDocSet swModelDocExt = swModel.ExtensionSet swFeatMgr = swModel.FeatureManagercount = swFeatMgr.GetFeatureCount(False)featArr = swFeatMgr.GetFeatures(False)Set swSelMgr = swModel.SelectionManager
Dim i, t
i = 1
Do Until i = count Debug.Print featArr(i).Name & " " & i ' Debug.Print featArr(i).Name & " " & featArr(i).GetType & " " & i
i = i + 1Loop
MsgBox "Process Complete!"
I usually work from here to select the items in the feature tree by adding in a line to start work after the origin has been found.
If featArr(i).GetTypeName = "OriginProfileFeature" Then i = i + 1 ' Adding one here moves passed the origin an onto the features/components.
This is part of a macro that hides all the items in the feature tree. My loop stops at mates, so I don't normally process them. I cycle back after everything is hidden and reveal only one feature at a time and do additional work.
doc_split = Split(doc_nam, "\")doc_count = UBound(doc_split)
assemble = doc_split(UBound(doc_split)) las = Len(assemble) - 7 abbrev = Left(assemble, las) obnam = featArr(i).Name & "@" & abbrev bRet = swModel.Extension.SelectByID2(obnam, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
You could replace HideComponent2 with FixComponent.
You just need to figure out how to delete all the mates.
Hope it helps.
Thanks to both of you.
I agree with Danniel, that mates usually get suppressed after the component is fixed.
But sometimes (I don't know why), the mates don't get suppressed and I get a bunch of red and yellow in my feature tree .
Does anyone know why this happens?
Retrieving data ...