6 Replies Latest reply on Jun 11, 2018 7:36 AM by Danniel Sims

    How to add a point to sheetmetal drawing to tell laser what is the "keep side"?

    Danniel Sims

      Ok, so I have a fairly complicated conversion for flat drawings.  Essentially, we get drawings from our parent company who have a different laser set-up than we do, so we have to change what items go on which layers and changes colors, etc.

       

      My problem is, I need to add a single point on the part drawing to tell the laser which side is the kept part.  It uses this marker to designate where the laser should start cutting( i.e. start inside a hole rather than burn through the part to keep).

       

      I can't find a way to guarantee that I can place a point on a drawing that lands on the part to keep.  My current method selects the center point of a bend line and inserts the point there.  It works fine, except if the part doesn't have a bend.  The fabrication department wants to go back and manually add this, but I've fully automated everything else.  Push a button and it runs through all the flats on a build list and converts them.... except this point.  I could use the bounding box, but I can't think of anyway to prevent the point being placed inside a hole.

       

      Any help would be appreciated.

       

      *This is only a section of the code where I think this would work best:

       

               Set swDraw = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)

              Set swModel = swApp.ActiveDoc

              Set swModelDocExt = swModel.Extension

              Set swSelMgr = swModel.SelectionManager

              status = swDraw.ActivateView("Drawing View1")

              status = swModelDocExt.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.104008832128, 0.1163870710783, 0, False, 0, Nothing, 0)

              Set swView = swSelMgr.GetSelectedObject6(1, -1)

              swModel.ViewZoomtofit2

              Set swRootDrawComp = swView.RootDrawingComponent

       

              sLayerName = "layer1" ' MAIN

              bRet = swDraw.CreateLayer(sLayerName, "LASER", 4194432, swLineCONTINUOUS, swLW_NORMAL, True): Debug.Assert bRet

              swDraw.ChangeComponentLayer sLayerName, False 'True for ALL VIEWS - False for SELECTED VIEW

         

              ' instance.CreateLayer2(Layername, LayerDesc, LayerColor, LayerStyle, LayerWidth, BOn, BPrint)

              'LINETYPES: swLineCONTINUOUS 0, swLineHIDDEN 1, swLinePHANTOM 2, swLineCHAIN 3, swLineCENTER 4, swLineSTITCH 5, swLineCHAINTHICK 6, swLineDEFAULT 7

              'LINE WEIGHTS: swLW_NONE   -1, swLW_THIN 0, swLW_NORMAL 1, swLW_THICK 2, swLW_THICK2 3, swLW_THICK3 4, swLW_THICK4 5, swLW_THICK5 6, swLW_THICK6 7

                          'swLW_NUMBER 8, swLW_LAYER 9, swLW_CUSTOM 10

       

              sLayerName = "layer4" ' BEND LINES

              bRet = swDraw.CreateLayer(sLayerName, "BEND", 8404992, swLineHIDDEN, swLW_NORMAL, True): Debug.Assert bRet ' NEED THIS

         

              sLayerName = "layer30" ' LOCATION

              bRet = swDraw.CreateLayer(sLayerName, "LOCATE", 65535, swLineCONTINUOUS, swLW_NORMAL, True): Debug.Assert bRet ' NEED THIS

             

             'Drawingview1 is still selected - *I WANT TO ADD THE POINT HERE AT SOME X & Y  - this was recorded separately Part should be swModel

              Dim skPoint As Object

              Set skPoint = Part.SketchManager.CreatePoint(X, Y, 0#)

              Part.SetPickMode

              Part.ClearSelection2 True

             

              sLayerName = "layer40"  ' ETCHING

              bRet = swDraw.CreateLayer(sLayerName, "ETCHING", 4227327, swLineCHAIN, swLW_NORMAL, True): Debug.Assert bRet ' NEED THIS

        • Re: How to add a point to sheetmetal drawing to tell laser what is the "keep side"?
          Ivana Kolin
          Option Explicit
          
          
          Sub main()
              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swDrawing As SldWorks.DrawingDoc
              Dim drView As SldWorks.View
              Dim Comp As SldWorks.Component2
              Dim itr As Long
          
          
              Dim vComps As Variant
              Dim vFaces As Variant
              Dim i As Long
              Dim mathUtil As MathUtility
              Dim mp As MathPoint
              Dim vp As Variant
              Dim p(2) As Double
              Dim mtvt As MathTransform
              Dim mtst As MathTransform
              Dim swSketch As Sketch
              Dim vTessTriangles As Variant
              Dim swFace As SldWorks.Face2
              
              Set swApp = Application.SldWorks
              Set mathUtil = swApp.GetMathUtility
              Set swModel = swApp.ActiveDoc
              Set swDrawing = swModel
          
          
              Set drView = swDrawing.ActiveDrawingView
              Debug.Assert Not drView Is Nothing
          
          
              Debug.Assert drView.GetVisibleComponentCount <> 0
              vComps = drView.GetVisibleComponents
          
          
              Debug.Assert Not IsEmpty(vComps)
          
          
              For i = 0 To UBound(vComps)
                  Set Comp = vComps(i)
                  'Get all faces of this component that are visible in this drawing view
                  vFaces = drView.GetVisibleEntities2(Comp, swViewEntityType_Face)
          
          
                  If IsEmpty(vFaces) Then
                      Debug.Print "   No faces."
                  Else
                      swModel.SketchManager.AddToDB = True
                      For itr = 0 To UBound(vFaces)
                          Set swSketch = swModel.SketchManager.ActiveSketch
                          Set mtst = swSketch.ModelToSketchTransform
                          Set mtvt = drView.ModelToViewTransform
                          Set swFace = vFaces(itr)
                          vTessTriangles = swFace.GetTessTriangles(True)
                          p(0) = (vTessTriangles(0) + vTessTriangles(3) + vTessTriangles(6)) / 3
                          p(1) = (vTessTriangles(1) + vTessTriangles(4) + vTessTriangles(7)) / 3
                          p(2) = (vTessTriangles(2) + vTessTriangles(5) + vTessTriangles(8)) / 3
                          vp = p
          
          
                          Set mp = mathUtil.CreatePoint(vp)
                          Set mp = mp.MultiplyTransform(mtvt.Multiply(mtst))
          
          
                          swModel.SketchManager.CreatePoint mp.ArrayData(0), mp.ArrayData(1), mp.ArrayData(2)
          
          
                      Next itr
                      swModel.SketchManager.AddToDB = False
                  End If
              Next i
          End Sub
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
            • Re: How to add a point to sheetmetal drawing to tell laser what is the "keep side"?
              Danniel Sims

              Ivana,

               

              Thank you!  This appears to be doing exactly what I need!  I'm test running my macro through now.

              • Re: How to add a point to sheetmetal drawing to tell laser what is the "keep side"?
                Danniel Sims

                Ivana,

                 

                I need to figure this out, but thank you for this.  The group that will be using this is a little afraid about how close to the edge some of these points end up.  They'd like me to build in some buffer.... but I would have never figured out where to find this on my own.

                  • Re: How to add a point to sheetmetal drawing to tell laser what is the "keep side"?
                    Ivana Kolin

                    this is using first tessellated triangle. You can loop trough all of them and with some math find largest one and use it for the point creation. Or if you don’t mind to have more than one point, then you can add a point for each triangle.

                      • Re: How to add a point to sheetmetal drawing to tell laser what is the "keep side"?
                        Danniel Sims

                        Option Explicit

                        Sub Placepoint()

                         

                        Dim swApp As SldWorks.SldWorks

                        Dim swModel As SldWorks.ModelDoc2

                        Dim swDrawing As SldWorks.DrawingDoc

                        Dim drView As SldWorks.View

                        Dim Comp As SldWorks.Component2

                        Dim itr As Long

                        Dim d1 As Double

                        Dim d2 As Double

                        Dim d3 As Double

                        Dim Pd, PdMax

                         

                        Dim vComps As Variant

                        Dim vFaces As Variant

                        Dim i As Long

                        Dim mathUtil As MathUtility

                        Dim mp As MathPoint

                        Dim vp As Variant

                        Dim p(2) As Double

                        Dim mtvt As MathTransform

                        Dim mtst As MathTransform

                        Dim swSketch As Sketch

                        Dim vTessTriangles As Variant

                        Dim swFace As SldWorks.Face2

                             

                        Set swApp = Application.SldWorks

                        Set mathUtil = swApp.GetMathUtility

                        Set swModel = swApp.ActiveDoc

                        Set swDrawing = swModel

                         

                        Set drView = swDrawing.ActiveDrawingView

                        Debug.Assert Not drView Is Nothing

                         

                        Debug.Assert drView.GetVisibleComponentCount <> 0

                        vComps = drView.GetVisibleComponents

                         

                        Debug.Assert Not IsEmpty(vComps)

                         

                        For i = 0 To UBound(vComps)

                            Set Comp = vComps(i)

                            'Get all faces of this component that are visible in this drawing view

                            vFaces = drView.GetVisibleEntities2(Comp, swViewEntityType_Face)

                         

                            If IsEmpty(vFaces) Then

                                Debug.Print "   No faces."

                            Else

                                swModel.SketchManager.AddToDB = True

                                For itr = 0 To UBound(vFaces)

                                    Set swSketch = swModel.SketchManager.ActiveSketch

                                    Set mtst = swSketch.ModelToSketchTransform

                                    Set mtvt = drView.ModelToViewTransform

                                    Set swFace = vFaces(itr)

                                    vTessTriangles = swFace.GetTessTriangles(True)

                                   

                                    Do Until itr = ((UBound(vTessTriangles) + 1) / 9)

                         

                                        'Length of line in XYZ 1-2pt, 2-3pt, 3-1pt

                         

                                        d1 = Sqrt((vTessTriangles(9 * itr + 3) - vTessTriangles(9 * itr + 0)) ^ 2_

                                            + (vTessTriangles(9 * itr + 4) - vTessTriangles(9 * itr + 1)) ^ 2_

                                            + (vTessTriangles(9 * itr + 5) - vTessTriangles(9 * itr + 2)) ^ 2)

                         

                                        d2 = Sqrt((vTessTriangles(9 * itr + 6) - vTessTriangles(9 * itr + 3)) ^ 2_

                                            + (vTessTriangles(9 * itr + 7) - vTessTriangles(9 * itr + 4)) ^ 2_

                                            + (vTessTriangles(9 * itr + 8) - vTessTriangles(9 * itr + 5)) ^ 2)

                         

                                        d3 = Sqrt((vTessTriangles(9 * itr + 0) - vTessTriangles(9 * itr + 6)) ^ 2_

                                            + (vTessTriangles(9 * itr + 1) - vTessTriangles(9 * itr + 7)) ^ 2_

                                            + (vTessTriangles(9 * itr + 2) - vTessTriangles(9 * itr + 8)) ^ 2)

                                      

                                        'Perimeter Calc

                                        Pd = d1 + d2 + d3

                                       

                                       'Keep largest perimeter               

                                        If Pd > PdMax Then

                                            PdMax = Pd

                                            p(0) = (vTessTriangles(9 * itr + 0) + vTessTriangles(9 * itr + 3) + vTessTriangles(9 * itr + 6)) / 3

                                                        'p(0) = (vTessTriangles(0) + vTessTriangles(3) + vTessTriangles(6)) / 3

                                            p(1) = (vTessTriangles(9 * itr + 1) + vTessTriangles(9 * itr + 4) + vTessTriangles(9 * itr + 7)) / 3

                                                          'p(1) = (vTessTriangles(1) + vTessTriangles(4) + vTessTriangles(7)) / 3

                                            p(2) = (vTessTriangles(9 * itr + 2) + vTessTriangles(9 * itr + 5) + vTessTriangles(9 * itr + 8)) / 3

                                                          'p(2) = (vTessTriangles(2) + vTessTriangles(5) + vTessTriangles(8)) / 3

                                       

                                        End If

                                    itr = itr + 1

                                    Loop

                         

                                    vp = p

                         

                                    Set mp = mathUtil.CreatePoint(vp)

                                    Set mp = mp.MultiplyTransform(mtvt.Multiply(mtst))

                         

                                   swModel.SketchManager.CreatePoint mp.ArrayData(0), mp.ArrayData(1), mp.ArrayData(2)

                         

                                Next itr

                                swModel.SketchManager.AddToDB = False

                               

                                End If

                            Next i

                        End Sub

                        • Re: How to add a point to sheetmetal drawing to tell laser what is the "keep side"?
                          Danniel Sims

                          Again, thanks so much.  I just ran this again this morning with the new code and it works beautifully!  There's an occasional point near an edge, but the vast majority are much more centrally located.