Rename parts in an assembly based on an active variable

Hello 

I would need to rename all the parts of my assemblies that are made of wood. For this part not too much trouble I think because swood creates very specific properties that differentiate the hardware from the rest. 

What solution would you recommend? The idea is to have the assembly that would have a name like XXXXXX-XXXX whose last four numbers are numbers. 

This counter will be incremented for each wood panel that is part of the assembly. 

Is ProjectManager suitable for this type of request or do I need to develop a macro to do it? 

Thank you in advance to all of you:) 

Have a nice day! 

Vincent 


capture.png

With ProjectManager this should be feasible.

Create a rule that replaces the last 4 characters with the ones you want with the condition if the material = wood property

And for the value put an automatic smartcounter counter or something like that.

All you have to do is do some test and you should be fine!

 

Otherwise it's also doable with smartbom + Integration

Smartbom to retrieve a list of csv files with wood ownership

Then integration to make the name change with an incremented counter

2 Likes

Thank you for your answer, 

I tested it effectively I manage to increment the name of my different panels according to the name of the parent. 

On the other hand, the counter does not reset to zero with each assembly processed, do you think it is possible to do this? 

Second remark, when I process an assembly it is in a folder each time that contains (plan, assembly file and parts files). I would like not to have to indicate the destination folder each time but that it takes the file of the assembly processed at the time. 

Thank you in advance for your answers, 

Kind regards

Vincent

I haven't found with a quick search how to reset a counter on each project if @jmsavoyat  go through it will tell us if it's feasible. (I think I've seen a topic on it but I can't find it anymore)

1 Like

Hello

I think you can get away with advanced counters by using an "Auto Counter" that will  reset based on a variable. See https://help.visiativ.com/mycadtools/2021/fr/SmartCounter4.html

Kind regards

3 Likes

Hello 

Finally, I add conditions to renaming parts based on a configuration property that SWOOD creates. 

I have sketched out a macro, but I have trouble understanding correctly how the dialogue with solidworks works. 

I manage to get all the different children that my assembly has. 

Now I would like to succeed in verifying that a property is beautiful and exists in each of them, if so I rename it if not, I move on to the next one. 

Can you help me? I'm posting the beginning of my code. 

Thank you in advance, have a good day. 

 

Dim swApp As Object
Explicit Option

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swAssy As ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim val As String
Dim valout As String
Dim bool As Boolean
Dim Wood As String
Dim Name() As String
Dim list As String
Dim retval() As String
Dim Text As String

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension

If swModel.GetType = swDocASSEMBLY Then

retval = swModel.GetDependencies2(False, False, False)

ReDim name(1 TB ((UBound(retval) - 1) / 2) + 1)
For i = 0 TB (UBound(retval) - 1) / 2

    Set swModelDocExt = swModel.Extension
    Set swCustProp = swModelDocExt.CustomPropertyManager("")
    bool = swCustProp.Get4("SWOODCP_PanelStockLength", True, val, valout)
Debug.Print "Value:                    " & val   
Debug.Print "Evaluated value:          " & valout   
Debug.Print "Up-to-date data:          " & bool   
    text = text & retval(2 * i) & vbCr


Next i
End If
MsgBox (text)

End Sub