1 Reply Latest reply on Oct 25, 2014 8:16 PM by Sanya Shmidt

    Re-attach dimensions VBA

    Sanya Shmidt

      Hello everyone,

       

      Does anyone know how to re-attach dangling dim`s on the drawing after replacing the model. See below is what I have so far. Script opens the template file and replaces the model. Also see video.

      Now I need to re-attach dim`s.

       

                Public Sub BafflesDrawing()
              Dim swModelDocExt As ModelDocExtension
              Dim swDrawingDoc As DrawingDoc
              Dim swSelectionMgr As SelectionMgr
              Dim swDrawingComponent As DrawingComponent
              Dim swView As SldWorks.View
              Dim swComponent As Component2
              Dim views(0) As Object
              Dim instances(0) As Object
              Dim viewsIn(0) As DispatchWrapper
              Dim instancesIn(0) As DispatchWrapper
              Dim status As Boolean
      
              Dim fileerror As Long
              Dim filewarning As Long
              Dim ModelPath As String
              Dim FileName As String
      
              FileName = swModel.GetTitle
              ModelPath = swModel.GetPathName
            
              swModel = swApp.OpenDoc6(".......STANDARD BAFFLE.SLDDRW", 3, 0, "", fileerror, filewarning)
              swModel = swApp.ActiveDoc
      
              swModel = swApp.ActiveDoc
              swDrawingDoc = swModel
              status = swModel.ActivateView("Drawing View1")
      
              'Select the view in which to replace the model
              swModelDocExt = swModel.Extension
              status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
              swSelectionMgr = swModel.SelectionManager
              swView = swSelectionMgr.GetSelectedObject6(1, -1)
              views(0) = swView
              viewsIn(0) = New DispatchWrapper(views(0))
      
      
              ' Select the instance of the model to replace
              status = swModelDocExt.SelectByID2(FileName & "@Drawing View1", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
              swDrawingComponent = swSelectionMgr.GetSelectedObject6(1, -1)
              swComponent = swDrawingComponent.Component
              instances(0) = swComponent
      
              instancesIn(0) = New DispatchWrapper(instances(0))
              status = swDrawingDoc.ReplaceViewModel(ModelPath, (viewsIn), (instancesIn))
      
      
      
      

       

       

      https://dl.dropboxusercontent.com/u/23443066/DanglingDims_x264.avi