Property Intelligence Macro

Hello

In my company, we call our pieces: Nomdeprojet_Numérodepièce_Révision.

I want to make a Solidworks macro that will allow me to fill in the "ProjectName" properties (first 7 characters or anything before the first "_") and "PartNumber" (characters in between the two "_") of a part in the custom property.

Could you help me with the code because I'm a real beginner when it comes to macros, or if a simpler method exists.

 

Thank you

 

Quentin

Hello

It's not in Solidworks, and not exactly what you're looking for, but it can help you with the macro.

In my case, the file name is as follows: désignationdelapièce__référence

The reference always has 8 characters.

 

/*Searching for the separator
separator=search(rel_model_name(),"__")
/* test the presence of the separator
if separator >0
/*Extracting the designation
designation=extract(rel_model_name(),1,(separator-1))
/*Retrieve the reference
reference=extract(rel_model_name(),(separator+2),8)
else
designation=rel_model_name()
reference="...-.... "
endif

 

S.B

Thank you

I succeeded thanks to an open forum topic, if that helps:

 

 

Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

 
Sub main()

 
    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

 
    'Check and Add/Update PartNo Property
   
    If swModel.CustomInfo("_ToolingNo") = "" Then

      swModel.AddCustomInfo2 "_ToolingNo", swCustomInfoText, Left(swModel.GetTitle, 7)

    Else

        swModel.CustomInfo("_ToolingNo") = Left(swModel.GetTitle, 7)

    End If

 
    'Check and Add/Update Revision Property
  
    If swModel.CustomInfo("_Position") = "" Then

      swModel.AddCustomInfo2 "_Position", swCustomInfoText, Mid(swModel.GetTitle, 9, 5)

    Else

        swModel.CustomInfo("_Position") = Mid(swModel.GetTitle, 9, 5)

    End If

 
    'Check and Add/Update Description Property

    If swModel.CustomInfo("Revision") = "" Then

      swModel.AddCustomInfo2 "Revision", swCustomInfoText, Mid(swModel.GetTitle, 15, 2)

    Else

        swModel.CustomInfo("Revision") = Mid(swModel.GetTitle, 15, 2)

    End If

 
End Sub