3 Replies Latest reply on Apr 25, 2014 10:24 AM by Nick Salters

    LocalLPattern in subassembly

    Nick Salters



      I am trying ot modify a LocalLinearPattern in a subassembly.  I can do it fine when I open the subassembly and write code to modify it there, and the only real difference is what goes in to the Part.Extension.SelectByID2() portion, so I assume that is where I am having the issue.  I don't think I am properly selecting the local pattern within the subassembly.  Any help would be greatly appreciated.



      My tree looks like this:







      Code looks like this:


      Sub AlterPart()

          Dim swApp As Object

          Dim pPart As Object

          Dim longstatus As Long, longwarnings As Long

          Set swApp = CreateObject("SldWorks.Application")

          Set pPart = swApp.ActiveDoc

          Part.ResolveAllLightWeightComponents (True)

          Dim Skip2(0 To 50) As Long

          Dim boolstatus As Boolean

          Dim lFeatureData As ILocalLinearPatternFeatureData

          Dim pFeature As IFeature

          Dim pSelMan As SelectionMgr

          Erase Skip2()

          Skip2(0) = 42

          Skip2(1) = 43


             boolstatus = Part.Extension.SelectByID2("LocalLPattern1@NextAssembly-1@TopAssembly", "COMPPATTERN", 0, 0, 0, False, 0, Nothing, 0)

              Set pSelMan = pPart.SelectionManager

              Set pFeature = pSelMan.GetSelectedObject5(1)

              Set lFeatureData = pFeature.GetDefinition

              lFeatureData.SkippedItemArray = (Skip2)

              pFeature.ModifyDefinition (lFeatureData, pPart, Nothing)





      End Sub

        • Re: LocalLPattern in subassembly
          Artem Taturevych

          Hi Nick and Welcome to the SolidWorks API Community!


          I would suggest to not select by composed name. It is better to find the pointer directly. When you modifying the definition in context you should pass the pointer to component as the context object. Please find the code below which is applicable to your case.


          Dim swApp As SldWorks.SldWorks

          Dim swAssy As SldWorks.AssemblyDoc


          Sub main()


              Set swApp = Application.SldWorks


              Set swAssy = swApp.ActiveDoc


              ModifyLinPattern "NextAssembly-1", "LocalLinearPattern1"


          End Sub


          Sub ModifyLinPattern(compName As String, pattName As String)


              Dim swComp As SldWorks.Component2

              Set swComp = swAssy.GetComponentByName(compName)


              Dim swFeat As SldWorks.Feature

              Set swFeat = swComp.FeatureByName(pattName)


              Dim swFeatData As SldWorks.LocalLinearPatternFeatureData

              Set swFeatData = swFeat.GetDefinition


              swFeatData.AccessSelections swAssy, swComp


              Dim skipArr(1) As Long

              skipArr(0) = 1: skipArr(1) = 3


              swFeatData.SkippedItemArray = skipArr


              swFeat.ModifyDefinition swFeatData, swAssy, swComp


          End Sub


          Regards, Artem Taturevych | Snr. Developer | IC3D ANZ


          IC3DSteel – New Steel Solution for SolidWorks

          translationXpert – SolidWorks files language translator

          LinkedIn - SolidWorks API Group

            • Re: LocalLPattern in subassembly
              Nick Salters

              Thanks for the assistance, my biggest problem was understanding the component2 method and then what the AccessSelections method wanted in terms of parameters.  In addition to this, I saw that the Modify Definition should automatically release the selection, and I added the release selection after that anyway, but in the model after my code runs, the subassembly is still "Open" for editing.  Is there a way to have it "close" for editing.  Not sure if I'm making sense here, but basically it leaves it where the SubAssembly is Opened and I want it closed after the code runs.


              Other than that the model is updating as it should.  Thanks again!