2 Replies Latest reply on Feb 20, 2018 7:47 AM by Slawomir Paluch

    współrzędne punktów w szkicu

    Slawomir Paluch

      Witam, jestem debiutantem w SW, potrzebuję w automatyczny sposób zczytywc współrzędne punktów ze szkicu 3D, jak się zabrac do tego

        • Re: współrzędne punktów w szkicu
          Ivana Kolin
          '---------------------------------------------
          ' Preconditions:
          ' 1. Open a part and select a sketch.
          ' 2. Open the Immediate window.
          '
          ' Postconditions:
          ' 1. Gets all points of the sketch.
          ' 2. Examine the Immediate window.
          '---------------------------------------------
          Option Explicit
           Function TransformSketchPointToModelSpace(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swSketch As SldWorks.Sketch, swSkPt As SldWorks.SketchPoint) As SldWorks.MathPoint
              Dim swMathUtil As SldWorks.MathUtility
              Dim swXform As SldWorks.MathTransform
              Dim nPt(2) As Double
              Dim vPt  As Variant
              Dim swMathPt As SldWorks.MathPoint
              nPt(0) = swSkPt.X:      nPt(1) = swSkPt.Y:      nPt(2) = swSkPt.Z
              vPt = nPt
              Set swMathUtil = swApp.GetMathUtility
              Set swXform = swSketch.ModelToSketchTransform
              Set swXform = swXform.Inverse
              Set swMathPt = swMathUtil.CreatePoint((vPt))
              Set swMathPt = swMathPt.MultiplyTransform(swXform)
              Set TransformSketchPointToModelSpace = swMathPt
          End Function
          Sub ProcessSketchPoint(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swSketch As SldWorks.Sketch, swSketchPt As SldWorks.SketchPoint)
               
              Dim swModPt As SldWorks.MathPoint
              Set swModPt = TransformSketchPointToModelSpace(swApp, swModel, swSketch, swSketchPt)
              Debug.Print "       (sketch)   = (" & swSketchPt.X * 1000# & ", " & swSketchPt.Y * 1000# & ", " & swSketchPt.Z * 1000# & ") mm"
              Debug.Print "       (model )   = (" & swModPt.ArrayData(0) * 1000# & ", " & swModPt.ArrayData(1) * 1000# & ", " & swModPt.ArrayData(2) * 1000# & ") mm"
            End Sub
          
            Sub main()
              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swSelMgr As SldWorks.SelectionMgr
              Dim swFeat As SldWorks.Feature
              Dim swSketch As SldWorks.Sketch
              Dim vskPtArr As Variant
              Dim vskPt As Variant
              Dim swSkPt  As SldWorks.SketchPoint
            
              Dim vID As Variant
              Dim i As Long
              Dim bRet As Boolean
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swSelMgr = swModel.SelectionManager
              Set swFeat = swSelMgr.GetSelectedObject5(1)
              Set swSketch = swFeat.GetSpecificFeature
              Debug.Print "Feature = " & swFeat.Name & " [" & swSketch.Is3D & "]"
              Debug.Print "  Sketch Segments:"
              vskPtArr = swSketch.GetSketchPoints2
              For Each vskPt In vskPtArr
                  Set swSkPt = vskPt
                  vID = swSkPt.GetID
                  Debug.Print "    ID = [" & vID(0) & "," & vID(1) & "]"
                  ProcessSketchPoint swApp, swModel, swSketch, swSkPt
              Next vskPt
          End Sub