5 Replies Latest reply on Feb 7, 2013 12:01 PM by Jacob Filek

    Autosize Refplanes

    Jacob Filek
      I would like to know if anyone can help me.
      I'm trying to create a macro to "Autosize" the first three planes in a part.
      It's a very frustrating problem when I see many part models created by other users that do not autosize the planes.
      In the API there is a IRefPlaneFeatureData.AutoSize() Property that accepts a true or false.
      The problem is that it does nothing. It doesn't matter what version the part was created either pre 2009 or post 2010.
      Here is my code...
      Do While Not Feat Is Nothing
      If Feat.GetTypeName.ToString = "RefPlane" Then
      Dim  finfo As SldWorks.RefPlaneFeatureData
      finfo = Feat.GetDefinition
      If finfo IsNot Nothing Then
      finfo.AutoSize = True
      End If
      End If
      Loop
        • Re: Autosize Refplanes
          Keith Rice

          This is because you are not modifying the feature definition. After calling AutoSize you need to use IFeature::ModifyDefinition and pass in the IRefPlaneFeatureData object. If this doesn't work either then you may need to use IRefPlaneFeatureData::AccessSelections immediately after using IFeature::GetDefinition.

           

          Keith

          Video Tutorials for the SolidWorks API

            • Re: Autosize Refplanes
              Jacob Filek

              Thanks Keith,

               

              I updated my code...

               

               

              swModel = swApp.ActiveDoc

               

              Do While Not Feat Is Nothing

                   If Feat.GetTypeName.ToString = "RefPlane" Then

               

                        Dim finfo as SldWorks.RefPlaneFeatureData

                        finfo = Feat.GetDefinition

                        finfo.AccessSelections(swModel, Nothing)

                        finfo.AutoSize = True

                        Feat.ModifyDefinition(finfo, swModel, Nothing)

               

                   End If

               

              Feat = Feat.GetNextFeature

              Loop

               

              Still Nothing Happens!

                • Re: Autosize Refplanes
                  Jacob Filek

                  In the IRefPlaneFetureData Interface Remarks:

                   

                  Before calling any of the methods and properties on this interface, you should determine the reference plane's type because some IRefPlaneFeatureData methods and properties only work with constraint-based reference planes and some only work with non-constrained reference planes. Use IRefPlaneFeatureData::Type2 to determine the type of reference plane.

                  If IRefPlaneFeatureData::Type2 returns swRefPlaneConstraintBase, then the reference plane is constraint based. To determine if a constraint-based reference plane has angle or offset distances references, call IRefPlaneFeatureData::Type:

                  • swRefPlaneAngle is returned for angle references. 
                  • swRefPlaneDistance is returned for offset distance references.

                  Otherwise, the reference plane is not constraint based. Call IRefPlaneFeatureData::Type to determine its type.

                  NOTE: Reference planes created in SolidWorks 2010 or later are constraint based; reference planes created in SolidWorks 2009 or earlier are not.

                  The following table shows which IRefPlaneFeatureData methods and properties to use with which types of reference planes.

                   

                   

                  Method or property

                  Constraint-based

                  Constraint-based
                  with angle or offset distance
                  references

                  Not
                  constraint-based

                  AccessSelections

                  ?

                  ?

                  ?

                  GetSelectionsCount

                  ?

                  ?

                  ?

                  IAccessSelections

                  ?

                  ?

                  ?

                  IGetSelections

                  ?

                  ?

                  ?

                  ISetSelections

                  X

                   

                  ?

                  ?

                  ReleaseSelectionAccess

                  ?

                  ?

                  ?

                  Angle

                  X

                  ?

                  ?

                  AngleOrDistance 

                  ?

                  ?

                   

                  X

                  AutoSize

                  X

                   

                  ?

                  ?

                  Constraint

                  ?

                  ?

                  X

                  Distance

                  X

                  ?

                  ?

                  OriginOnCurve 

                  X

                   

                  ?

                  ?

                  ProjectionType

                  X

                   

                  ?

                  ?

                  Reference

                  ?

                  ?

                   

                  X

                  ReverseDirection

                  X

                   

                  ?

                  ?

                  Selections

                  ?
                  (get only)

                  ?

                  ?

                  SolutionIndex

                  X

                   

                  ?

                  ?

                  Type 

                  X

                  ?

                  ?

                  Type2

                  ?

                  ?

                  X

                  UseNormalPlane

                  X

                   

                  ?

                  ?

              • Re: Autosize Refplanes
                Artem Taturevych

                It is possible to do this via the SolidWorks command. Please find the macro in the attachment which auto sizes all planes and here the VB.NET equivalent for Auto Size first three standard planes. You should add the reference to SolidWorks Commands Type Library in your macro/project.

                 

                Dim Feat As Feature = swApp.IActiveDoc2.FirstFeature

                 

                While Feat.GetTypeName2 <> "OriginProfileFeature"

                      If Feat.GetTypeName = "RefPlane" Then

                            Feat.Select2(False, -1)

                            swApp.RunCommand(swCommands_e.swCommands_Auto_Size, "")

                      End If

                      Feat = Feat.GetNextFeature

                End While

                 

                swApp.IActiveDoc2.GraphicsRedraw2()

                __________________________

                Regards,

                Artem Taturevych

                Application Engineer at Intercad

                http://intercad.com.au/

                Tel: +61 2 9454 4444

                  • Re: Autosize Refplanes
                    Jacob Filek

                    Thanks Mate

                     

                     

                    Here is my code...

                     

                     

                    Dim Feat As SldWorks.Feature = swModel.FirstFeature

                    Do While Not Feat Is Nothing

                         If Feat.GetTypeName.ToString = "RefPlane" Then

                     

                     

                              Feat.Select2(False, -1)

                     

                              swApp.RunCommand(swCommands_Auto_Size, ""

                         End If

                         Feat = Feat.GetNextFeature

                    Loop

                    swModel.GraphicsRedraw2()