Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing view scale + SW VBA 1

Status
Not open for further replies.

33456

Mechanical
May 23, 2007
10
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 ?
 
Replies continue below

Recommended for you

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:

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
 
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 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor