We work in the same way, we put the marking manually when creating the file that we will use for the cutting software. I don't think it's possible to do it via a macro because your marking is not done via Solidworks.
SW can display fold lines on the unfolded (drawing) view. Is there a difference with what you are looking for? On your example, there are no "yellow lines"
The code below will create 3mm lines at each end of the flounder lines.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swMathUtil As SldWorks.MathUtility
Dim BendlinesArr As Variant
Dim Bendline As Variant
Dim swSketch As SldWorks.Sketch
Dim swModelToViewXForm As SldWorks.MathTransform
Dim swModelToSketchXForm As SldWorks.MathTransform
Dim swDrawingToViewXForm As SldWorks.MathTransform
Dim swSketchLine As SldWorks.SketchLine
Dim swSkStartPt As SldWorks.SketchPoint
Dim swSkEndPt As SldWorks.SketchPoint
Dim swSketchSeg As SldWorks.SketchSegment
Dim nPt(2) As Double
Dim vPt As Variant
Dim swStartPt As SldWorks.MathPoint
Dim swEndPt As SldWorks.MathPoint
Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
Dim X3 As Double, Y3 As Double, X4 As Double, Y4 As Double
Dim Length As Double, Delta As Double
Sub main()
Set swApp = Application.SldWorks
Set swMathUtil = swApp.GetMathUtility
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Dim swLayerMgr As SldWorks.LayerMgr
Set swLayerMgr = swModel.GetLayerManager
Dim SavedLayerName As String
SavedLayerName = swLayerMgr.GetCurrentLayer
'optionnel: ajoute les lignes sur un nouveau calque'
'swLayerMgr.AddLayer "nouveauCalque", "", 0, 0, 0
'optionnel: ajoute les lignes sur un calque existant'
'swLayerMgr.SetCurrentLayer "monCalque"
While Not swView Is Nothing
If swView.IsFlatPatternView Then
swDraw.ActivateView swView.GetName2
If swView.GetBendLineCount > 0 Then
BendlinesArr = swView.GetBendLines
For Each Bendline In BendlinesArr
Set swSketchLine = Bendline
If swSketchLine.IsBendLine Then
Set swSkStartPt = swSketchLine.GetStartPoint2
Set swSkEndPt = swSketchLine.GetEndPoint2
Set swSketch = swSketchLine.GetSketch
Set swModelToSketchXForm = swSketch.ModelToSketchTransform.Inverse
Set swModelToViewXForm = swView.ModelToViewTransform
Set swDrawingToViewXForm = drawingToViewTransform(swView).Inverse
nPt(0) = swSkStartPt.X
nPt(1) = swSkStartPt.Y
nPt(2) = swSkStartPt.Z
vPt = nPt
Set swStartPt = swMathUtil.CreatePoint(vPt)
Set swStartPt = swStartPt.MultiplyTransform(swModelToSketchXForm)
Set swStartPt = swStartPt.MultiplyTransform(swModelToViewXForm)
Set swStartPt = swStartPt.MultiplyTransform(swDrawingToViewXForm)
nPt(0) = swSkEndPt.X
nPt(1) = swSkEndPt.Y
nPt(2) = swSkEndPt.Z
vPt = nPt
Set swEndPt = swMathUtil.CreatePoint(vPt)
Set swEndPt = swEndPt.MultiplyTransform(swModelToSketchXForm)
Set swEndPt = swEndPt.MultiplyTransform(swModelToViewXForm)
Set swEndPt = swEndPt.MultiplyTransform(swDrawingToViewXForm)
X1 = swStartPt.ArrayData(0)
Y1 = swStartPt.ArrayData(1)
X2 = swEndPt.ArrayData(0)
Y2 = swEndPt.ArrayData(1)
Set swSketchSeg = swSketchLine
'set lines length to 3mm'
Delta = 0.003
Length = swSketchSeg.GetLength
X3 = (X2 - X1) * Delta / Length + X1
Y3 = (Y2 - Y1) * Delta / Length + Y1
X4 = (X1 - X2) * Delta / Length + X2
Y4 = (Y1 - Y2) * Delta / Length + Y2
swModel.SetAddToDB True
Set swSketchSeg = swModel.SketchManager.CreateLine(X1, Y1, 0#, X3, Y3, 0#)
swSketchSeg.Color = RGB(255, 255, 0)
Set swSketchSeg = swModel.SketchManager.CreateLine(X2, Y2, 0#, X4, Y4, 0#)
swSketchSeg.Color = RGB(255, 255, 0)
swModel.SetAddToDB False
End If
Next
End If
End If
Set swView = swView.GetNextView
Wend
swLayerMgr.SetCurrentLayer SavedLayerName
swModel.ClearSelection2 True
End Sub
Public Function drawingToViewTransform(swView As SldWorks.View) As SldWorks.MathTransform
Dim swMathUtil As SldWorks.MathUtility
Dim transformData(15) As Double
Set swMathUtil = swApp.GetMathUtility
transformData(0) = Cos(swView.Angle)
transformData(1) = Sin(swView.Angle)
transformData(2) = 0#
transformData(3) = -Sin(swView.Angle)
transformData(4) = Cos(swView.Angle)
transformData(5) = 0#
transformData(6) = 0#
transformData(7) = 0#
transformData(8) = 1#
transformData(9) = swView.Position(0)
transformData(10) = swView.Position(1)
transformData(11) = 0#
transformData(12) = swView.ScaleDecimal
transformData(13) = 0#
transformData(14) = 0#
transformData(15) = 0#
Set drawingToViewTransform = swMathUtil.CreateTransform(transformData)
End Function
Thank you JeromeP for the macro it works great. All we need is to find a way to make the sketch lines the right color, which are constrained on the fold lines since we remove them afterwards and they are only for the fold up.
Hi, I might also be interested in this macro, but I couldn't get it to work. How exactly does it work?
From an MEP with the bend lines shown, hidden?
Or else it's by copying the code that I make a mistake...
Last point, is it possible to pass these yellow lines on a certain layer as well? (We have an automatic cleaning of the cutting planes with integration that hides some layers, threads and the background layer before saving in dxf)
Before launching the macro, the bend lines must be visible.
To create the lines on the "mylayer" layer, add the following lines after "Sand swView = swView.GetNextView" :
Dim swLayerMgr As SldWorks.LayerMgr Set swLayerMgr = swModel.GetLayerManager Dim SavedLayerName As String SavedLayerName = swLayerMgr.GetCurrentLayer swLayerMgr.SetCurrentLayer "myLayer"
Yes. you just have to put an apostrophe ' in front of the lines :(or delete these lines)
' swModel.SetAddToDB True
' swModel.SetAddToDB False
On the other hand, it will put automatic relationships, so it can do anything, especially if there is a zoom out, so zoom in (even if the room becomes bigger than the screen) before launching the macro.
Making more specific relationships is possible, but it would require more work.
Very nice macro now that I've managed to get it to work! On the other hand, on some impossible part, this bug Example 1 attached, the lines are not in the right place and error in the macro.
In addition, it is impossible to put the strokes on an uncreated layer. But already on the parts where it works it will save us a lot of time!
Hello, when I need to mark the lines at the ends I use a tool in Mycadtools called "MarkFoldLines".
It generates the desired shape at the end of the fold lines. (in this case, a 1mm triangle, but we can very well put a line or other. This path is a block so we have to see if in the options, we can tell it that the blocks are yellow.
Edit: changing the color of the sketch of the block works