Multi Export Assembly and Parts with Structure

Programming and macros
Mmike4
Posts: 1
Joined: Sun Oct 08, 2023 2:18 pm
Answers: 0

Multi Export Assembly and Parts with Structure

Unread post by Mmike4 »

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.
User avatar
Stefan Sterk
Posts: 30
Joined: Tue Aug 10, 2021 2:40 am
Answers: 2
x 42
x 61

Re: Multi Export Assembly and Parts with Structure

Unread post by Stefan Sterk »

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)

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
User avatar
mihkov
Posts: 33
Joined: Sun Feb 05, 2023 2:01 am
Answers: 0
x 14
x 20

Re: Multi Export Assembly and Parts with Structure

Unread post by mihkov »

Mmike4 wrote: Sun Oct 08, 2023 2:26 pm
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.
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()
Remember that the file name and the name in the tree may differ.
Post Reply