I'm looking for a macro that can re-edit all library functions in a part at once in order to refresh the changes in that library in SOLIDWORKS

hello, I'm looking for a macro capable of re-editing all the library functions in a room at once in order to update the changes in this library, (most of the time the "link to the library part" box is grayed out 

 It often happens that I create library functions to go faster, but the problem is that often there are a hundred per part and when I have to make a change for example a drilling diameter that needs to be narrowed or enlarged  or a chamfer to be added, I have to reprint all the library functions one by one in order to update this change on the whole room  which can take hours 

I unfortunately don't know how to write macro so I turn to this forum to find a charitable soul who could explain to me how to do it or write one 

A few screenshots of an example would surely make it easier to understand your topic.

Because I didn't understand everything.

On the other hand, a hundred library functions in my opinion can only weigh down the room.

difficult to explain with screenshots, 

for example;   I have a piece including cubes with a cylinder on them with a chamfer on the edge of the cylinder, I create a library function allowing to quickly create this shape by clicking on a few vertices, so I arrange this library all over a part, later I am asked to replace the chamfer with a fillet, So I change it in the SLDLFP file, then, in order to update this change in my part I have to doubleclick on each of my bibli functions and click once in the config area of the bibli then press enter, this allows the library function to apply the changes I made in the sldlfp, The problem is that I have to do this for each function of bibli that are in  my room  

 

When I say a hundred it's often about 30  per piece on several parts of an assembly, but the heaviness of the part is not so much of a problem if it's too heavy I divide it into several parts  

 


cature_1_.png
capture_2.png

Hello

To change a common dimension, there are variables/equations.

But in the case of the example, why not instead apply the function to a single element and repeat the resulting field?

1 Like

in fact none of the squares on which I place the library has the same dimension/curvature  and the library allows me to create a shape that adapts to the structure on which I place  it repetition is not a solution, and as far as the equation variables are concerned, I already use them but it doesn't work if I add a function to the library or change for example a chamfer by a fillet, moreover a large number of equations slows down the part 

 

in any case thank you for the speed of your answers 

I'm attaching a screenshot that may allow you to better understand why I can't do a rehearsal


capture_3.png

Actually...

You already have a chance, it's that at home the function is updated. Not at home, I have to reimport it from the library... or something escapes me.

1 Like

What I don't really understand is how to update.

A CTRL+Q is not enough? You have to edit each library function and validate? (right click on the bibli function + enter)

Otherwise you have this macro that rebuilds everything automatically.

https://www.codestack.net/solidworks-api/document/macro-feature/run-macro-on-rebuild/

Maybe to test or otherwise for library functions it's library feature.

 

 

Some examples of macros with library features:

https://help.solidworks.com/2018/English/api/sldworksapi/Create_Library_Feature_With_References_Example_VB.htm

 

Another example for reading information from a library function:

https://help.solidworks.com/2016/English/api/sldworksapi/Get_Library_Feature_Data_Example_VB.htm

more precisely when I want to refresh a library I right click edit the function, then I click in the area where normally the different configs of the library are located, a warning window appears, click on Yes (or I press Enter it comes back to the same) and there, the modifications apply

 

In the attached video, I don't know why but you don't see the warning window when I click in the config  area so I put it in a screenshot 

about the macro that automatically rebuilds everything given by @sbadenis  I didn't manage to get it to work and the CTRL+Q only rebuilds the functions of the part but doesn't take into account the library modification

 


piece1.sldprt_2022-05-24_14-25-02.mp4
capture_4.png

sorry @sbadenis but I don't understand the usefulness of this macro:

'' Another example to read the information of a library function:

https://help.solidworks.com/2016/English/api/sldworksapi/Get_Library_Fea... ''

 

I found a topic evoking my problem but unfortunately there is no real solution in the answers 

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

Try this I don't have a library function on hand to test,  it's the previous macro with maybe the update of the function if I understood correctly:

'-------------------------------------------------------------
' Preconditions:
' 1. Open a model document that contains at least one
'    library feature.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Traverses the FeatureManager design tree searching for
'    library features.
' 2. Gets each library feature's data.
' 3. Inspect the Immediate window.
'-------------------------------------------------------------
Option Explicit

Dim boolstatus As Boolean
Dim swApp As SldWorks.SldWorks
Dim ModelDoc2 As SldWorks.ModelDoc2
Dim Feature As SldWorks.Feature
Dim NextFeature As SldWorks.Feature
Dim LibraryFeatureData As LibraryFeatureData
Dim placementPlaneType As Long
Dim placementPlane As Object
Dim ConfigurationName As String
Dim vConfigs As Variant
Dim vConfigName As Variant
Dim x As Long
Dim LinkToLibraryPart As Boolean
Dim LocatingDimensionsCount As Long
Dim vLocDimName As Variant
Dim vLocDimVal As Variant
Dim i As Long
Dim bOverrideDimVal As Boolean
Dim SizeDimensionsCount As Long
Dim vSizDimName As Variant
Dim vSizDimVal As Variant
Dim ReferencesCount As Long
Dim vRefType As Variant
Dim vRefName As Variant
Dim vRefs As Variant
Dim status As Boolean


Sub main()

Set swApp = Application.SldWorks
Set ModelDoc2 = swApp.ActiveDoc

' Traverse the FeatureManager design tree searching for library features
Set Feature = ModelDoc2.FirstFeature

