I´m trying to write a macro to export a whole assembly with full structure (Subfolders for Subassemblies) into different Formats (PDF/STEP/DWG)
My Idea is to use the Traverse Assembly Code from the Solidworks API help to create a List with the Structure and all Names. Then open the first file, check if it is a part or an assembly, create a subfolder if needed, and export the files.
My Problem is that the exported list contains the Instance ID from every part and assembly.
The list looks like this:
9805092275-4
9805092275-4/3130061202-3
9805092275-4/9801060882-1
9805092275-4/3130061202-2
But I want it to look like this :
9805092275
9805092275/3130061202
9805092275/9801060882
9805092275/3130061202
Any Ideas on how to fix that other that rearranging the whole String?
A similar Macro would help too if you have seen something like that already.
Thanks for your help.
Multi Export Assembly and Parts with Structure
- Stefan Sterk
- Posts: 37
- Joined: Tue Aug 10, 2021 2:40 am
- x 51
- x 77
Re: Multi Export Assembly and Parts with Structure
Hi @Mmike4
Here is a example on how you could get the name without the instance ID.
Copy component name to the component reference using SOLIDWORKS API (codestack.net)
Here is a example on how you could get the name without the instance ID.
Copy component name to the component reference using SOLIDWORKS API (codestack.net)
Code: Select all
'**********************
'Copyright(C) 2023 Xarial Pty Limited
'Reference: https://www.codestack.net/solidworks-api/document/assembly/components/name-to-component-reference/
'License: https://www.codestack.net/license/
'**********************
compName = swComp.Name2
If swComp.IsVirtual() Then
'if virtual remove the context assembly name
compName = Left(compName, InStr(compName, "^") - 1)
Else
'remove the index name
compName = Left(compName, InStrRev(compName, "-") - 1)
End If
Re: Multi Export Assembly and Parts with Structure
Stefan Sterk option is the best. You'll have to track down duplicates now.
There is an alternative option: you can get the component file name from the full path to the file. You can get the full path like this:
Code: Select all
Dim swComp As IComponent2
Dim value As System.String
value = swComp.GetPathName()