Slt, I'm looking for a macro to rename my drawing tabs

Hello 

I'm looking for a macro that I could customize and that would allow me to look for a property of the model in my active view and once captured, rename the sheet according to this property for all the sheets. We make drawings that include several parts with engraving numbers and it is this engraving number that I would like to import in order to name the tab of my drawing. If you have something, please let me know. Thank you so much! (we are on SW 2016)

 

Eric

2 Likes

Hello

See if it can help you...

http://www.lynkoa.com/tutos/macro-solidworks-renommer-feuille-1-de-la-msie-en-plan

1 Like

I found another one that should work... You may have to change the code to put your function (engraving number)...

I found it here in the last post:

http://www.forum-cao-3d.fr/api-questions/renommer-feuille-mep-solidworks-t12546.html


rename_all_sheetsconfiguration.swp
1 Like

Hello

Would it be easier to capture a piece of data directly in my drawing and ask that the macro rename the sheet according to this data? Because in the end the number I'm interested in automatically writes in my cartridge! I just find it abont that Dassault is not thinking of integrating this option directly into the leaf properties!!!

Thank you

Thank you for your answer cobra, but I already had this macro but it doesn't take a direct property in the part itself, but either the config name or the part name:(

A silly thing, but if you read this property in the name of the config it should work...

Hello

To retrieve the property in the title block, the easiest way is to loop over the annotations.

Basically, you have to use this type of loop:

    Set swView=swDraw.GetFirstView ' Declaration to enable the basemap
     Set swNote = swView.GetFirstNote
    swModel.ClearSelection2 (True)
    Do While Not swNote Is Nothing
        Set swAnn = swNote.GetAnnotation
        sValue = "$PRPSHEET:""" & Num_Gravage & """" ' Put the name of the property you are looking for
        If swNote.PropertyLinkedText = sValue Then
                swSheet.SetName (swNote.GetText)
                Exit Sub
        End If
        swModel.ClearSelection2 (True)
        Set swNote = swNote.GetNext
    Loop
 

 

Well, thank you Ceril, but as I'm not a VBA programmer, I'm not too sure where and how to insert your line, here is the code I'm trying to adapt to my needs! If you could give me a hand, that would be great. Thank you

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSheet As SldWorks.Sheet
Dim swModelview2 As Configuration
Dim ConfigName As String
Dim vSheets As Variant
Dim swView As SldWorks.View
Dim i As Integer

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

vSheets = swModel.GetSheetNames
For i = 1 TB swModel.GetSheetCount
swModel.ActivateSheet vSheets(i - 1)
Set swSheet = swModel.GetCurrentSheet
Count = swModel.GetModelViewCount

Set swView = swModel.GetFirstView

Do While Not swView Is Nothing
ConfigName = swView.ReferencedConfiguration
Set swView = swView.GetNextView
Loop
swSheet.SetName ConfigName
Next i

swModel.EditRebuild3
swModel.Save2 False
    
End Sub

1 Like

Hello

Attached is the code that corresponds. All that remains is to enter the name of the property sought.

 


renommage_feuille.txt

I made a small mistake, for the processing of several sheets, replace exit sub by exit do in this part:

If swNote.PropertyLinkedText = sValue Then
                swSheet.SetName (swNote.GetText )
                swModel.EditRebuild3
                swModel.Save2 False
                Exit Do

1 Like

At the top Cyril! Thank you very much for your help!!

1 Like

Hello, relative to this new macro, is there a  way to tell it that the note in which the info I am looking for to rename my tabs is found actually contains more than one property?

The note is composed of 2 properties to form my final number, and I don't know how to tell it the &!

To sum up, how can we tell him to copy the note that contains this property and this property?

Thank you for your help, I suck at VBA:)

 

Eric

Hello

In the code, replace the line sValue = "$PRPSHEET:"""Num_Gravage""" 'Put the name of the property you are looking for with:

sValue = "$PRP:""Num_gravage"""" & "$PRP:"Other"""" &"   "'Enter the name of the property you are looking for"

If there is nothing between the two properties in the content of the annotation, remove the first & " ":

sValue = "$PRP:""Num_gravage""" & "$PRP:""Other"""" &" 

Hello Cyril,  Here's what I did, but it doesn't work?!

    Do While Not swNote Is Nothing
        Set swAnn = swNote.GetAnnotation
        sValue = "$PRPSHEET:""No Drawing""" & "$PRPSHEET:""No Piece (Drawing)"""  'Put the name of the property you are looking for'
        If swNote.PropertyLinkedText = sValue Then
                swSheet.SetName (swNote.GetText)
                swModel.EditRebuild3
                swModel.Save2 False
                Exit Do
        End If
        swModel.ClearSelection2 (True)
        Set swNote = swNote.GetNext
    Loop
Next
End Sub

I have only copied here the section that interests us.

$PRPSHEET or only $PRP?

 

Thank you

Eric

Hello, it doesn't matter PRP or PRPSHEET, it depends on where the property is taken from.

It is absolutely necessary to use the & " " at the end of the sValue, i.e.:

sValue = "$PRPSHEET:""No Drawing""" & "$PRPSHEET:""No Piece (Drawing)"""  & "