Auto-enter a view scale into a note
Auto-enter a view scale into a note
(OP)
Anyone,
I found an interesting question at this thread on comp.cad.solidworks. FOSW is asking how to automatically add the current VIEW scale to an annotation note. It seems like an interesting idea so I'm seeing if anyone knows how this can be done:
http://g roups.goog le.com/gro up/comp.ca d.solidwor ks/browse_ thread/thr ead/5b28b3 2abab3cd08
I found an interesting question at this thread on comp.cad.solidworks. FOSW is asking how to automatically add the current VIEW scale to an annotation note. It seems like an interesting idea so I'm seeing if anyone knows how this can be done:
http://g
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
http://sw.fcsuper.com/index.php






RE: Auto-enter a view scale into a note
Try thread559-155304
Regards,
Regg
RE: Auto-enter a view scale into a note
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
http://sw.fcsuper.com/index.php
RE: Auto-enter a view scale into a note
Would you mind if I hosted your macro on my site?
Matt
http://sw.fcsuper.com
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
http://sw.fcsuper.com/index.php
RE: Auto-enter a view scale into a note
I actually made some changes to your code to center the text to the view instead of having a set x/y location. Added Viewish string, swNote justification, calculation to find X center of view, and insert point at that center:
CODE
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
Dim Viewish As String
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 to center justification
swNote.SetTextJustification (swTextJustificationCenter)
'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 center and 5mm below from bottom edge of view bounding box
Viewish = (ViewCorners(0) + ViewCorners(2)) / 2
swAnnotation.SetPosition Viewish, ViewCorners(1) - 0.005, 0
'unlock view focus
swView.FocusLocked = False
End If
Next
'refresh graphics screen
swModelDoc.WindowRedraw
End Sub
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
http://sw.fcsuper.com/index.php
RE: Auto-enter a view scale into a note
Go ahead a host away.
Regards,
Regg
RE: Auto-enter a view scale into a note
I took the liberty of form-alizing your macro, pun intended.
AddViewLabel
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: Auto-enter a view scale into a note
I downloaded and ran your macro. I like it. However, if you do not mind me making suggestions, I would set the form's ShowModel property to false. That way the user does not have to preselect the view. Something else you may want to consider is changing the Show Scale... and Display Scale... check boxes to options boxes. It is kind of neat that checking the second box automatically checks the firts box but when you uncheck the second box the first box stays checked; the user may not want (or expect) that. That is why I would change them to option boxs. Remember these are just suggestions, please take no offense to them; I can see you put some time and effort into writing the macro. Have a star.
Regards,
Regg
RE: Auto-enter a view scale into a note
Suggestions duly noted and implementation successful. I also fixed a behavior issue between the two description lines.
The update is available at the same link I listed above
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: Auto-enter a view scale into a note
Heckler
Sr. Mechanical Engineer
SWx 2007 SP 3.0 & Pro/E 2001
XP Pro SP2.0 P4 3.6 GHz, 1GB RAM
NVIDIA Quadro FX 1400
o
_`\(,_
(_)/ (_)
(In reference to David Beckham) "He can't kick with his left foot, he can't tackle, he can't head the ball and he doesn't score many goals. Apart from that, he's all right." -- George Best
RE: Auto-enter a view scale into a note
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group