tighthead
Mechanical
- Dec 18, 2001
- 11
How do we include the scale of a view in a note on a draaawing (linked)?
SW2005 sp0.
SW2005 sp0.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swNote As SldWorks.note
Dim swAnnotation As SldWorks.Annotation
Dim swSelection() As Object
Dim ScaleRatio As Variant
Dim ViewCorners As Variant
Dim SelectionIndex As Long
Sub main()
'attach to SolidWorks
Set swApp = Application.SldWorks
'get active document
Set swModelDoc = swApp.ActiveDoc
'check for document
If swModelDoc Is Nothing Then
MsgBox "No active document. ", vbOKOnly + vbCritical, "Label View Scale"
Exit Sub
End If
'check if document is drawing
If swModelDoc.GetType = swDocDRAWING Then
Set swDrawing = swModelDoc
Else
MsgBox "Active document must be drawing. ", vbOKOnly + vbCritical, "Label View Scale"
Exit Sub
End If
'get selection manager
Set swSelMgr = swModelDoc.SelectionManager
'check if anything selected
If swSelMgr.GetSelectedObjectCount = 0 Then
MsgBox "No views selected. ", vbOKOnly + vbCritical, "Label View Scale"
Exit Sub
Else
'save selections
ReDim swSelection(1 To swSelMgr.GetSelectedObjectCount) As Object
'check if selection is drawing view
For SelectionIndex = 1 To swSelMgr.GetSelectedObjectCount
If swSelMgr.GetSelectedObjectType2(SelectionIndex) = swSelDRAWINGVIEWS Then
Set swSelection(SelectionIndex) = swSelMgr.GetSelectedObject5(SelectionIndex)
End If
Next
End If
'analize selections
For SelectionIndex = 1 To swSelMgr.GetSelectedObjectCount
'check if selected object is view
If swSelection(SelectionIndex) Is Nothing Then
MsgBox "Selected object " & SelectionIndex & " is not a drawing view. ", vbOKOnly + vbExclamation, "Label View Scale"
Else
'get selected view
Set swView = swSelection(SelectionIndex)
'get view scale
ScaleRatio = swView.ScaleRatio
'get view corner locations
ViewCorners = swView.GetOutline
'lock view focus so note will move if corresponding view moved
swView.FocusLocked = True
'create note
Set swNote = swDrawing.InsertNote("Scale " & ScaleRatio(0) & ":" & ScaleRatio(1))
'set note angle
swNote.angle = 0
'set note is balloon to no
swNote.SetBalloon 0, 0
'get note annotation object
Set swAnnotation = swNote.GetAnnotation
'set note leader to none
swAnnotation.SetLeader2 False, 0, True, False, False, False
'locate note 10mm right from left edge and 5mm below from bottom edge of view bounding box
swAnnotation.SetPosition ViewCorners(0) + 0.01, ViewCorners(1) - 0.005, 0
'unlock view focus
swView.FocusLocked = False
End If
Next
'refresh graphics screen
swModelDoc.WindowRedraw
End Sub