AnsweredAssumed Answered

ReplaceViewModel(IDrawingDoc) not working

Question asked by Edgar Quintana on Aug 19, 2014
Latest reply on May 25, 2017 by Di Anne

The example in SW API help is not doing what is supposed to do. I 'm assuming that the API call is not functioning correctly. Can anybody run this macro and get the correct output?

 

This example shows how to replace a model in drawing views.

 

 

'---------------------------------------------------------------------------

' Preconditions:

' 1. Open: install_dir\samples\tutorial\api\assem20.slddrw.

' 2. Ensure that the specified replacement model exists.

'

' Postconditions: The specified component in Drawing View1 is replaced

' with the specified model.

'

' NOTE: Because the model is used elsewhere, do not save changes

' when closing it.

'---------------------------------------------------------------------------

Dim swApp As SldWorks.SldWorks

Dim Part As SldWorks.ModelDoc2

Dim draw As SldWorks.DrawingDoc

Dim selMgr As SldWorks.SelectionMgr

Dim vViews(0) As Variant

Dim vInstances(0) As Variant

Dim boolstatus As Boolean

 

 

Option Explicit

 

 

Sub main()

 

 

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc

    Set draw = Part

   

 

 

    boolstatus = Part.ActivateView("Drawing View1")

   

 

 

    ' Select the view in which to replace the model

    boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

    Set selMgr = Part.SelectionManager

    Set vViews(0) = selMgr.GetSelectedObject6(1, -1)

   

 

 

    ' Select the instance of the model to replace

    boolstatus = Part.Extension.SelectByID2("Assem20-3@Drawing View1/block20-1@assem20", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

    Set vInstances(0) = selMgr.GetSelectedObject6(1, -1)

   

 

 

    boolstatus = draw.ReplaceViewModel("C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\bagel.sldprt", vViews, vInstances)

 

 

End Sub

Outcomes