for my project i need a code to extract the topological relationship between components in assembly and their assembly sequence
this data is used to generate a process planning for my project
Basically, you're asking us to do your work.
Is that it?
basically am mechanical engineer and i am new to api, so help me how to proceed
Generating component data from an assembly is a complex problem to work on. You need to traverse the feature manager design tree to get each feature from the assembly and check whether the feature is a component. Then you can populate data for each component.
The complexity in this case can be attributed to the fact that an assembly component can itself be a sub-assembly and hence may have more components.
Here are certain Classes which can help you in generating requisite data: -
Hope this helps!!!
hi Rajat Jain
thanks for your reply.
OK, you can achieve that with this example (vb.Net): I don't know if it has any errors, as I wrote it without debugging.
Public Sub GetTree() Dim swModel As ModelDoc2 = iSwApp.ActiveDoc Dim activeConfig As Configuration = swModel.ConfigurationManager.ActiveConfiguration Dim rootComp As Component2 = activeConfig.GetRootComponent3(True) Traverse(rootComp) End Sub
Public Sub Traverse(ByVal swComp As Component2) Debug.Print("Component name: " & swComp.Name2)
Dim firstLevelChildrenComps As Object = swComp.GetChildren() If Not firstLevelChildrenComps Is Nothing Then For Each swChildComp As Component2 In firstLevelChildrenComps If Not swChildComp.GetSuppression = swComponentSuppressionState_e.swComponentSuppressed Then Traverse(swChildComp) End If Next End If End Sub
nice code! Thanks for sharing...!
FYI...I ran it...no tweaking needed! lool...
I've been traversing components this whole time...I LOVE this way of getting the tree!
hi Eduardo Brites,
thanks for your reply..
i run this macro in solidworks 2008 but it shows some error in the line "Set rootComp = activeConfig.GetRootComponent3(True)"
i attached the error wat it shows .
plzz do help me..
Dim swModel As SldWorks.ModelDoc2 Dim activeConfig As SldWorks.Configuration Dim rootComp As New SldWorks.Component2 Dim swApp As SldWorks.SldWorks
Public Sub GetTree() Set swApp = CreateObject("SldWorks.Application") swApp.Visible = True Set swModel = swApp.ActiveDoc Set activeConfig = swModel.ConfigurationManager.ActiveConfiguration Set rootComp = activeConfig.GetRootComponent3(True) Traverse (rootComp) End Sub
Public Sub Traverse(ByVal swComp As Component2) Debug.Print ("Component name: " & swComp.Name2) Dim firstLevelChildrenComps As Object Dim swChildComp As Component2 Set firstLevelChildrenComps = swComp.GetChildren() If Not firstLevelChildrenComps Is Nothing Then For Each swChildComp In firstLevelChildrenComps If Not swChildComp.GetSuppression = swComponentSuppressionState_e.swComponentSuppressed Then Traverse (swChildComp) End If Next End If End Sub
Use GetRootComponent() instead, the GetRootComponent3() is only available in Solidworks 2010 and above.
hi Eduardo Brites
hi i don know why this error"Set rootComp = activeConfig.GetRootComponent(True) "comes in this line plz clarify ....
it gets the first available component for the current configuration to then strart traversing.
The GetRootComponent does not require any paramaters like GetRootComponent3 did...so you need to delete that boolean value (true) from your code.
Set rootComp = activeConfig.GetRootComponent()
Retrieving data ...