X2021/Wardrobe/SolidWorks/Instructions.vb

195 lines
9.0 KiB
VB.net

Imports SldWorks
Public Class Instructions
Public Shared Sub Generate_Instructions(withFrame As Boolean)
Dim swApp As SldWorks.SldWorks
swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks)
Dim status As Boolean
Dim iDrawing As DrawingDoc
Dim swSheetWidth As Double
swSheetWidth = 0.42
Dim swSheetHeight As Double
swSheetHeight = 0.297
iDrawing = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2020\templates\Drawing.drwdot", 12, swSheetWidth, swSheetHeight)
Dim swSheet As Sheet
swSheet = iDrawing.GetCurrentSheet()
swSheet.SetProperties2(12, 12, 1, 1, False, swSheetWidth, swSheetHeight, True)
swSheet.SetTemplateName(Settings.HLCtFolder & "\Files Needed\A3 Part.slddrt")
swSheet.ReloadTemplate(True)
swSheet.SetScale(1, 10, False, False) ' FIXA
swSheet.SetName("Instructions")
Dim layMgr As LayerMgr
layMgr = iDrawing.GetLayerManager()
status = layMgr.SetCurrentLayer("Svenska")
Dim drawName As String
If withFrame = True Then
drawName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\gratings_assembly_simplified_with_frame.SLDASM"
Else
drawName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\gratings_assembly_simplified.SLDASM"
End If
Dim myView As View
myView = iDrawing.CreateDrawViewFromModelView3(drawName, "*Front", swSheetWidth / 2, swSheetHeight / 2, 0)
myView.UseSheetScale() = True
myView.SetDisplayTangentEdges2(2)
Dim swExtensions As SldWorks.ModelDocExtension
swExtensions = iDrawing.Extension
Dim RootComp = myView.RootDrawingComponent
Dim CompName = RootComp.Name
Dim OutLine = myView.GetOutline
Dim noteAnnotation As IAnnotation
Dim textFormat As Object
Dim balloonName As String
Dim editedNote As Object
'Gratings
status = swExtensions.SelectByID2(myView.GetName2, "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Dim vNotes As Object
Dim autoBalloonParams As Object
autoBalloonParams = iDrawing.CreateAutoBalloonOptions()
autoBalloonParams.Layout = 1
autoBalloonParams.ReverseDirection = False
autoBalloonParams.IgnoreMultiple = True
autoBalloonParams.InsertMagneticLine = False
autoBalloonParams.LeaderAttachmentToFaces = True
autoBalloonParams.Style = 1
autoBalloonParams.Size = 3
autoBalloonParams.EditBalloonOption = 1
autoBalloonParams.EditBalloons = 1
autoBalloonParams.UpperTextContent = 1
autoBalloonParams.UpperText = """"
autoBalloonParams.Layername = "Symbol"
vNotes = iDrawing.AutoBalloon5(autoBalloonParams)
iDrawing.ClearSelection2(True)
Dim gratingCounter As Integer = Grating_Fill.numOfHorizontal * Grating_Fill.numOfVertical - Multiple_3D_Simplified.listOfObsolete.Count
For i = vNotes.Length - 1 To 0 Step -1
If i < Grating_Fill.numOfHorizontal * Grating_Fill.numOfVertical - Multiple_3D_Simplified.listOfObsolete.Count Then
Dim noteInfo = vNotes(i).GetLeaderInfo()
noteAnnotation = vNotes(i).GetAnnotation()
noteAnnotation.SetPosition2(noteInfo(3), noteInfo(4), 0)
noteAnnotation.SetLeader3(0, 1, False, False, False, False)
textFormat = noteAnnotation.GetTextFormat(0)
textFormat.CharHeight = 0.0025
status = noteAnnotation.SetTextFormat(0, False, textFormat)
iDrawing.ClearSelection2(True)
balloonName = vNotes(i).GetName()
status = swExtensions.SelectByID2(balloonName & "@" & myView.GetName2, "NOTE", 0, 0, 0, False, 0, Nothing, 0)
editedNote = swExtensions.EditBalloonProperties2(1, 3, 0, "G-" & gratingCounter, 0, "", 0, False, 1, "X", 0.001)
gratingCounter -= 1
Else
iDrawing.ClearSelection2(True)
balloonName = vNotes(i).GetName()
status = swExtensions.SelectByID2(balloonName & "@" & myView.GetName2, "NOTE", 0, 0, 0, False, 0, Nothing, 0)
iDrawing.EditDelete
End If
Next
Dim straightFrames = Frame_3D.frameDT.Select("TYPE = 'SIDE'")
Dim straightFramesDT As New DataTable
straightFramesDT.Columns.Add("LENGTH", GetType(Integer))
straightFramesDT.Columns.Add("SIDE", GetType(Integer))
For i = 1 To 4
Dim sideNum = i + 1
If sideNum = 5 Then
sideNum = 1
End If
For j = straightFrames.Length - 1 To 0 Step -1
Dim DR As DataRow = straightFrames(j)
If DR("SIDE") = sideNum Then
Dim newDR As DataRow = straightFramesDT.NewRow
newDR("LENGTH") = DR("LENGTH")
newDR("SIDE") = i
straightFramesDT.Rows.Add(newDR)
End If
Next
Next
Dim sideOffsets(3) As Double
Dim cornerFrames = Frame_3D.frameDT.Select("TYPE = 'CORNER'")
For i = 0 To 3
Dim cornerFrameExist As Boolean = False
For j = 0 To cornerFrames.Length
If cornerFrames(j)("CORNER") = i + 1 Then
cornerFrameExist = True
Exit For
End If
Next
If cornerFrameExist = True Then
sideOffsets(i) = 0.21
Else
sideOffsets(i) = 0
End If
Next
Dim worldX, worldY, offsetX, offsetY As Double
Dim scale As Double = myView.ScaleDecimal
For i = 0 To straightFramesDT.Rows.Count - 1
If straightFramesDT.Rows(i)("SIDE") = 1 Then
worldX = swSheetWidth / 2 + (-(Data.gratingL / 1000) / 2 + sideOffsets(0) + (straightFramesDT.Rows(i)("LENGTH") / 1000) / 2) * scale
sideOffsets(0) += straightFramesDT.Rows(i)("LENGTH") / 1000
worldY = swSheetHeight / 2 + ((Data.gratingW / 1000) / 2 + 0.001) * scale
offsetX = worldX - 0.01 - 0.0045
offsetY = worldY + 0.02 + 0.0015
ElseIf straightFramesDT.Rows(i)("SIDE") = 2 Then
worldX = swSheetWidth / 2 + ((Data.gratingL / 1000) / 2 + 0.001) * scale
worldY = swSheetHeight / 2 + ((Data.gratingW / 1000) / 2 - sideOffsets(1) - (straightFramesDT.Rows(i)("LENGTH") / 1000) / 2) * scale
sideOffsets(1) += straightFramesDT.Rows(i)("LENGTH") / 1000
offsetX = worldX + 0.02 - 0.0045
offsetY = worldY + 0.01 + 0.0015
ElseIf straightFramesDT.Rows(i)("SIDE") = 3 Then
worldX = swSheetWidth / 2 + ((Data.gratingL / 1000) / 2 - sideOffsets(2) - (straightFramesDT.Rows(i)("LENGTH") / 1000) / 2) * scale
sideOffsets(2) += straightFramesDT.Rows(i)("LENGTH") / 1000
worldY = swSheetHeight / 2 - ((Data.gratingW / 1000) / 2 + 0.001) * scale
offsetX = worldX + 0.01 - 0.0045
offsetY = worldY - 0.02 + 0.0015
Else
worldX = swSheetWidth / 2 - ((Data.gratingL / 1000) / 2 + 0.001) * scale
worldY = swSheetHeight / 2 + (-(Data.gratingW / 1000) / 2 + sideOffsets(3) + (straightFramesDT.Rows(i)("LENGTH") / 1000) / 2) * scale
sideOffsets(3) += straightFramesDT.Rows(i)("LENGTH") / 1000
offsetX = worldX - 0.02 - 0.0045
offsetY = worldY - 0.01 + 0.0015
End If
status = swExtensions.SelectByRay(worldX, worldY, 0, 0, 0, -1, 0.0005, 2, False, 0, 0)
Dim BomBalloonParams As Object
BomBalloonParams = swExtensions.CreateBalloonOptions()
BomBalloonParams.Style = 1
BomBalloonParams.Size = 3
BomBalloonParams.UpperTextContent = 1
BomBalloonParams.UpperText = """"
BomBalloonParams.ShowQuantity = False
BomBalloonParams.QuantityPlacement = 1
BomBalloonParams.QuantityDenotationText = "X"
BomBalloonParams.QuantityOverride = False
Dim myNote = swExtensions.InsertBOMBalloon2(BomBalloonParams)
noteAnnotation = myNote.GetAnnotation()
textFormat = noteAnnotation.GetTextFormat(0)
textFormat.CharHeight = 0.0025
status = noteAnnotation.SetTextFormat(0, False, textFormat)
noteAnnotation.SetPosition2(offsetX, offsetY, 0)
iDrawing.ClearSelection2(True)
balloonName = myNote.GetName()
status = swExtensions.SelectByID2(balloonName & "@" & myView.GetName2, "NOTE", 0, 0, 0, False, 0, Nothing, 0)
editedNote = swExtensions.EditBalloonProperties2(1, 3, 0, "F-" & i + 1, 0, "", 0, False, 1, "X", 0.001)
Next
End Sub
End Class