Hi there,
I have a part that is mated with a line in a 3D-Sketch. The3D-Sketch is in an assembly. The user selects the part on thescreen and my addin recieves the IComponent2 interface of the part.
How do I get the ISketchLine-Interface of the mated line?
My idea was to examine the mates of the Part by examining thefeature tree of the part. Unfortunately the functions that returnsthe feature tree of the component returns everything except theMateGroup of the part.
I use the same functions that were descibed in the SolidWorks APIHelp "Traversing Assembly at Component and Feature Levels Example"
Thanks in advance,
Matthias SenffSolidworksApi macros

I have a part that is mated with a line in a 3D-Sketch. The3D-Sketch is in an assembly. The user selects the part on thescreen and my addin recieves the IComponent2 interface of the part.
How do I get the ISketchLine-Interface of the mated line?
My idea was to examine the mates of the Part by examining thefeature tree of the part. Unfortunately the functions that returnsthe feature tree of the component returns everything except theMateGroup of the part.
I use the same functions that were descibed in the SolidWorks APIHelp "Traversing Assembly at Component and Feature Levels Example"
Thanks in advance,
Matthias SenffSolidworksApi macros

To set your tree options, right click on the top feature in youtree, which is the name of your part, choose "Tree Display" andthen either "View Features" or "View Mates and Dependencies" thiswill change whether the next item below the part in the tree is afolder or a mate.
I hope this isn't to long of a note.
Hope this helps.
Dan Miel
Option Explicit
Sub main()
Dim swModel As SldWorks.ModelDoc2
Dim swApp As SldWorks.SldWorks
Dim swFeat As SldWorks.Feature
Dim swMateFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swMate As SldWorks.Mate2
Dim swSelMgr As SldWorks.SelectionMgr
Dim comp As SldWorks.Component2
Dim Model1 As SldWorks.ModelDoc2
Set swApp = Application.SldWorks
If swApp Is Nothing Then
Err.Raise 1234, , "Solidworks is gone."
End If
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set comp = swSelMgr.GetSelectedObjectsComponent(1)
If comp Is Nothing Then
Set Model1 = swModel
Else
Set Model1 = comp.GetModelDoc
End If
Set swFeat = Model1.FirstFeature
back:
' Iterate over features in FeatureManager design tree
Do While Not swFeat Is Nothing
If UCase("MateGroup") = UCase(swFeat.GetTypeName) Then
Set swMateFeat = swFeat
Exit Do
End If
Set swFeat = swFeat.GetNextFeature
Loop
If Not swMateFeat Is Nothing Then ' Get first mate, which is asubfeature
Set swSubFeat = swMateFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Set swMate = swSubFeat.GetSpecificFeature2
If Not swMate Is Nothing Then
Debug.Print swMate.MateEntity(0).ReferenceComponent.Name2
Debug.Print swMate.MateEntity(1).ReferenceComponent.Name2
End If
' Get the next mate in MateGroup
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
Else
If Not comp Is Nothing Then
Set comp = comp.GetParent
If comp Is Nothing Then
Set Model1 = swModel
Else
Set Model1 = comp.GetModelDoc
End If
Set swFeat = Model1.FirstFeature
If Not swFeat Is Nothing Then GoTo back
End If
End If
End Sub
Thanks for the answers.
Matthias Senff
set comp = swMate.MateEntity(0).ReferenceComponent you can findcomponent Set ent = swMateEnt(0).Reference you have entity usingfor mate.
I was unaware that SolidWorks assigns the Mates automatically tothe correct assembly if you change the underlying structures sothat you can always reach them by the parents.
When you traverse the FeatureManager Design tree and check themates below each part and assembly, you know which mates belong tothat part. You can then check each mate for broken references.
What I'm saying is that as long as you know that your mates aregood and not invalid you can find the components for the mate likeIvana is doing, but if a ReferenceComponent is suppressed then Idon't think MateEntity will find it.
Dan Miel
This macro should go down the tree and find each component and thenthe mates for that component. It retrieves the information whetherthe components are in folders or not. I wrote this macro so itfinds all parts of all sub assemblies. If you want it to find thetop level only, comment out the line indicated. This prints out thecomponent name the mates to that component and any folder that thecomponents are in.
If you are looking for mates for a particular part you just need toinsert a check that looks for the component name that you want tocheck.
Dan Miel
SW 2008
I try to combine your and Ivanas code to find an efficientsolution.
Matthias Senff