9 Replies Latest reply on Aug 9, 2016 7:51 AM by Amen Allah Jlili

    Activate Component Annotation

    Sdiri Marwa

      HI all,

       

      Attached image show what i want to have which is the activation of a specific annotation view in a component in an open assembly.I have tried different methodes but still unable to reach my goal perfectly .

      In fact i was able to activate the view and show it.But my problem is that I had to activate the component to activate its annotation view .

      So i must call ActivateDoc3 which open the part document in new window and i do not want that, i want to activate annotation in component with api as if i was using user interface.

      Thanks

        • Re: Activate Component Annotation
          Amen Allah Jlili

          Alright Marwa, try this:

           

          You need to edit the part in context. You can achieve that by using the AssemblyDoc::EditPart2 method. This will would allow you to edit the part without having to leave the assembly. Grab a ModelDocExtension object from the component in question and use .AnnotationViews to get an array of annotations. Use the AnnotationView::Activate to activate it. Use AssemblyDoc::EditAssembly to return to the assembly.

           

          Hope this works. Let me know if it does.

          ----------------------------------------------------------------------------------------------------------
          CADHero.com -  SolidWorks API automation - +216 21842724 - amen@cadhero.com jliliamen@gmail.com

            • Re: Activate Component Annotation
              Sdiri Marwa

              Thank you for the reply. I have wrote a function doing exactly what you recommended as illustrated in the figure bellow. However  the activate function return false even though i have allowed showing all type of annotations and feature dimensions.So all variable b,b1and b2 return false.

               

                • Re: Activate Component Annotation
                  Amen Allah Jlili

                  Do you mind if you copy-paste the code so I can try it?

                    • Re: Activate Component Annotation
                      Sdiri Marwa

                      Alright here is the function :

                       

                      public void ActivateMyAnnotation(ModelDoc2 swCompModel, string AnnotationViewName, AssemblyDoc swAssembly)

                              {

                                  int nRetval = 0;

                                   int nInfo = 0;

                                   nRetval = swAssembly.EditPart2(true, false, ref nInfo);

                       

                       

                                 ModelDocExtension swModelExt = swCompModel.Extension;

                                  object[] swAnnViews = null;

                                   AnnotationView swAnnView = default(AnnotationView);

                                  int i = -1;

                                  swAnnViews = (object[])swModelExt.AnnotationViews;

                                  Debug.Print("Number of annotation views: " + swModelExt.AnnotationViewCount);

                                  for (i = 0; i <= swModelExt.AnnotationViewCount - 1; i++)

                                  {

                                      swAnnView = (AnnotationView) swAnnViews[i];

                                    Feature  swFeat = (Feature) swAnnView;

                                      Debug.Print("   " + swFeat.Name);

                                      if (swFeat.Name ==AnnotationViewName)

                                      {

                                          bool b=swAnnView.Activate();

                                          bool b1 = swAnnView.Show();

                                          bool b2 = swAnnView.IsShown();

                                          swAssembly.EditAssembly();

                                          break;

                                      }

                                  }

                              }

                        • Re: Activate Component Annotation
                          Amen Allah Jlili

                          Well, just a quick piece of information rom the API help about the AnnotationView::Show, it says

                           

                          Return Value

                          True if the annotations in an annotation view that is not activated are shown (see Remarks)

                          Remarks

                          This method returns false if the annotation view is activated.

                            • Re: Activate Component Annotation
                              Sdiri Marwa

                              Thanks for your help ,well what i want is to activate the annotation view and show its annotations.I guess from your explanation that if the view is successfully activated i should get b=true b1=false and b2=true.And if the annotation view is not activated b=false b1=true and b2=true.Both the scenarios show annotations in the user interface but i get b=false b1=false and b2=false which neither activate the annotation view nor show its annotations

                                • Re: Activate Component Annotation
                                  Amen Allah Jlili

                                  Weird.
                                  I recorded a VBA macro to see the actions SWX records when I display annotations of a part inside an assembly.

                                   

                                   

                                  Try this workaround:

                                   

                                  instead of activating the annotation view, simply select it and then start selecting and activating (ActivateSelectedFeature Method (IModelDoc2)) all the features of the part (bodyfeature type) one by one. Then clear the selection set.

                                   

                                  Recorded macro example:

                                   

                                  ' ******************************************************************************
                                  ' C:\Users\PC\AppData\Local\Temp\swx2608\Macro1.swb - macro recorded on 08/08/16 by PC
                                  ' ******************************************************************************
                                  Dim swApp As Object
                                  
                                  
                                  Dim Part As Object
                                  Dim boolstatus As Boolean
                                  Dim longstatus As Long, longwarnings As Long
                                  
                                  
                                  Sub main()
                                  
                                  
                                  Set swApp = Application.SldWorks
                                  Set Part = swApp.ActiveDoc
                                  Dim myModelView As Object
                                  Set myModelView = Part.ActiveView
                                  myModelView.FrameState = swWindowState_e.swWindowMaximized
                                  boolstatus = Part.Extension.SelectByID2("*Top", "ANNVIEW", 0, 0, 0, False, 0, Nothing, 0)
                                  boolstatus = Part.Extension.SelectByID2("Boss-Extrude1@Arm_Mount-1@assem", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
                                  Part.ActivateSelectedFeature
                                  boolstatus = Part.Extension.SelectByID2("Boss-Extrude2@Arm_Mount-1@assem", "BODYFEATURE", 0, 0, 0, True, 0, Nothing, 0)
                                  Part.ActivateSelectedFeature
                                  boolstatus = Part.Extension.SelectByID2("Boss-Extrude3@Arm_Mount-1@assem", "BODYFEATURE", 0, 0, 0, True, 0, Nothing, 0)
                                  Part.ActivateSelectedFeature
                                  boolstatus = Part.Extension.SelectByID2("Cut-Extrude2@Arm_Mount-1@assem", "BODYFEATURE", 0, 0, 0, True, 0, Nothing, 0)
                                  Part.ActivateSelectedFeature
                                  End Sub
                                  

                                   

                                   

                                  Untitled.png

                      • Re: Activate Component Annotation
                        Sdiri Marwa

                        Well thank you again i appreciate your help.The main reason why i had to use annotation view is that i want to show some part dimension from two different feature(Extrude and Cut) at top assembly level .When i tested the  work around you suggested (i recorded my own macro) it will show all dimensions in extrude and cut feature .