This sounds like an interesting problem to solve. You will get more involvement from the users on here if you begin to tackle this yourself and come here with specific questions when you hit a roadblock. You'll be hard pressed to find someone to just write this all for you as I estimate it could take quite a bit longer than just a few minutes.
Thank you for your words.Definitely these words are motivating me find solution by myself & I am trying as well.
Off course minute will turn to week as I am new in this domain.
Will surely reply you with final solution.
Have you tried recording a macro? If you look around on this forum and/or SOLIDWORKS API helps files, you can find the required puzzle pieces to solve this
Task 1: User can define/select folder. Browse for folder in SW Macro
Task 2: call all parts from folder in assembly & set it at origin Add and Mate Component Example (VBA)
Task 3: Save in same folder with user define name for assembly. Browse for folder in SW Macro
Task 4:Close Solidworks. ExitApp Method (ISldWorks)
Thank you Sir.
Yes few of them I already tried.
I am working on putting all together.
I started writing this and tomorrow it will be finished if you wait for it
Really appreciate your help.
As I am working on this & surely not able to finish in days time.
I am looking forward for your code.
Hello, this is my code, I got to the point where all parts are inserted in new assembly. They are not positioned as their own origin, this needs to be worked on.
My code is not professional. I used GetOpenFileName to get folder name. Solidworks doesn't support open folder dialog box as I know and I didn't want to use any reference not in Solidworks so It got a bit dirty. I explained in the code
Dim swApp As SldWorks.SldWorks
Set swApp = Application.SldWorks
'this is where I used file open dialog box to get file name and folder name
'I search all "\" characters which For Each and InStr thourgh all characters to determine where file name begins, to do that I used InStr and made an array
'to record positions of "\" characters
'after that I used Right and Left method to seperate path and file name to variables
'the reason of this "UBound(fol) - 2)" is that when InStr couldn't find after last "\" character it returns a zero
'I made this changed to "jump1"
'and continues from that to beginning of file string. finds first "\" character again
'I made an if statement to check if any of the array members are same within each other, so when it finds same
'thing it changes that one to "jump2" which is first "\" character
Dim fol() As Variant
Dim Filter As String
Dim fileConfig As String
Dim fileDispName As String
Dim fileOptions As Long
Filter = "SOLIDWORKS Files (*.sldprt)|*.sldprt;"
filepath = swApp.GetOpenFileName("File for Folder", "", Filter, fileOptions, fileConfig, fileDispName)
If filepath <> Empty Then
For i = 1 To Len(filepath)
folsay = folsay + 1
If i >= 2 Then
ReDim Preserve fol(1 To i)
fol(folsay) = InStr(fol(folsay - 1) + 1, filepath, "\")
foltemp = fol(folsay)
For k = LBound(fol()) To UBound(fol()) - 1
If fol(k) = foltemp Then
fol(UBound(fol)) = "jump2"
fol(UBound(fol) - 1) = "jump1"
ReDim Preserve fol(1 To i)
fol(folsay) = InStr(filepath, "\")
filename = Right(filepath, Len(filepath) - fol(UBound(fol) - 2))
folderpath = Left(filepath, fol(UBound(fol) - 2))
'MsgBox filename & vbCrLf & folderpath
'searched through folder's files to check solidworks parts
'opened them one by one and recorded their title to use when adding parts in assembly
Set fol1 = CreateObject("scripting.filesystemobject")
Set fol2 = fol1.GetFolder(folderpath)
Dim swpart As SldWorks.ModelDoc2
Dim err As Long
Dim warr As Long
For Each fi In fol2.Files
If InStr(fi.Name, "sldprt") Then
Set swpart = swApp.OpenDoc6(fi, swDocPART, swOpenDocOptions_Silent, "", err, warr)
orderopen = orderopen + 1
ReDim Preserve opendoc(1 To orderopen)
opendoc(orderopen) = swpart.GetTitle
'I made a new assembly here
'and added components which are opened at the same time and closed them after that
Dim swmodel As SldWorks.ModelDoc2
Dim swasm As SldWorks.AssemblyDoc
Dim longstatus As Long
Dim status As Long
Dim status2 As Long
assytemplate = swApp.GetUserPreferenceStringValue(swDefaultTemplateAssembly)
Dim swcomponent As SldWorks.Component2
Dim swSheetWidth As Double
swSheetWidth = 0
Dim swSheetHeight As Double
swSheetHeight = 0
Set swmodel = swApp.NewDocument(assytemplate, 0, swSheetWidth, swSheetHeight)
activetitle = swmodel.GetTitle
swApp.ActivateDoc2 activetitle, False, longstatus
Set swmodel = swApp.ActiveDoc
Set swasm = swmodel
For alfa = LBound(opendoc) To UBound(opendoc)
Set swcomponent = swasm.AddComponent5(opendoc(alfa), swAddComponentConfigOptions_CurrentSelectedConfig, "", False, "", -1, -1, -1)