AnsweredAssumed Answered

Component Reference Property - code help

Question asked by Todd Bennett on Aug 30, 2018
Latest reply on Aug 30, 2018 by Todd Bennett

I have some code I "borrowed" and was trying to make work for my situation.


From an assembly, I need to select one or more parts and change their COMPONENT REFERENCE to be whatever value I need.

Anyone want to fix this or give me something better?






Sub main()


    Dim myModelView As Object

    Dim Part As ModelDoc2

    Dim boolstatus As Boolean

    Dim longstatus As Long, longwarnings As Long

    Dim swEntity As Entity

    Dim objectCount As Integer

    Dim swComponent As Component2

    Dim refRoot As String

    Dim refNumber As Integer


    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc


    Set myModelView = Part.ActiveView


    Dim swSelectionMgr As SelectionMgr

    Set swSelectionMgr = Part.SelectionManager


    objectCount = swSelectionMgr.GetSelectedObjectCount


    refRoot = InputBox("Reference Number")


    For i = 1 To objectCount

        Set swEntity = swSelectionMgr.GetSelectedObject6(i, -1)

        Set swComponent = swEntity.GetComponent

        swComponent.ComponentReference = refRoot



    Part.ForceRebuild3 (True)


End Sub