Edit all the parts of an assembly one by one to apply a macro?

Hello

I have a macro that allows me to fill in information from each piece based on the file name. The problem is that for the moment I have to run this macro part by part and I would just like to know the function to repeat this task for all the parts of the assembly.

Thank you!

Hello

1. Could you share your macro with us in case other members have this problem?

2. If I understand correctly, you want to run the macro from the assembly?

1 Like

Hello

I made this type of macro a while ago, see the attached example.

It is certainly to be modified and refined for your needs, but may be able to help.

A+


remplprop.swp

Yes, it's possible if you have the MycadTools suite.

You can use the INTEGRATION utility to run your macro on a series of files.

1 Like

Hello

In order to retrieve the list of components of an assembly, you must use the GetDocumentDependencies2 function.

More info here: http://help.solidworks.com/2015/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~getdocumentdependencies2.html

For example, in an app in VB.net, I do the following

Statements:

    Dim Application_SW As SldWorks.SldWorks
    Dim Model_SW As SldWorks.ModelDoc2
    Dim Component_SW As SldWorks.Component2
    Dim Nom_fichier_SW As String
    Dim Liste_dependances As Object

 

Function Code:

    Function Acquisition_dependences(ByRef Chemin_assemblage_SW as string) as object
        Dim Type_fichier_SW As Integer = 2
        Application_SW. OpenDoc6(Chemin_assemblage_SW, Type_fichier_SW, 0, "", longstatus, longwarnings)
        Model_SW = Application_SW. ActiveDoc
        Nom_fichier_SW = Model_SW. GetPathName
        Return Application_SW. GetDocumentDependencies2(Nom_fichier_SW, True, True, False)
    End Function

 

Then you use the following code to execute the function:

Liste_dependances = Acquisition_dependences(Chemin_de_ton_fichier_ASM)

This returns an array of strings in the following form:

"If you use this method with an assembly that contains two documents, Part1 and SubAssem1, an example of what might be returned is:

 [ "Part1", "C:\temp\Part1.SLDPRT", "SubAssem1", "c:\temp\SubAssem1.SLDASM" ]

 

Hoping to have helped you

1 Like

Thank you very much for your answers!

I'm attaching the macro to you in attachment!


custom-properties-automatic-naming-v3_description.swp

If your problem is solved, please select the best answer.

@remem: This function only returns the list of dependent shares, doesn't it? Is it possible to apply a macro to the returned array? 

I admit that I'm struggling a little bit: I have to replace "Nom_fichier_SW" with the name of the file I want to process,  right?

An error message appears for the penultimate line, the return, I'm attaching a screenshot.

Sorry that's a lot of questions, I hope you'll have time to help me


capture.png
1 Like

@julien.Bonus:

You changed the function when you shouldn't do it as I see in your screenshot.

Copies the code of the declarations as well as the code of the function without modifying them.

Then in the call line of the function: Liste_dependances = Acquisition_dependences(Chemin_de_ton_fichier_ASM)

Only edit the italicized part by indicating the path of your assembly.

1 Like