8 Replies Latest reply on Aug 14, 2018 8:20 AM by Josh Brady

    Use API to Check Part/Assembly Fully Defined?

    Andre Colemen

      I've been searching on and off for an answer or method to this question for a while.

       

      Is it possible to use the API to check or get the constraint status of a part or assembly? (Fully Defined, Under Defined, etc.)  So far, I have found a solution that is specific to Sketches, but what I am looking for is a 'Get' command or some type of check that I can run to return an output for a specified Assembly that just tells me the constraint status of the assembly.  My initial guess was that there would be a command specific for this, since the Feature Manager tree has the '(-) symbols next to any part in the assembly that is under-defined. But this has proven to be much more obscure to figure out.

       

      Thanks for any help.

          • Re: Use API to Check Part/Assembly Fully Defined?
            Andre Colemen

            Awesome, thank you.

             

            Can't believe I hadn't come across that member of IComponent2 in my searches so far.

              • Re: Use API to Check Part/Assembly Fully Defined?
                Parth Patel

                Hi,

                I am new for the API.

                As explained in above I want a same thing but I could not able to do it.

                So, can I get that particular code for getting the "Fully Defined and Under Defined" assembly or part status.

                 

                When I run the code I got error "User-Defined Type not defined" at this "value = instance.GetConstrainedStatus()".

                I tried all thing including references and all.

                 

                Looking for your help.

                  • Re: Use API to Check Part/Assembly Fully Defined?
                    Deepak Gupta

                    Parth Patel wrote:

                     

                    When I run the code I got error "User-Defined Type not defined" at this "value = instance.GetConstrainedStatus()".

                    I tried all thing including references and all.

                     

                    Looking for your help.

                    Did you defined the variables correctly? Do share your full macro to debug.

                      • Re: Use API to Check Part/Assembly Fully Defined?
                        Parth Patel

                        Hi,

                        this is my Code.

                         

                        Option Explicit

                        Dim swApp As SldWorks.SldWorks

                        Dim swModel As SldWorks.ModelDoc2

                        Dim swConfigMgr As SldWorks.ConfigurationManager

                        Dim curCnfg As SldWorks.Configuration

                        Dim curNam As String

                        Dim resp As String

                        Dim retval() As String

                        Dim cnfgCnt As String

                        Public i As Integer

                         

                         

                        Private Sub CommandButton1_Click()

                           

                            curNam = curCnfg.Name

                           

                            Call GetConstrainedStatus

                           

                            cnfgCnt = swModel.GetConfigurationCount - 1

                           

                            retval = swModel.GetConfigurationNames()

                           

                            swModel.ShowConfiguration2 retval(i)

                         

                         

                            If i < cnfgCnt Then

                                i = i + 1

                            Else

                                i = 0

                            End If

                         

                         

                        End Sub

                         

                         

                        Private Sub UserForm_Initialize()

                            Set swApp = Application.SldWorks

                            Set swModel = swApp.ActiveDoc

                            Set swConfigMgr = swModel.ConfigurationManager

                            Set curCnfg = swConfigMgr.ActiveConfiguration

                        End Sub

                         

                         

                        Public Function GetConstrainedStatus() As Long

                            Dim instance As IComponent

                            Dim value As System.Integer

                            value = instance.GetConstrainedStatus()

                        End Function

                          • Re: Use API to Check Part/Assembly Fully Defined?
                            Deepak Gupta

                            Not fully sure as what your codes are doing but here are quick VBA codes (no error handling has been added). Use/modify as needed.

                             

                            Option Explicit
                            Sub main()
                                Dim swApp As SldWorks.SldWorks
                                Dim swModel As SldWorks.ModelDoc2
                                Dim swAssy As SldWorks.AssemblyDoc
                                Dim swConf As SldWorks.Configuration
                                Dim swRootComp As SldWorks.Component2 
                               
                                Set swApp = Application.SldWorks
                                Set swModel = swApp.ActiveDoc
                                Set swAssy = swModel
                                Set swConf = swAssy.GetActiveConfiguration
                                Set swRootComp = swConf.GetRootComponent3(True)
                            
                                ' Traverse components
                                TraverseComponent swRootComp, 1
                               
                            End Sub
                            
                            Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
                                Dim vChildComp As Variant
                                Dim swChildComp As SldWorks.Component2
                                Dim swCompConfig As SldWorks.Configuration
                                Dim sPadStr As String
                                Dim i As Long
                               
                                vChildComp = swComp.GetChildren
                                For i = 0 To UBound(vChildComp)
                                    Set swChildComp = vChildComp(i)
                                    TraverseComponent swChildComp, nLevel + 1
                                    Debug.Print swChildComp.Name2 & "-" & swChildComp.GetConstrainedStatus
                                Next i
                            End Sub
                            
                              • Re: Use API to Check Part/Assembly Fully Defined?
                                Parth Patel

                                Thank You Dipak,

                                 

                                The Code is running perfectly but it did not give what I want.

                                 

                                Let me explain my requirement,

                                    1. I have created one user form with one command button and when I press / Hit the button the assembly configuration going to          change per each click in sequence.

                                    2. I did prepare the code for that and it's working perfect and it is activating the configuration per each hit of command button.

                                    3. In this user form I want add a text box and need to pass (Need to get status of assembly) "Fully Defined" or "Under Defined" status of          the Assembly per configuration.

                                As above points the macro work perfectly till point 2. but I need help on point 3.

                                 

                                Please find the SWx. (Macro) file from the attachment.

                                Attachment name is :- UpdateConfigurations.swp

                                 

                                Thanks and Regards,

                                Parth K

                                  • Re: Use API to Check Part/Assembly Fully Defined?
                                    Josh Brady

                                    Parth,

                                    I didn't look at your .swp, but unless it's drastically different from the code you posted originally, you're miles and miles away from what you want.  Your GetConstrainedStatus function shows a deep lack of basic understanding of how to write VBA code.  I'm not saying that to be mean, it's just the current status.  Everyone starts out that way.

                                     

                                    Your project may be interesting enough to someone that they will write it for you.  Otherwise, I would recommend taking a step back... Learn VBA first (there are free tutorials online).  Then go to cadsharp.com and learn as much as you can about SW API.  Then you'll be ready to tackle this project.