I HAVE ONE MADE DRAWING FOR A ASSEMBLY NOW I M TRYING TOASSIGN THE DIFFERENT LAYER TO THE EACH CHILD COMPONENT OF THEASSEMLY WITH THE HELP OF FOLLOWING MACRO, IT IS RUNNING FINE BUT IM FACING ONE PROBLEM...
IN ASSEMBLY THE CHILD COMPONENTS ARE IN THE SEQUENCE OF
TB-1
TB-2
TB-3..SO ON
BUT WHEN I M RUNNING THE MACRO IT PICKING THE CHILD NAME IN RANDOMMANNER SOMETIME FIRST IT PICKS TB-2, THEN TB-5 & SO ON
AS PER MY NEED IT SHOULD PICKS IN SEQUENCE SO CAN ANYBODY TELL WHATSHOLUD I MODIFY IN MACRO SO THAT IT WILL WORK ACCORDING TO MYNEED...
' Preconditions:
' (1) Drawing document is open.
' (2) Drawing view of an assembly is selected.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swDrawComp As SldWorks.DrawingComponent
Dim bRet As Boolean
Dim sPadStr As String
Dim vDrawCompChildArr As Variant
Dim vDrawCompChild As Variant
Dim swDrawCompChild As SldWorks.DrawingComponent
Dim sLayerName As String
Dim q As String
Dim p As String
Dim swLayerMgr As LayerMgr
Dim vLayers As Variant
Dim layer As Variant
Dim retval As Boolean
Dim child As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject5(1)
Set swDrawComp = swView.RootDrawingComponent
Set swLayerMgr = swModel.GetLayerManager
child = ""
'get comp & child name
vDrawCompChildArr = swDrawComp.GetChildren
If Not IsEmpty(vDrawCompChildArr) Then
For Each vDrawCompChild In vDrawCompChildArr
Set swDrawCompChild = vDrawCompChild
'set name of layer
comp = swDrawComp.Name
child = swDrawCompChild.Name
q = Replace(child, comp & "/", "")
a = Right(q, 2)
m = Replace(q, a, "")
'create layer
colour.Show
k1 = colour.k
retval = swDraw.CreateLayer(m, "1", k1, 0, 0, True)
'assign layer
swDrawCompChild.layer = m
Next
End If
swModel.ForceRebuild3 True
swModel.ViewZoomtofit2
End Sub
SolidworksApi macros
IN ASSEMBLY THE CHILD COMPONENTS ARE IN THE SEQUENCE OF
TB-1
TB-2
TB-3..SO ON
BUT WHEN I M RUNNING THE MACRO IT PICKING THE CHILD NAME IN RANDOMMANNER SOMETIME FIRST IT PICKS TB-2, THEN TB-5 & SO ON
AS PER MY NEED IT SHOULD PICKS IN SEQUENCE SO CAN ANYBODY TELL WHATSHOLUD I MODIFY IN MACRO SO THAT IT WILL WORK ACCORDING TO MYNEED...
' Preconditions:
' (1) Drawing document is open.
' (2) Drawing view of an assembly is selected.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swDrawComp As SldWorks.DrawingComponent
Dim bRet As Boolean
Dim sPadStr As String
Dim vDrawCompChildArr As Variant
Dim vDrawCompChild As Variant
Dim swDrawCompChild As SldWorks.DrawingComponent
Dim sLayerName As String
Dim q As String
Dim p As String
Dim swLayerMgr As LayerMgr
Dim vLayers As Variant
Dim layer As Variant
Dim retval As Boolean
Dim child As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject5(1)
Set swDrawComp = swView.RootDrawingComponent
Set swLayerMgr = swModel.GetLayerManager
child = ""
'get comp & child name
vDrawCompChildArr = swDrawComp.GetChildren
If Not IsEmpty(vDrawCompChildArr) Then
For Each vDrawCompChild In vDrawCompChildArr
Set swDrawCompChild = vDrawCompChild
'set name of layer
comp = swDrawComp.Name
child = swDrawCompChild.Name
q = Replace(child, comp & "/", "")
a = Right(q, 2)
m = Replace(q, a, "")
'create layer
colour.Show
k1 = colour.k
retval = swDraw.CreateLayer(m, "1", k1, 0, 0, True)
'assign layer
swDrawCompChild.layer = m
Next
End If
swModel.ForceRebuild3 True
swModel.ViewZoomtofit2
End Sub
SolidworksApi macros

I M STILL WAITING
GetChildren, as you have found, does not return the components inany particular order. If you want them in the order they appear inthe feature tree, you will have to traverse the feature tree. Thereare examples in the API help and/or the API support downloadssection of the SW website.
SO STILL I M NOT ABLE TO DO THIS ..PLEASE EXPLAIN HOW I CAN DO THIS(TRANSERSE TREE)
Dim swApp As SldWorks.SldWorks
Dim swView As SldWorks.View
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swDwgComp As SldWorks.DrawingComponent
Dim swComp As SldWorks.Component2
Dim swViewDoc As SldWorks.ModelDoc2
Dim swFM As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim CurRow As Long
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swDwg = swDoc
Set swView = swDwg.ActiveDrawingView
Set swDwgComp = swView.RootDrawingComponent
Set swViewDoc = swDwgComp.Component.GetModelDoc2
Set swFM = swViewDoc.FeatureManager
Set swFeat = swViewDoc.FirstFeature
Set xlApp = New Excel.Application
xlApp.Visible = True
xlApp.Workbooks.Add
Set xlSheet = xlApp.ActiveSheet
CurRow = 1
While Not swFeat Is Nothing
RecurseIt swFeat, 0
Set swFeat = swFeat.GetNextFeature
Wend
End Sub
Sub RecurseIt(myFeat As SldWorks.Feature, myLevel As Long)
Dim mySubFeat As SldWorks.Feature
Dim SubComp As SldWorks.Component2
Dim SubFeatCount As Long
If (myFeat.GetTypeName2 = "Reference") Or (myFeat.GetTypeName2 ="ReferencePattern") Then
Set SubComp = myFeat.GetSpecificFeature2
xlSheet.cells(CurRow, 1) = myLevel
xlSheet.cells(CurRow, 2) = SubComp.Name2
Set swDwgComp = SubComp.GetDrawingComponent(swView)
swDwg.CreateLayer Replace(swDwgComp.Name, "/", ""), "1",Int((999999 - 2) * Rnd + 2), 0, 0, True
swDwgComp.Layer = Replace(swDwgComp.Name, "/", "")
CurRow = CurRow + 1
Set mySubFeat = SubComp.FirstFeature
While Not mySubFeat Is Nothing
RecurseIt mySubFeat, myLevel + 1
Set mySubFeat = mySubFeat.GetNextFeature
Wend
End If
Set mySubFeat = myFeat.GetFirstSubFeature
While Not mySubFeat Is Nothing
RecurseIt mySubFeat, myLevel + 1
Set mySubFeat = mySubFeat.GetNextSubFeature
Wend
End Sub