8 Replies Latest reply on Jul 17, 2014 5:44 PM by Danny Bradford

    Save Assembly as part settings

    Danny Bradford

      Greetings,

       

      I apologize for this simplistic question but sometimes these help documents skip some simple but key points. Here goes...

       

      I am trying to use this code to take an open assembly and save it as a part:

       

              Dim swApp As SldWorks

              Dim swModel As ModelDoc2

              Dim swModelDocExt As ModelDocExtension

              Dim nErrors As Long

              Dim nWarnings As Long

              Dim bool As Boolean

       

              swApp = GetObject(, "SldWorks.Application")

              swModel = swApp.ActiveDoc

              swModelDocExt = swModel.Extension

       

              bool = swApp.SetUserPreferenceIntegerValue(swSaveAsmAsPartOptions_e.swSaveAsmAsPart_ExteriorFaces, 1)

              swModelDocExt.SaveAs("C:\test_folder\create_me.sldprt", 0, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, nErrors, nWarnings)

       

       

              MsgBox(bool)

       

              swApp.CloseDoc(swModel.GetTitle)

       

       

      Unfortunately while the boolean messagebox comes back as true but the settings are not really being taken into account during save.

       

      I know it has something to do with the SetUserPreferenceIntegerValue second value. I have tried many options but cannot get control. The help is quite cryptic in this regard.

       

      Thanks in advance for your assistance.

        • Re: Save Assembly as part settings
          Danny Bradford

          I forgot to mention I am in VB.NET...

          • Re: Save Assembly as part settings
            Deepak Gupta

            Pick the required value from this table:

             

            MemberDescription
            swSaveAsmAsPart_AllComponents1
            swSaveAsmAsPart_ExteriorComponents2
            swSaveAsmAsPart_ExteriorFaces3

             

            The table is from the SW API help files only.

             

            bool = swApp.SetUserPreferenceIntegerValue(swSaveAsmAsPartOptions_e.swSaveAsmAsPart_ExteriorFaces, 1)

            You may also edit the line as

            bool = swApp.SetUserPreferenceIntegerValue(swSaveAssemblyAsPartOptions, 1) ' Pick the required value from the table

              • Re: Save Assembly as part settings
                Danny Bradford

                Thanks for the reply. In fact it was a previous post that you answered that got me so close to what i want to do so thanks for that as well!

                 

                Unfortunately it is still not working. Here is my latest save code:

                 

                    Private Sub Save_to_Part()

                        Dim swApp As SldWorks

                        Dim swModel As ModelDoc2

                        Dim swModelDocExt As ModelDocExtension

                        Dim nErrors As Long

                        Dim nWarnings As Long

                        Dim bool As Boolean

                        Dim swModelDoc As ModelDoc2

                        Dim swAssembly As AssemblyDoc

                        Dim boolstatus As Boolean

                 

                        swApp = GetObject(, "SldWorks.Application")

                        swModel = swApp.ActiveDoc

                        swModelDocExt = swModel.Extension

                        swModelDoc = swApp.ActiveDoc

                        swAssembly = swModelDoc

                 

                        ' Set the selected component to transparent

                   

                        boolstatus = swAssembly.SetComponentTransparent(False)

                 

                        bool = swApp.SetUserPreferenceIntegerValue(swSaveAsmAsPartOptions_e.swSaveAsmAsPart_AllComponents, 0)

                        swModelDocExt.SaveAs("C:\test_folder\create_me.sldprt", 0, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, nErrors, nWarnings)

                 

                 

                        swApp.CloseDoc(swModel.GetTitle)

                    End Sub

                 

                The save is occurring but it is continuing to default to External references only part. I would like to use the All Components.

                 

                Thanks