I have a situation that comes up from time to time where a number of sheets are added to a drawing with additional section and detail views. This creates a situation where the view names and not in alphabetical order thru the sheets. I have routines where I traverse the drawing sheets to perform some operation. What I'm looking for is the command sequence for renaming the section and detail views.
For instance: Starting on "Sheet1", rename all the section views from A to X1. Then update all the detail views labels from X2 - X3. Next sheet...
What are the commands to rename the a section and/or detail views?
Dave
SolidworksApi macros
Try this macro: #CODE|Relable Views
Excellent. Thank you. Worked perfectly.
Artem,
Nice code - it'd be nice if the macro is also included renaming all proj. views
Hi Christian,
Yes, this is possible but projected views do not have labels rather names. How would you like to name them, just alphabetically or you have any other naming convention?
Thanks,
Artem
Hi Artem,
The number of the projected view (Drawing ViewXX) sometimes is jumped from 1 to 3 or 8 to 10 - would it be possible to rearrange for number in order?
artem
unfortunaly this does not seem to work for sw 2014
i do get it to run if i update the library and delete 2016 ref and add 2014
and then the macro runs without problems
the downside is that it does not seem to do anything
a long while back u made this
Conversion of Tree from Chineese to English - DASSAULT: SOLIDWORKS 3D Design - Eng-Tips
i need something simular to that only for drawing files
i tried changing this
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc
to this
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.DrawingDoc
and that stops the macro from throwwing errors on drawwings
but it does not work propper
as it only changes the first 2 instances
i understand it does not change the view sections
is there a way to combine these 2 macro`s into 1 ?
Artem...this macro is magical. i desperately want to use it. Is it possible to exclude I,O,Q,S,X & Z? we don't use these alphabet as its against our standard.
You can set IF conditions to check the current cur and if that matches with I,O,Q,S,X & Z, then jump to next.
thanks deepak.. but i couldn't edit it. i am not good it that. will ask some expert to edit for me.
and
sorry everyone to reopen this conversation, but with the idea, I'd like to know how to change just the details labels to number instead of letters.
my idea is to change this last line, but I need still something else to verify the numbers, check if the number was used or not and use the next one, or just add a last number used +1.
You can add a variable
and then use
<p>swDetailedView.SetLabel ("DetailView" & nNumView)</p>And can check if nNumView is used or not. If used, then bump by +1, check and repeat. If not then use the nNumView value and next view.
Thanks! I did what you said changed the code and works fine now!
Here is the code changed with everything I've done to work.
I don't know if there is any way to make the code see all sheets at once, but I already can work with this!
maybe there is a easy way to do this!
I found out what was the problem, It works perfect now!
THANKS!!
<p><em style="font-size: 8pt;">Const A_CHAR As Integer = 65</em></p><p><em style="font-size: 8pt;">Const Z_CHAR As Integer = 90</em></p><p><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Dim swApp As SldWorks.SldWorks</em></p><p><em style="font-size: 8pt;">Dim swDraw As SldWorks.DrawingDoc</em></p><p><em style="font-size: 8pt;">Dim swSheet As SldWorks.Sheet</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Dim curChar As Integer</em></p><p><em style="font-size: 8pt;">Dim nNumView As Long</em></p><p><span style="color: #e23d39;"><strong><em style="font-size: 8pt;">Dim curNum As Long</em></strong></span></p><p><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Sub main()</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Set swApp = Application.SldWorks</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Set swDraw = swApp.ActiveDoc</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> If swDraw Is Nothing Then</em></p><p><em style="font-size: 8pt;"> MsgBox "Please open drawing document"</em></p><p><em style="font-size: 8pt;"> End</em></p><p><em style="font-size: 8pt;"> End If</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Dim vSheetNames As Variant</em></p><p><em style="font-size: 8pt;"> vSheetNames = swDraw.GetSheetNames</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Dim sheetInd As Integer</em></p><p><em style="font-size: 8pt;"> curChar = A_CHAR</em></p><p><em style="font-size: 8pt;"> <span style="color: #e23d39;"><strong>curNum = 1</strong></span></em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> For sheetInd = 0 To UBound(vSheetNames)</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> swDraw.ActivateSheet vSheetNames(sheetInd)</em></p><p><em style="font-size: 8pt;"> Set swSheet = swDraw.Sheet(vSheetNames(sheetInd))</em></p><p><em style="font-size: 8pt;"> Dim vViews As Variant</em></p><p><em style="font-size: 8pt;"> vViews = swSheet.GetViews</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Dim i As Integer</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> For i = 0 To UBound(vViews)</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Dim swView As SldWorks.View</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Set swView = vViews(i)</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Select Case swView.Type</em></p><p><em style="font-size: 8pt;"> Case swDrawingViewTypes_e.swDrawingSectionView</em></p><p><em style="font-size: 8pt;"> Dim swSectionView As SldWorks.DrSection</em></p><p><em style="font-size: 8pt;"> Set swSectionView = swView.GetSection</em></p><p><em style="font-size: 8pt;"> Debug.Print swSectionView.GetLabel</em></p><p><em style="font-size: 8pt;"> swSectionView.SetLabel2 (GetNextName)</em></p><p><em style="font-size: 8pt;"> Case swDrawingViewTypes_e.swDrawingDetailView</em></p><p><em style="font-size: 8pt;"> Dim swDetailedView As SldWorks.DetailCircle</em></p><p><em style="font-size: 8pt;"> Set swDetailedView = swView.GetDetail</em></p><p><em style="font-size: 8pt;"> Debug.Print swDetailedView.GetLabel</em></p><p><em style="font-size: 8pt;"> <span style="color: #e23d39;"><strong>swDetailedView.SetLabel ("DETALHE " & GetNextNumber) 'swDetailedView.SetLabel GetNextName</strong></span></em></p><p><em style="font-size: 8pt;"> End Select</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Next</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> Next</em><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;"> swDraw.ForceRebuild</em></p><p><em style="font-size: 8pt;">End Sub</em></p><p><em style="font-size: 8pt;"> </em></p><p><em style="font-size: 8pt;">Function GetNextName() As String</em></p><p><em style="font-size: 8pt;"> If curChar > Z_CHAR Then</em></p><p><em style="font-size: 8pt;"> MsgBox ("Overflow")</em></p><p><em style="font-size: 8pt;"> End</em></p><p><em style="font-size: 8pt;"> End If</em></p><p><em style="font-size: 8pt;"> GetNextName = Chr(curChar) & curText</em></p><p><em style="font-size: 8pt;"> curChar = curChar + 1</em></p><p><em style="font-size: 8pt;">End Function</em></p><p></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;">Function GetNextNumber() As String</em></strong></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;"> GetNextNumber = curNum</em></strong></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;"> curNum = curNum + 1</em></strong></p><p><strong style="color: #e23d39;"><em style="font-size: 8pt;">End Function</em></strong></p>The link no longer works, can you put up the code?
You can use the codes post by in this post : https://forum.solidworks.com/message/769040#comment-769040
Long after the fact with this one, but here is my addition. This code, based on the code I found here, will add on a "A" prefix after the alphabet is used up then continue on. Removed unnecessary code and pulled the dims out to the start so you're not re-declaring on every loop to speed things up.
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swSectionView As SldWorks.DrSection
Dim swDetailedView As SldWorks.DetailCircle
Dim curChar As Integer
Dim sheetInd As Integer
Dim i As Integer
Const A_CHAR As Integer = 65
Const Z_CHAR As Integer = 90
Dim prefix As String
Dim vViews As Variant
Dim vSheetNames As Variant
Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
'this is a prefix for sections and details
prefix = ""
If swDraw Is Nothing Then
MsgBox "Please open drawing document"
End
End If
vSheetNames = swDraw.GetSheetNames
curChar = A_CHAR
For sheetInd = 0 To UBound(vSheetNames)
swDraw.ActivateSheet vSheetNames(sheetInd)
Set swSheet = swDraw.Sheet(vSheetNames(sheetInd))
vViews = swSheet.GetViews
For i = 0 To UBound(vViews)
Set swView = vViews(i)
'This if statement will add an A prefix to any existing prefixes when the count goes past Z
If curChar > 90 Then
prefix = prefix & "A"
curChar = A_CHAR
End If
Select Case swView.Type
Case swDrawingViewTypes_e.swDrawingSectionView
Set swSectionView = swView.GetSection
swSectionView.SetLabel2 (prefix & GetNextName)
Case swDrawingViewTypes_e.swDrawingDetailView
Set swDetailedView = swView.GetDetail
swDetailedView.SetLabel (prefix & GetNextName)
End Select
Next
Next
swDraw.ForceRebuild
End Sub
Function GetNextName() As String
GetNextName = Chr(curChar) & curText
curChar = curChar + 1
End Function
The link does not work. I am also after it
Here is a code
<p>Const A_CHAR As Integer = 65</p><p>Const Z_CHAR As Integer = 90</p><p></p><p></p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swDraw As SldWorks.DrawingDoc</p><p>Dim swSheet As SldWorks.Sheet</p><p></p><p></p><p>Dim curChar As Integer</p><p></p><p></p><p>Sub main()</p><p> </p><p> Set swApp = Application.SldWorks</p><p></p><p></p><p> Set swDraw = swApp.ActiveDoc</p><p> </p><p> Set swSheet = swDraw.GetCurrentSheet</p><p> </p><p> Dim vViews As Variant</p><p> vViews = swSheet.GetViews</p><p> </p><p> Dim i As Integer</p><p> </p><p> curChar = A_CHAR</p><p></p><p></p><p> For i = 0 To UBound(vViews)</p><p> </p><p> Dim swView As SldWorks.View</p><p> </p><p> Set swView = vViews(i)</p><p> </p><p> Select Case swView.Type</p><p> Case swDrawingViewTypes_e.swDrawingSectionView</p><p> Dim swSectionView As SldWorks.DrSection</p><p> Set swSectionView = swView.GetSection</p><p> Debug.Print swSectionView.GetLabel</p><p> swSectionView.SetLabel2 GetNextName</p><p> Case swDrawingViewTypes_e.swDrawingDetailView</p><p> Dim swDetailedView As SldWorks.DetailCircle</p><p> Set swDetailedView = swView.GetDetail</p><p> Debug.Print swDetailedView.GetLabel</p><p> swDetailedView.SetLabel GetNextName</p><p> End Select</p><p> </p><p> Next</p><p> </p><p> swDraw.ForceRebuild</p><p> </p><p>End Sub</p><p></p><p></p><p>Function GetNextName() As String</p><p></p><p></p><p> If curChar > Z_CHAR Then</p><p> MsgBox ("Overflow")</p><p> End</p><p> End If</p><p> </p><p> GetNextName = Chr(curChar) & curText</p><p></p><p></p><p> curChar = curChar + 1</p><p></p><p></p><p>End Function</p>-----
Thanks,
Artem
Development of advanced SOLIDWORKS add-in - YouTube
Hi, I know this is a very old thread but how would I modify this to rename auxiliary views rather than section/detail views?
Thanks in advance
I was hoping to try out this code, but the variable "curText", which is used in several blocks of code here is never defined.
I know that's an old thread and the links are expired. Could someone help me with this macro?