4 Replies Latest reply on Jul 7, 2014 6:52 PM by Sushil Chaskar

    Getting offset planes..

    Sushil Chaskar

      Trying to get no. of planes automatically.. Getting error as Object variable not set in bolded line.. Any help ?

       

      Dim swApp As Object  

       

       

       

       

      Dim Part, Model As Object 

       

       

      Dim planeName, newPlaneName As String

       

       

      Dim planeFeature As Object

       

       

      Dim i, planeCount As Integer

       

       

      Set swApp = CreateObject("SldWorks.Application")

       

       

      Set Model = swApp.ActiveDoc

       

       

      If Model Is Nothing Then

       

       

      Exit Sub

       

       

      End If

       

       

      newPlaneName = "Plane1"

       

       

      planeCount = 0

       

       

       

       

      For i = 1 To 5

       

       

      Model.ClearSelection

       

       

      Model.SelectByID newPlaneName, "PLANE", 0, 0, 0

       

       

      Model.CreatePlaneAtOffset 0.1, 0

       

       

       

       

      planeCount = planeCount + 1

       

       

       

       

      planeName = "Plane" & planeCount

       

       

      newPlaneName = "MyPlane" & i

       

       

       

       

      Set planeFeature = Model.FeatureByName(planeName)

       

       

       

       

      planeFeature.Name = (newPlaneName)

       

       

      Model.EditRebuild

       

       

      Next

       

       

       

       

      End Sub

        • Re: Getting offset planes..
          Artem Taturevych

          You do not have a features with names Plane1, Plane2, Plane3, Plane4, Plane5

            • Re: Getting offset planes..
              Sushil Chaskar

              Artem, thank you. Can you suggest changes in algo.

                • Re: Getting offset planes..
                  Artem Taturevych

                  Hi, Try this:

                   

                  For i = 1 To 5

                   

                  Model.ClearSelection

                   

                  Model.SelectByID newPlaneName, "PLANE", 0, 0, 0

                   

                  Set planeFeature = Model.CreatePlaneAtOffset3 (0.1, False, True)

                   

                  planeCount = planeCount + 1

                   

                  planeName = "Plane" & planeCount

                   

                  newPlaneName = "MyPlane" & i

                   

                  Set planeFeature = Model.FeatureByName(planeName)

                   

                  planeFeature.Name = newPlaneName

                   

                  Model.EditRebuild

                   

                  Next

                   

                  Also make sure that you have a master plane named 'Plane1' or change this line to appropriate name:

                   

                  newPlaneName = "Plane1"

                    • Re: Getting offset planes..
                      Sushil Chaskar

                      Thank you very much.. Can you do me another favour ? Been trying to get 3d intersection curves between plane and model for number of planes.. Did this way..For this, first I am selecting all faces of model, then getting plane count and then creating 3d intersections for each plane. But getting only one skech... Can you suggest ?  FI: count1 is number of faces and Count is number of planes (including basic three planes)

                       

                       

                      Option Explicit

                       

                       

                      Sub main()

                       

                       

                          Dim swApp As SldWorks.SldWorks

                       

                          Dim swModel As SldWorks.ModelDoc2

                       

                          Dim swSelMgr As SldWorks.SelectionMgr

                       

                          Dim swSelData As SldWorks.SelectData

                       

                       

                          Dim swPart              As SldWorks.PartDoc

                       

                       

                          Dim swBody              As SldWorks.Body2

                       

                       

                          Dim swFace              As SldWorks.Face

                       

                       

                          Dim swEnt               As SldWorks.Entity

                       

                       

                          Dim bRet                As Boolean

                       

                       

                          Dim vBodies             As Variant

                         

                          Dim boolstatus         As Boolean

                       

                           Dim count1 As integer

                       

                           count1 = 0

                        

                          Set swApp = CreateObject("SldWorks.Application")

                       

                       

                          Set swModel = swApp.ActiveDoc

                       

                       

                          Set swPart = swModel

                       

                       

                          Set swSelMgr = swModel.SelectionManager

                       

                       

                          Set swSelData = swSelMgr.CreateSelectData

                       

                       

                          vBodies = swPart.GetBodies2(swAllBodies, True)

                       

                       

                          Set swBody = vBodies(0)

                       

                       

                          Set swFace = swBody.GetFirstFace

                       

                       

                        

                          swModel.ClearSelection2 True

                       

                       

                        

                          Do While Not swFace Is Nothing

                       

                       

                              Set swEnt = swFace

                       

                       

                            

                              ' Select through Entity

                       

                       

                              bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet

                       

                       

                            

                              Set swFace = swFace.GetNextFace

                                  

                               count1 = count1 + 1

                         

                      Loop

                        

                          Dim Count As Integer

                          Count = 0

                          Dim swfeature As SldWorks.Feature

                          Set swfeature = swModel.FirstFeature

                         While Not swfeature Is Nothing

                         If swfeature.GetTypeName = "RefPlane" Then

                         swfeature.Select2 True, 0

                            Count = Count + 1

                         End If

                           Set swfeature = swfeature.GetNextFeature

                        Wend

                       

                        MsgBox Count

                          Dim i , j As Integer

                          For i = 1 To Count - 3

                          boolstatus = swModel.Extension.SelectByID2("Plane" & i, "PLANE", 0, 0, 0, False, 0, Nothing, 0)

                          swModel.SketchManager.InsertSketch True

                          swModel.Sketch3DIntersections

                          For j = 1 to count1

                      boolstatus = swModel.Extension.SelectByID2("Face" & i, "FACE", 0, 0, 0, False, 0, Nothing, 0)

                          Next j

                          swModel.Sketch3DIntersections

                          swModel.ClearSelection2 True

                          swModel.Sketch3DIntersections

                          swModel.ClearSelection2 True

                          swModel.SketchManager.InsertSketch True

                      Next i

                      End Sub