Macro composition on the go

Hello

I have a macro that allows me to run multiple commands on Solidworks from an Excel file.

I want to develop this macro by doing a "Composition to go" of an assembly that the macro opens before.

However, I would like to exclude some pieces from the takeaway composition based on their name (those that are in a standard element library) but I can't find the corresponding code.

Here is the link to the code used for the takeaway composition: http://help.solidworks.com/2012/English/api/sldworksapi/Pack_and_Go_an_Assembly_Example_vb.htm

Do you know how to exclude parts from a line of code?

Thank you

Hello

See this answer in VB.NET:

https://forum.solidworks.com/thread/53030

Or here in VBA:

https://forum.solidworks.com/thread/109556

https://cloud.centralinnovation.com.au/sharpcode/index?article=Exclude-files-from-Pack-n-Go

 

.PL

Thank you for your answer which seems to correspond to what I am looking for.

When composing to go, I want to exclude pieces with "Bride" in the name.

However, I want to save the pieces in a new repertoire.

So I have to mix the two codes but I can't do it.

Can you help me?

Thank you.

I tried with the code as an attachment but all the parts (even the ones with the name "Bride") are created in the new folder.


compo.txt

I would like to do as in this video but with the help of the macro:

https://youtu.be/vJgcFBKF49E

Do you think it's possible?

Attach your code to your message explaining what the error is or which line the macro is crashing at.

The code is in the text file of the previous message.

And as said in the message, the macro runs correctly but no piece is excluded from the takeaway composition.

Sorry, I hadn't seen.

I'm looking at that.

Can you tell me in which part of your code you did the exclusion please?

It is in this part that the exclusion should be made:

Dim swModel As SldWorks.ModelDoc2
Dim swPackAndGo As SldWorks.PackAndGo
Set swApp = Application.SldWorks
    
    Set swModel = swApp.ActiveDoc
    
    If swModel.GetPathName() <> "*Bride*" Then

With at the end

    Else
        
        MsgBox "Please save the document"
        
    End If

In what link did you see that exclusion was done like that?

Hello

 

In this link: https://cloud.centralinnovation.com.au/sharpcode/index?article=Exclude-files-from-Pack-n-Go

But I don't think I'm using it in the right way because, as I understand it, the excluded components are the ones that contain in their name part of the assembly name. However, I would like to exclude components that contain specific text.

In the link you put in, the exclusion is done like this:

 

Const SEARCH_TEXT As String = "BRIDE"

If InStr(1, name, SEARCH_TEXT, vbTextCompare) > 0 Then

newDocNames(i) = ""

Else

newDocNames(i) = name

End If

 

So it's not the same as what you wrote!

1 Like

Indeed it works better that way!

I'm still working on the code to exclude a second string before integrating it into the Solidworks API code to be able to choose the destination folder of the composition to take away.

Thank you for your help.PL

1 Like