8 Replies Latest reply on Dec 5, 2012 2:19 AM by Georg Draxler

    Use EditFreeze in Assembly?

    Georg Draxler

      Hello,

       

      i am trying to use the API Method EditFreeze, but i don't want to open every part document, so i run

      through the whole model and put every part in edit mode.

      After that i use EditFreeze:

       

      Boolstat = featMgr.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", False)

       

      But this is not moving the freezebar to the end of the featuretree. Boolstat says "False"

      The FeatMgr is from the modeldoc of the part in edit mode.

      Anybody know why this isn't working?

       

      Thanks for your help

        • Re: Use EditFreeze in Assembly?
          Artem Taturevych

          Try to use Feature Manager from Active model doc (i.e. assembly). When working in-context you should always use active document only (especially for feature creation). Even if it seems to work correct this may produce unexpected behaviour in future. Seen this a number of times.

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444

            • Re: Use EditFreeze in Assembly?
              Georg Draxler

              i tried now as you said, but using the assembly ModelDoc also doesn't work.

              Here is my sample code:

               

              For Each Component As sldworks.Component2 In Components

                          swDocForLoop = Component.GetModelDoc2

                          If swDocForLoop.GetType = swconst.swDocumentTypes_e.swDocPART Then

                              Component.Select4(False, seldata, False)

                              rootAssembly.EditPart2(True, False, editPartInfo)

               

                              Debug.WriteLine(editPartInfo)

                              Debug.WriteLine(Component.Name2)

                              fm.Freeze_(rootDoc) 'fm is an instance of a class. rootDoc is my Assembly where i call the programm

               

                          End If

              Next

               

              Implementation of Freeze_

               

              Function Freeze_(ByVal swDoc As ModelDoc2)

                      Dim swModelDocExt As ModelDocExtension = swDoc.Extension

                      Dim featMgr As FeatureManager

                      Dim selMgr As SelectionMgr

                      Dim Boolstat As Boolean = True

                      Dim feat As Feature

                      'Dim swPart As SolidWorks.Interop.sldworks.PartDoc

               

                      'Get ModelDocs Featuermanager and Selectionmanger

                      featMgr = swDoc.FeatureManager

                      selMgr = swDoc.SelectionManager

               

                      feat = featMgr.GetFreezeLocation

               

                      'Move featurefreeze to bottom of featuretree if Model is not freezed

                      If feat Is Nothing Then

                          Boolstat = featMgr.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", False)

                      Else

                          Exit Function

                      End If

                      'Check if model is freezed now

                      feat = featMgr.GetFreezeLocation

                      'If model is not freezed do a force rebuild and freeze again

                      If feat Is Nothing Then

                          swDoc.ForceRebuild3(False)

                          Boolstat = featMgr.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", False)

                      End If

               

                  End Function

               

              I also tried to record a macro freezing a part in an assembly. it records the freeze methode but when i play the macro it doesn't freeze.

                • Re: Use EditFreeze in Assembly?
                  Michael Kozikowski

                  You need to have the assembly component document EXPLICITLY open for this to work, unlike the UI, it is required. The API requires a model view, so just open the component document and re-run the macro.

                    • Re: Use EditFreeze in Assembly?
                      Georg Draxler

                      The assembly document is allready open. It is the document where i start the macro but i don't want to open every part document because it slows down the whole process. It would be nicer and faster to do this in edit mode.

                      I also tried now to open the part documents silent in backgound, but it didn't bring me to another result. Could you give me a code snippet? My precondition is only an open assembly.

                        • Re: Use EditFreeze in Assembly?
                          Michael Kozikowski

                          With the component document explicitly opened, and the assembly document active, you should be able to edit the component freeze bar in the assembly context. This is required, but we have an SPR 652782 "Cannot IFeatureManager::EditFreeze move the freeze bar of a component in-context to an assembly without having the component document open" to address it. Please use the workaround described.

                            • Re: Use EditFreeze in Assembly?
                              Georg Draxler

                              Sorry, but it dosen't work. Here is my current code:

                               

                                      Dim swapp As sldworks.SldWorks = CType(GetObject(, "SldWorks.Application"), sldworks.SldWorks)

                                      Dim rootDoc As sldworks.ModelDoc2 = swapp.ActiveDoc

                                      Dim rootAssembly As sldworks.AssemblyDoc = rootDoc

                                      Dim selmgr As sldworks.SelectionMgr

                                      Dim seldata As sldworks.SelectData

                                      Dim swDocuments As Array

                               

                                      Dim errors As Integer

                                      Dim warnings As Integer

                               

                                      selmgr = rootDoc.SelectionManager

                                      seldata = selmgr.CreateSelectData

                               

                                      Dim selObject As Object

                               

                                      With selmgr

                                          selObject = .GetSelectedObject6(0, 0)

                                      End With

                               

                                      swDocuments = rootDoc.GetDependencies2(False, False, False)

                               

                                      Dim editPartInfo As swconst.swEditPartCommandStatus_e

                               

                                      Dim Components As Array

                               

                                      Components = rootAssembly.GetComponents(True)

                               

                                      Dim swDocForLoop As sldworks.ModelDoc2

                                      Dim fm As New FeatureFreeze

                                      Dim docToOpen As sldworks.ModelDoc2

                                      For Each Component As sldworks.Component2 In Components

                                          swDocForLoop = Component.GetModelDoc2

                                          If swDocForLoop.GetType = swconst.swDocumentTypes_e.swDocPART Then

                                              docToOpen = swapp.OpenDoc6(swDocForLoop.GetPathName, _

                                                                          swconst.swDocumentTypes_e.swDocPART, _

                                                                          swconst.swOpenDocOptions_e.swOpenDocOptions_Silent, _

                                                                          "", errors, warnings)

                                              If docToOpen Is Nothing Then

                                                  docToOpen = swapp.GetOpenDocument(swDocForLoop.GetPathName)

                                              End If

                                              Component.Select4(False, seldata, False)

                                              rootAssembly.EditPart2(True, False, editPartInfo)

                               

                                              Debug.WriteLine(editPartInfo)

                                              Debug.WriteLine(Component.Name2)

                                              fm.Freeze_(docToOpen, rootDoc, swapp)

                               

                                          End If

                               

                                      Next

                                 End Sub

                               

                              And here is the code of Freeze_:

                               

                              Function Freeze_(ByVal swDoc As ModelDoc2, ByVal rootDocument As ModelDoc2, ByVal swApp As SldWorks)

                                      Dim swModelDocExt As ModelDocExtension = swDoc.Extension

                                      Dim featMgr As FeatureManager

                                      Dim selMgr As SelectionMgr

                                      Dim Boolstat As Boolean = True

                                      Dim feat As Feature

                                      Dim activeRootDoc As ModelDoc2

                                      Dim acterror As swActivateDocError_e

                                      'Dim swPart As SolidWorks.Interop.sldworks.PartDoc

                               

                                      'Get ModelDocs Featuermanager and Selectionmanger

                                      featMgr = swDoc.FeatureManager

                                      selMgr = swDoc.SelectionManager

                               

                                      feat = featMgr.GetFreezeLocation

                                      'swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swRebuildOnActivation, swRebuildOnActivation_e.swDontRebuildActiveDoc)

                               

                                      'Move featurefreeze to bottom of featuretree if Model is not freezed

                                      If feat Is Nothing Then

                                          activeRootDoc = swApp.ActivateDoc3(rootDocument.GetPathName, False, swRebuildOnActivation_e.swDontRebuildActiveDoc, acterror)

                                          Boolstat = featMgr.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", False)

                                      Else

                                          Return False

                                          Exit Function

                                      End If

                                      'Check if model is freezed now

                                      feat = featMgr.GetFreezeLocation

                                      'If model is not freezed do a force rebuild and freeze again

                                      If feat Is Nothing Then

                                          swDoc.ForceRebuild3(False)

                                          activeRootDoc = swApp.ActivateDoc3(rootDocument.GetPathName, False, swRebuildOnActivation_e.swDontRebuildActiveDoc, acterror)

                                          Boolstat = featMgr.EditFreeze(swMoveFreezeBarTo_e.swMoveFreezeBarToEnd, "", False)

                                      End If

                                      Return True

                                  End Function

                               

                              Please copy&past and give it a try. Please tell me where my error is.

                              If i activate the part component (activeRootDoc = swApp.ActivateDoc3(swDoc.GetPathName, False, swRebuildOnActivation_e.swDontRebuildActiveDoc, acterror) ) it works, but i don't want to activate the part. (with activate i mean that the part doc becomes the model currently showing in solidworks)

                               

                              Added more Information

                            • Re: Use EditFreeze in Assembly?
                              Artem Taturevych

                              Georg,

                               

                              When you have an opened assembly with components not lightweight or suppressed that means that the models already loaded in memory and you can just make them visible instead of opening (this actually would be the same). In other words performance will be not critically decreased. Try the ModelDoc2::Visible property.

                              ______________________

                              Regards,

                              Artem Taturevych

                              Application Engineer at Intercad

                              http://intercad.com.au/

                              Tel: +61 2 9454 4444