While Not Feature Is Nothing

    Debug.Print Feature.Name, Feature.GetTypeName

    ' If feature is a library feature, then get its data; otherwise,
    ' move onto the next feature in the FeatureManager design tree

    If Feature.GetTypeName = "LibraryFeature" Then
        Debug.Print ""
        Debug.Print Feature.Name, Feature.GetTypeName
        Set LibraryFeatureData = Feature.GetDefinition
        boolstatus = LibraryFeatureData.AccessSelections(ModelDoc2, Nothing)

        ' Access the selections of the library feature that define it
        Debug.Print "LibraryFeatureData.AccessSelections = " & boolstatus

        ' Get its placement type
        Set placementPlane = LibraryFeatureData.GetPlacementPlane2(swLibFeatureData_e.swLibFeatureData_PartRespect, placementPlaneType)
        Debug.Print "PlacementPlaneType = " & placementPlaneType
        placementPlane.Select False

        ' Get the name of the active library feature configuration
        ConfigurationName = LibraryFeatureData.ConfigurationName
        Debug.Print "ConfigurationName = " & ConfigurationName
                        

        ' Determine if the library feature is linked to
        ' the library feature part
        LinkToLibraryPart = LibraryFeatureData.LinkToLibraryPart
        Debug.Print "LinkToLibraryPart = " & LinkToLibraryPart
        

        ' If the library feature part document is open or
        ' if the library feature is linked to the library feature
        ' part document, then get the names of all of the
        ' library feature configurations; if neither,
        ' then only the name of the active library configuration
        ' is returned
        'vConfigs = LibraryFeatureData.GetAllConfigurationNames
        'Debug.Print "Configuration names :"

        'If Not IsEmpty(vConfigs) Then
            'For x = LBound(vConfigs) To UBound(vConfigs)
                'Debug.Print "  " & vConfigs(x)
            'Next x
        'End If

        ' Get the number of locating dimensions
        'LocatingDimensionsCount = LibraryFeatureData.GetDimensionsCount(0)
        'Debug.Print "LocatingDimensionsCount = " & LocatingDimensionsCount

        ' Get the locating dimensions
        'vLocDimVal = LibraryFeatureData.GetDimensions(0, vLocDimName)
        'Debug.Print "Locating dimensions :"

        'If Not IsEmpty(vLocDimName) Then
            'For i = LBound(vLocDimName) To UBound(vLocDimName)
                'Debug.Print "  " & vLocDimName(i), vLocDimVal(i)
            'Next i
        'End If

        ' Determine if existing dimension values of the library
        ' feature can be overridden
        'bOverrideDimVal = LibraryFeatureData.OverrideDimension
        'Debug.Print "OverrideDimension = " & bOverrideDimVal

        ' Get the number of feature dimensions
        'SizeDimensionsCount = LibraryFeatureData.GetDimensionsCount(1)
        'Debug.Print "SizeDimensionsCount = " & SizeDimensionsCount

        ' Get the feature dimensions
        'vSizDimVal = LibraryFeatureData.GetDimensions(1, vSizDimName)
        'Debug.Print "Size dimensions :"
        'If Not IsEmpty(vSizDimName) Then
            'For i = LBound(vSizDimName) To UBound(vSizDimName)

                'Debug.Print "  " & vSizDimName(i), vSizDimVal(i)
            'Next i
        'End If

        ' Get the number of references
        'ReferencesCount = LibraryFeatureData.GetReferencesCount
        'Debug.Print "GetReferencesCount = " & ReferencesCount

        ' Get the references
        'vRefs = LibraryFeatureData.GetReferences3(swLibFeatureData_e.swLibFeatureData_PartRespect, vRefType, vRefName)
        'If Not IsEmpty(vRefType) Then
            'Debug.Print "Reference types and names: "
            'For i = LBound(vRefType) To UBound(vRefType)
                'Debug.Print "  " & vRefType(i) & ", " & vRefName(i)
                'vRefs(i).Select False
            'Next i
        'End If

        'Release the selections that define the library feature
        LibraryFeatureData.ReleaseSelectionAccess

        ' Update the definition of the library feature
        status = Feature.ModifyDefinition(LibraryFeatureData, ModelDoc2, Nothing)
    
    
    End If

    ' Get the next feature until there are no more
    Set NextFeature = Feature.GetNextFeature
    Set Feature = Nothing
    Set Feature = NextFeature
    Set NextFeature = Nothing

Wend

End Sub

 

I can't get it to work 

 

I'm attaching the part and the library (small clarification is that I use a lot of different library functions that don't all have the same references to be placed) 

 

One idea would be to link a bibli configuration to a part configuration, this would allow, by changing the config, to reload the library 


Part1.SLDPRT
carre_-__a.sldlfp

Hello @josé2fois,

A first approach, by taking up the idea of the configurations of the library function.
If the changes within this function are limited to "making a change, for example a drilling diameter that needs to be narrowed or enlarged, or a chamfer to be added", the principle is to make these changes in a new configuration of the same library function.

Then, via the attached macro (Biblifunction.swp), all the configurations concerned by the modification are replaced by this new configuration. In a way, a macro searches for and replaces a configuration in a library function.
The macro also forces the link to the SLDLFP file of the library function.

To use, you must fill in 3 strings of characters:
- the name of the library function (in your example "square -  A")
- The name of the configuration to be replaced. I've set 3 of them for my tests in your example: "A_défaut", "Fillet", and "Chamfer". An empty string processes all occurrences of configurations.
- The name of the replacement configuration, containing the changes.

This macro only works on this principle of replacing the config, on a SolidWorks part, and does not allow you to change references, dimensions, etc...
Use with caution, there are few (no) guardrails and no cancel function.
It's all in the enclosed zip, in SW 2021 version.

Kind regards.


fonctionbibli.zip
2 Likes

@m.blt   THANK YOU THANK YOU THANK YOU !!

It works like God!

It's fantastic, I'll finally be able to really enjoy the benefits of the library features