×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Auto-enter a view scale into a note
2

Auto-enter a view scale into a note

RE: Auto-enter a view scale into a note

fcsuper,

Try thread559-155304

Regards,

Regg

RE: Auto-enter a view scale into a note

(OP)
Is there any way to make this auto update if the view scale changes?

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
http://sw.fcsuper.com/index.php

RE: Auto-enter a view scale into a note

(OP)
Regg,

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

fcsuper,

Go ahead a host away.

Regards,

Regg

RE: Auto-enter a view scale into a note

(OP)
Regg,

I took the liberty of form-alizing your macro, pun intended.  smarty  I added other labelling support as well.  Check it out and let me know whatcha think:

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

fcsuper,

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

(OP)
Regg,

Suggestions duly noted and implementation successful.  I also fixed a behavior issue between the two description lines. pc2

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

I submitted an enhancement that anytime you take a view out of the sheets default scale that it places a note which states the views scale.  I often use 3/4 or 1/2 scale ISO views for some of my complex molded parts....which helps the mold maker to see what he's trying to build.  Just as a side note I got this idea because Pro/E does this and I found it helpful.

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

(OP)
Technically, and Isometric view scale isn't true since Isometric is a distorted 3D projection to a flat surface.  Of course, SolidWorks let's one treat it as true, but that because it treats it as a model in the flat.  This is why I always use parathesis when I identify an isometric view's scale, and why I put that option into the macro.  Hopefully SolidWorks will listen to your request.  bigears

Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources