×
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

Drawing view scale + SW VBA

Drawing view scale + SW VBA

Drawing view scale + SW VBA

(OP)
I want to check each drawing view in my drawing on theire scale and make it 1:1 if necesarry.
How ??
This i got:

Dim Mloopdoorfeaturetree As SldWorks.Feature
Dim Mtellerviewport
Dim Msoort, MSubsoort, Msubsoort2, Mschaalview

Set Mloopdoorfeaturetree = swModel.FirstFeature
Mtellerviewport = 0
        
While Not Mloopdoorfeaturetree Is Nothing
   Msoort = Mloopdoorfeaturetree.GetTypeName
   If Msoort = "DrSheet" Then
        Set MSubsoort = pdoorfeaturetree.GetFirstSubFeature
        While Not MSubsoort Is Nothing
              Msubsoort2 = MSubsoort.GetTypeName
              If Msubsoort2 = "AbsoluteView" Then
                 Set SelMgr = swModel.SelectionManager
                 boolstatus = swModel.ActivateView(Msubsoort2)
                 boolstatus = swModel.Extension.SelectByID2(Msubsoort2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
                 Mtellerviewport = Mtellerviewport + 1
               End If
               Set MSubsoort = MSubsoort.GetNextSubFeature
          Wend
          MsgBox Mtellerviewport & " viewports in de tekening."
          End If
      Set Mloopdoorfeaturetree = Mloopdoorfeaturetree.GetNextFeature
Wend


so i count the numbers of viewports in my drawing, but how can i check theire scale ?

RE: Drawing view scale + SW VBA

As fcsuper said, download the AddViewScale macro he suggested.

It will add the View Scale note to any pre-selected view(s). There is a better description of it (called Label View Scale) at:
http://sw.fcsuper.com/index.php?name=UpDownload&req=viewsdownload&sid=3

To avoid having to select the views yourself, use the below macro that will automatically to select each view, and then the macro will make a sub-call to the downloaded macro above...

I got most of this straight from the SW API Help, the rest from the macro recorder:

CODE

'Mostly from...
'Get Drawing View Names and Types Example (VB)
'This example shows how to the names and types of all of the drawing views on the current sheet.
 
'---------------------------------------
'
' Preconditions: Drawing document is open.
'
' Postconditions: None
'
'---------------------------------------

Option Explicit

Sub main()

    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swDraw                  As SldWorks.DrawingDoc
    Dim swSheet                 As SldWorks.Sheet
    Dim swView                  As SldWorks.View
    Dim bRet                    As Boolean
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swDraw = swModel
    Set swSheet = swDraw.GetCurrentSheet
    
    'First selection is always the sheet.
    Set swView = swDraw.GetFirstView
    
    Debug.Print "File = " & swModel.GetPathName
    Debug.Print "  " & swSheet.GetName
    
    'Get the first view.
    Set swView = swView.GetNextView
    
    While (Not (swView Is Nothing))
        Debug.Print "    " & swView.GetName2 & " [" & swView.Type & "]"
        
        '***START: Added Code to select view and call other macro***
        If (InStr(swView.GetName2, "*") = 0) Then
    
            'Select View
            swModel.ClearSelection2 True
            bRet = swModel.ActivateView(swView.GetName2)
            bRet = swModel.Extension.SelectByID2(swView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
            
            'Call other macro
            swApp.RunMacro ("C:\Program Files\SolidWorks\macros\AddViewScale.swp"), "AddViewScale1", "main"
        End If
        '***END: Added Code to select view and call other macro***
        
        Set swView = swView.GetNextView
    Wend
End Sub

Later,
Ken

RE: Drawing view scale + SW VBA

I thought the original poster wanted to add a note to each view. If you want you get and/or set the view scale...in SolidWorks go to [b]Main Menu/Help/SolidWorks and Add-Ins API Help Topics/Index (tab) and look up these topics:
View, scale
View, ScaleDecimal
View, ScaleRatio

There are sample macros with each topic. You can still use the above code to iterate thru the views. What 33456 shows would actually iterate thru features in the feature tree...which may not be very efficient depending on model size/complexity.

Ken

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