-
Re: Help with creating a basic Macro ...
Michael Jeffries Oct 10, 2012 12:48 PM (in response to John Pesaturo)Try this:
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swDraw As DrawingDoc
Dim swSheet As Sheet
Dim swView As View
Dim vSheets As Variant
Dim swDispDim As DisplayDimension
Dim swAnn As Annotation
Dim swDim As Dimension
Dim sTextFormat As TextFormat
Dim swColorTable As ColorTable
Dim standardCount As Long
Dim count As Long
Dim colorName As String
Dim colorRef As Long
Sub main()
Set swApp = New SldWorks.SldWorks
Set swModel = swApp.ActiveDoc
Select Case swModel.GetType
Case swDocumentTypes_e.swDocDRAWING
Set swDraw = swModel
vSheets = swDraw.GetSheetNames
swDraw.ActivateSheet vSheets(0)
Set swSheet = swDraw.GetCurrentSheet
Case Else
swApp.SendMsgToUser ("Open a drawing document and try again.")
Exit Sub
End Select
i = 0
'Set swColorTable = swApp.GetColorTable
'
'standardCount = swColorTable.GetBasicColorCount
'Debug.Print "SolidWorks standard user-interface element and COLORREF value:"
'' Iterate through standard colors
'For count = 0 To (standardCount - 1)
' ' Get the entry name
' colorName = swColorTable.GetNameAtIndex(count)
' If colorName <> "" Then
' ' Get the entry's COLORREF
' colorRef = swColorTable.GetColorRefAtIndex(count)
' Debug.Print " " & colorName & " : " & colorRef
' Else
' End If
'Next count
While Not swSheet Is Nothing
'For i = 0 To UBound(vSheets)
Debug.Print "**************************************************"
Debug.Print "********************** " & swSheet.GetName & " ********************"
Debug.Print "**************************************************"
Set swView = swDraw.GetFirstView
While Not swView Is Nothing
Debug.Print swView.GetName2
Set swDispDim = swView.GetFirstDisplayDimension5
'************ DISPLAY DIMENSION DATA ****************
While Not swDispDim Is Nothing
Set swAnn = swDispDim.GetAnnotation
Set swDim = swDispDim.GetDimension
swAnn.Select True
Debug.Print " Display Dimension: " & swDim.FullName
swModel.SelectByName swSelectType_e.swSelDIMENSIONS, swDim.FullName
swAnn.Color = 0 'Black
swAnn.SetTextFormat 0, True, swAnn.GetTextFormat(0)
Set swDispDim = swDispDim.GetNext3
Wend
'************ ANNOTATION DATA ****************
Set swAnn = swView.GetFirstAnnotation
While Not swAnn Is Nothing
Select Case swAnn.GetType
Case swAnnotationType_e.swNote
Debug.Print swAnn.GetName
swAnn.Select True
swAnn.UseDocDispFrame = True
swAnn.UseDocDispLeader = True
swAnn.SetTextFormat 0, True, swAnn.GetTextFormat(0)
swAnn.Color = 0
Case Else
'do nothing
End Select
Set swAnn = swAnn.GetNext
Wend
Set swView = swView.GetNextView
Wend
Select Case i
Case UBound(vSheets)
'DO NOTHING
Exit Sub
Case Else
End Select
i = i + 1
swDraw.ActivateSheet vSheets(i)
Set swSheet = swDraw.GetCurrentSheet
Wend
'Next i
End Sub
-
SelectAnnotations.swp.zip 13.9 KB
-
Re: Help with creating a basic Macro ...
John Pesaturo Oct 10, 2012 12:57 PM (in response to Michael Jeffries)That works, but it literally grabs everything in the entire drawing ... Is there a way to just select the dimensions and annotations that are on the sheet, but avoid everything that's locked inside of the sheet format?
Oh, and I must say that is one heck of a Macro. I didn't think my "basic Macro" would be nearly as involved.
-
Re: Help with creating a basic Macro ...
Michael Jeffries Oct 10, 2012 1:13 PM (in response to John Pesaturo)It shouldn't grab everything in the drawing, only Annotations and Dimensions (and their annotations). Does it reset the color? I was having trouble getting it to override the color if the color was set by the format bar. I suspect it grabbed stuff in your title block because it's part of the drawing and not a template? If you right click >>> Edit sheet format, is it blank?
Mine only grabbed the dimensions and notes:
-
Re: Help with creating a basic Macro ...
John Pesaturo Oct 10, 2012 1:25 PM (in response to Michael Jeffries)Yes, it reset the color OK. It just grabbed everything within the sheet format as well and changed colors and sizes. I've attached the document I used to trouble shoot the problem to begin with for reference as to the sheet format setup.
On a side note, someone had mentioned to attach zip files in a group rather then individually, but I can't seem to figure out how to do that. The selection box when attaching documents won't let me ctrl select multiple items.
-
Drawing Fix Model.SLDPRT.zip 38.6 KB
-
Drawing Fix Model SB.SLDDRW.zip 94.8 KB
-
Re: Help with creating a basic Macro ...
Michael Jeffries Oct 10, 2012 1:42 PM (in response to John Pesaturo)Ok, not sure why it's grabbing items in your Sheet Format versus mine, but the simple solution (since you're just trying to fix color) is to comment out or delete the following lines:
'swAnn.SetTextFormat 0, True, swAnn.GetTextFormat(0)
Furthermore, you don't need it to select while it goes along, so you can also comment out the following lines:
'swAnn.Select True
I'll look into why it's changing your title block later, but keep in mind this fix will still change the color of the title block items (keep in mind, this macro loops through all of the views on a sheet and gets the annotations and dimensions, changes the color, then cycles to the next annotation >>> display dimension >>> view >>> sheet). If you have more than one sheet, it will change them as well.
The loop:
**********************************************
Sub Main()
ModelDoc2
DrawingDoc
Sheet
View
Display Dimension
Annotation (Notes Only)
Next View
Next Sheet
End Sub
**********************************************
To add .zip files together, highlight the files in windows explorer >> right click >>> send to >>> Compressed Zip Folder
-
Re: Help with creating a basic Macro ...
John Pesaturo Oct 10, 2012 2:31 PM (in response to Michael Jeffries)I have to admit to being in over my head here. To be honest it would be just as easy to manually window select everything on screen and simply change the line color to default. I had just hoped there was a way to get a quick Macro to do the same. I've tried the Macro "record" button a number of times now, and it just doesn't work the same way on every drawing. All in all, it simply leaves me more room to broaden my knowledge base and learn some programming language. I thank you for your time all the same and greatly appreciate the help.
-
Re: Help with creating a basic Macro ...
Michael Jeffries Oct 10, 2012 3:00 PM (in response to John Pesaturo)Ok, here is what was happening.
Views in Drawing:
Sheet1
Drawing View1
Drawing View2
All of your title block info was in the view "Sheet1", so I modified the code to exclude getting notes and dimensions that aren't specifically attached to a particular model / drawing view, i.e. Drawing View1, Drawing View2, Section View1, etc...
-
SelectAnnotations.swp.zip 13.9 KB
-
Re: Help with creating a basic Macro ...
John Pesaturo Oct 11, 2012 6:36 AM (in response to Michael Jeffries)Michael,
That seems to work really well. I've tried it out on a handful of drawings that I had seen with the issue, and it works as it should. It's only selecting the drawing dimensions and annotations, it stays away from the sheet format and it's not changing the sizes of the fonts any longer. Thank you so much for your assistance. You've been more then helpful.
-
-
-
-
-
-
-