9 Replies Latest reply on Sep 26, 2016 10:31 PM by Frank Wu Frank Wu

    SketchManager::MakeSketchBlockFromFile  Return Value =Nothing

    Frank Wu Frank Wu


           When I insert the same sketch block, always get an empty return value.

           I have tried many ways. But no one will work.

           Anyone can help me?




           My Code is below:



        Public Sub InsertPlugView(PtX As Object, PtY As Object, PtZ As Object, objPlugBlockPath As Object, objPlugBlockNbr As Integer)



              Dim swDoc As ModelDoc2 = Nothing

              Dim swPart As PartDoc = Nothing

              Dim swDrawing As DrawingDoc = Nothing

              Dim swAssembly As AssemblyDoc = Nothing

              Dim boolstatus As Boolean = False

              Dim longstatus As Integer = 0

              Dim longwarnings As Integer = 0


              Dim swSketchBlockDef As SketchBlockDefinition


              Dim plugPt(0 To 2) As Double

              Dim objPlugPt As Object


              Dim swSkBlockNm As String

              Dim MathUtility As MathUtility

              Dim swMathPt As MathPoint


              Dim swBlockInst As SketchBlockInstance


              swApp = GetObject(, "SldWorks.Application")

              swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swSketchInference, False)

              swDoc = swApp.ActiveDoc

              swDrawing = swDoc

              boolstatus = swDrawing.ActivateSheet("Sheet1")


              For i = 0 To objPlugBlockNbr - 1

                  swSkBlockNm = Application.StartupPath + objPlugBlockPath(i)

                  plugPt(0) = Val(PtX(i)) : plugPt(1) = Val(PtY(i)) : plugPt(2) = Val(PtZ(i))

                  objPlugPt = plugPt

                  MathUtility = swApp.GetMathUtility

                  swMathPt = MathUtility.CreatePoint (objPlugPt)


                  'Insert Block

                  swSketchBlockDef = swDoc.SketchManager.MakeSketchBlockFromFile(swMathPt, swSkBlockNm, False, 1, 0)


                  'swSketchBlockDef =Nothing error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


                   swBlockInst = swSketchBlockDef.GetInstances()(0)

                  'Explode Block



                  swDoc.SetPickMode ()



              Next i

          End Sub