Hello all,
I am kind of stumped. I have started to make a macro that will number our op sheets based on operation number. I can currently count each op sheet which and the macro will start back at one when the operation number changes, but I cant seem to figure out how to get it to count the total number of sheets per operation then do the individual number.
<p><span style="font-family: Consolas;">Sub main()<br> Dim swApp As SldWorks.SldWorks<br> Dim swModel As SldWorks.ModelDoc2<br> Dim swDrawing As SldWorks.DrawingDoc<br> Dim swSelMgr As SldWorks.SelectionMgr<br> Dim swNote As SldWorks.Note<br> Dim swView As SldWorks.View<br> Dim swSheet As SldWorks.Sheet<br> Dim swAnno As SldWorks.Annotation<br> <br> <br> <br> Dim swSelObj As Object<br> <br> <br> Dim SheetCount, e, k, t As Integer<br> Dim i, j, x, y As Integer</span></p><p><span style="font-family: Consolas;"> <br> Dim strop As String<br> Dim strop2 As String<br> Dim descriptionText As String<br> Dim SheetNames() As String<br> <br> <br> Dim sheets(0) As Long<br> <br> <br> Dim foundNote As Boolean<br> Dim ret As Boolean</span></p><p><span style="font-family: Consolas;"><br> Set swApp = Application.SldWorks<br> Set swModel = swApp.ActiveDoc<br> Set swDrawing = swModel<br> SheetNames = swDrawing.GetSheetNames<br> swDrawing.ActivateSheet SheetNames(0)<br> SheetCount = swDrawing.GetSheetCount<br> <br> If swApp.ActiveDoc.GetType <> swDocDRAWING Then<br> swApp.SendMsgToUser2 "This Macro Is Only For Use On Drawing Documents!", swMbWarning, swMbOk<br> End<br> End If</span></p><p></p><p>t = 1<br>For e = 1 To SheetCount<br>strop2 = strop<br> If e > 1 Then swDrawing.SheetNext<br> swDrawing.EditTemplate<br> Set swView = swDrawing.GetFirstView<br> Set swNote = swView.GetFirstNote<br> Do While Not swNote Is Nothing<br> If (swNote.GetName = "DetailItem32") Then<br> foundNote = True<br> strop = swNote.GetText<br> End If<br> Set swNote = swNote.GetNext<br> Loop<br> <br> t = t + 1<br> <br> If strop2 <> strop Then t = 1<br> <br> swApp.SendMsgToUser ("OP #" & strop & " : " & t)<br> Next i<br> <br> <br> <br> swDrawing.EditSheet</p><p>Next e</p><p></p><p>swDrawing.ForceRebuild3 True</p><p>End Sub</p>SolidworksApi macros
, try using the ReDim Preserve method as demonstrated by here
Thank you , I will try to give that a shot. I have been playing around with the code for a little while and currently the only part that I can't figure out is how to count the total number of sheets used when the note ="OP(whatever the op is)". I attached the current iteration of the macro.
As it stands now. It will delete any existing "SHEET _ OF _" and replaces it with a running total based on Note #32, which is the Operation number.
I was looking at the definition of ReDim and I am not sure how this would allow me to accomplish what I am looking for.
Can you attach some files to look at and adjust this macro?
Sadly I cannot as it is against my companies policy. I will say that detailitem32 is referring to $PRPSHEET:{OPERATION NO.}, which is a config specific note on our template.
You need to loop over the sheets in your document twice, once to count the totals and a second time to perform the changes that you are making in your existing macro.
Because your method of enumerating sheets is unique, I don't think there is a cleaner way of getting the totals than to count them.
You already have the iterator "t" being set to 1 every time a new Op is detected. Just append that value to an array "opSheetCounts" or something of that ilk before setting it to 1.
I think you are right. Sadly Arrays are not my strong suit, so I might try to loop until conditions are met then goto and kind of jump around.
is this what you want?
Thanks Ivana, but that isn't quite what I need. I will try to explain it a little better. Each drawing document contains all of our operation sheets for 1 part number. So lets say part number 1 has 5 operations. If operation 2 has 5 sheets total, I need the macro to output sheet 1 of 5 for the first sheet then continue until the next operation.
GoTo gets confusing quickly, hard to predict, hard to debug.
The syntax for arrays in VBA has a lot of overhead but they are very handy. I normally use the following pattern:
This isn't efficient for large arrays but it is quick to implement. It isn't efficient because redim preserve creates a copy of the array and copies the old array into the new one. For your purposes, Solidworks would probably crash from all the sheets before it saw a substantial performance difference from using redim preserve on every append.
and this?
Ivana that worked great. Thank you.
I have one more small issue with this. Is there a way I can make the macro only search the sheet format for the note I want to delete? We usually have a revision history sheet which always contains the work "SHEET" and when I run the macro as it stands it will not only delete the sheet count, "SHEET 1 OF 1", but it will delete the history sheet note as well.
Thank you,
Matt
I would set name to created note and use this name for removing.
something like this
Thanks Ivana, I currently have that in the code, but if I am too explicit then it wont delete all of the current sheets numbers and if I am not explicit enough then it will delete the note. The other issue is this will be used by multiple people, and while I have no problem avoiding the use of certain phrases I cant control what others do.
therefore gives this macro unique name to new created note. But it will not reach already created notes in past.
The only issue with this is we cannot adjust our current template without customer approval, and then that would also force everyone to use the macro, which I am not so sure everyone is accepting of. Is it possible to search for the note in a given area?
You are a life saver. Thank you so much, that works great.