X2021/Wardrobe/SolidWorks/Instructions.vb

431 lines
22 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)
swSheet.SetName("Instructions")
Dim layMgr As LayerMgr
layMgr = iDrawing.GetLayerManager()
status = layMgr.SetCurrentLayer("Svenska")
Dim drawName As String
If AppForm.fillMode = True Then
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
Else
If withFrame = True Then
drawName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\GRATING_ASSEMBLY_SIMPLIFIED_WITH_FRAME.SLDASM"
Else
drawName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\GRATING_ASSEMBLY_SIMPLIFIED.SLDASM"
End If
End If
Dim adjustedHeightPosInSheet As Double = swSheetHeight / 2 + 0.02
Dim myView As View
myView = iDrawing.CreateDrawViewFromModelView3(drawName, "*Front", swSheetWidth / 2, adjustedHeightPosInSheet, 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 numOfGratings = 1
If AppForm.fillMode = True Then
numOfGratings = Calculate_Fill_Grid.numOfHorizontal * Calculate_Fill_Grid.numOfVertical - Multiple_3D_Simplified.listOfObsolete.Count
End If
Dim gratingCounter As Integer = numOfGratings
For i = vNotes.Length - 1 To 0 Step -1
If i < numOfGratings 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
If withFrame = True Then
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))
straightFramesDT.Columns.Add("OFFSET_W", GetType(Integer))
straightFramesDT.Columns.Add("OFFSET_L", 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
newDR("OFFSET_W") = DR("OFFSET_W")
newDR("OFFSET_L") = DR("OFFSET_L")
straightFramesDT.Rows.Add(newDR)
End If
Next
Next
Dim worldX, worldY, offsetX, offsetY As Double
Dim scale As Double = myView.ScaleDecimal
For i = 0 To straightFramesDT.Rows.Count - 1
Dim offsetL As Double = straightFramesDT.Rows(i)("OFFSET_L") / 1000
Dim offsetW As Double = straightFramesDT.Rows(i)("OFFSET_W") / 1000
Dim length As Double = straightFramesDT.Rows(i)("LENGTH") / 1000
If straightFramesDT.Rows(i)("SIDE") = 1 Then
worldX = swSheetWidth / 2 + (-(Data.gratingL / 1000) / 2 + offsetL - length / 2) * scale
worldY = adjustedHeightPosInSheet + ((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 = adjustedHeightPosInSheet + (-(Data.gratingW / 1000) / 2 + offsetW + length / 2) * scale
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 + offsetL + length / 2) * scale
worldY = adjustedHeightPosInSheet - ((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 = adjustedHeightPosInSheet + (-(Data.gratingW / 1000) / 2 + offsetW - length / 2) * scale
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
Dim cornerFrames = Frame_3D.frameDT.Select("TYPE = 'CORNER'")
For i = 0 To cornerFrames.Length - 1
If cornerFrames(i)("CORNER") = 1 Then
worldX = swSheetWidth / 2 - ((Data.gratingL / 1000) / 2 + 0.001) * scale
worldY = adjustedHeightPosInSheet + ((Data.gratingW / 1000) / 2 + 0.001) * scale
offsetX = worldX - 0.022 - 0.01
offsetY = worldY + 0.002 + 0.01
ElseIf cornerFrames(i)("CORNER") = 2 Then
worldX = swSheetWidth / 2 + ((Data.gratingL / 1000) / 2 + 0.001) * scale
worldY = adjustedHeightPosInSheet + ((Data.gratingW / 1000) / 2 + 0.001) * scale
offsetX = worldX + 0.01
offsetY = worldY + 0.002 + 0.01
ElseIf cornerFrames(i)("CORNER") = 3 Then
worldX = swSheetWidth / 2 + ((Data.gratingL / 1000) / 2 + 0.001) * scale
worldY = adjustedHeightPosInSheet - ((Data.gratingW / 1000) / 2 + 0.001) * scale
offsetX = worldX + 0.01
offsetY = worldY - 0.002 - 0.01
Else
worldX = swSheetWidth / 2 - ((Data.gratingL / 1000) / 2 + 0.001) * scale
worldY = adjustedHeightPosInSheet - ((Data.gratingW / 1000) / 2 + 0.001) * scale
offsetX = worldX - 0.022 - 0.01
offsetY = worldY - 0.002 - 0.01
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 = 0
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(0, 3, 0, "Frame Corner", 0, "", 0, False, 1, "X", 0.001)
Next
End If
status = layMgr.AddLayer("Symbol", "", 0, 0, 2)
status = layMgr.SetCurrentLayer("Symbol")
Dim swSkMgr As SketchManager
swSkMgr = iDrawing.SketchManager
status = iDrawing.ActivateSheet("Sheet1")
Dim skSegment As Object
swSkMgr.AddToDB = True
Dim sheetProp = swSheet.GetProperties()
Dim sheetScale = myView.ScaleDecimal
For i = 0 To Draw_Grating.DirSymbolPoints.Count - 2
Dim x1, x2, y1, y2 As Double
x1 = CDbl((Draw_Grating.DirSymbolPoints(i)(0) - Data.guiPanelMidX) / (2000 * sheetScale)) + (swSheetWidth - 0.05) / sheetScale
y1 = -CDbl((Draw_Grating.DirSymbolPoints(i)(1) - Data.guiPanelMidY) / (2000 * sheetScale)) + (swSheetHeight / 2) / sheetScale
x2 = CDbl((Draw_Grating.DirSymbolPoints(i + 1)(0) - Data.guiPanelMidX) / (2000 * sheetScale)) + (swSheetWidth - 0.05) / sheetScale
y2 = -CDbl((Draw_Grating.DirSymbolPoints(i + 1)(1) - Data.guiPanelMidY) / (2000 * sheetScale)) + (swSheetHeight / 2) / sheetScale
skSegment = swSkMgr.CreateLine(x1, y1, 0, x2, y2, 0)
Next
swSkMgr.AddToDB = False
Dim note = iDrawing.CreateText2("Load Bearing Direction", (swSheetWidth - 0.072), (swSheetHeight / 2 + 0.012), 0, 0.003, 0)
' --- instruction for support beams ---
If Calculate_Fill_Grid.withSupportBeam = True Then
status = iDrawing.NewSheet3("Support Beams", 12, 12, 1, 10, False, Settings.HLCtFolder & "\Files Needed\A3 Part.slddrt",
swSheetWidth, swSheetHeight, "Same as sheet specified in Document Properties")
status = layMgr.SetCurrentLayer("Svenska")
drawName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\GRATINGS_ASSEMBLY_SIMPLIFIED.SLDASM"
myView = iDrawing.CreateDrawViewFromModelView3(drawName, "*Front", swSheetWidth / 2, adjustedHeightPosInSheet, 0)
myView.UseSheetScale() = True
myView.SetDisplayTangentEdges2(2)
status = myView.SetDisplayMode3(False, 1, False, False)
RootComp = myView.RootDrawingComponent
CompName = RootComp.Name
Dim gratingName, plane1Name, plane2Name As String
Dim viewName As String = myView.GetName2
Dim horizontalBeams = Calculate_Fill_Grid.supportBeamsDT.Select("ROTATION = '90'", "GLOBAL_OFFSET DESC")
If horizontalBeams.Length > 0 Then
status = False
Dim counter As Integer = 1
While status = False
gratingName = "SIMPLIFIED_FLOOR_GRATING_" & counter
iDrawing.ClearSelection2(True)
plane1Name = "Point1@SW1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane1Name, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
counter += 1
End While
gratingName = "SUPPORT_BEAM_" & horizontalBeams(0)("INDEX")
plane2Name = "Point6@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane2Name, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
Dim measurement As IDisplayDimension
OutLine = myView.GetOutline
measurement = iDrawing.AddVerticalDimension2(OutLine(0) - 0.005, 0, 0)
iDrawing.ClearSelection2(True)
Set_MeasurementProperties(measurement)
For i = 0 To horizontalBeams.Length - 2
gratingName = "SUPPORT_BEAM_" & horizontalBeams(i)("INDEX")
plane1Name = "Point6@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane1Name, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
gratingName = "SUPPORT_BEAM_" & horizontalBeams(i + 1)("INDEX")
plane2Name = "Point6@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane2Name, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
measurement = iDrawing.AddVerticalDimension2(OutLine(0) - 0.005, 0, 0)
iDrawing.ClearSelection2(True)
Set_MeasurementProperties(measurement)
Next
status = False
counter = 1
While status = False
gratingName = "SIMPLIFIED_FLOOR_GRATING_" & Calculate_Fill_Grid.numOfHorizontal * (Calculate_Fill_Grid.numOfVertical - 1) + counter
iDrawing.ClearSelection2(True)
plane1Name = "Point1@SW2@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane1Name, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
counter += 1
End While
gratingName = "SUPPORT_BEAM_" & horizontalBeams(horizontalBeams.Length - 1)("INDEX")
plane2Name = "Point6@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane2Name, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
OutLine = myView.GetOutline
measurement = iDrawing.AddVerticalDimension2(OutLine(0) - 0.005, 0, 0)
iDrawing.ClearSelection2(True)
Set_MeasurementProperties(measurement)
measurement.ShowParenthesis = True
End If
Dim verticalBeams = Calculate_Fill_Grid.supportBeamsDT.Select("ROTATION = '0'", "GLOBAL_OFFSET ASC")
If verticalBeams.Length > 0 Then
status = False
Dim counter As Integer = 0
While status = False
gratingName = "SIMPLIFIED_FLOOR_GRATING_" & counter * Calculate_Fill_Grid.numOfHorizontal + 1
iDrawing.ClearSelection2(True)
plane1Name = "Point1@SL1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane1Name, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
counter += 1
End While
gratingName = "SUPPORT_BEAM_" & verticalBeams(0)("INDEX")
plane2Name = "Point1@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane2Name, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
OutLine = myView.GetOutline
Dim measurement As IDisplayDimension
measurement = iDrawing.AddHorizontalDimension2(0, OutLine(3) + 0.005, 0)
iDrawing.ClearSelection2(True)
Set_MeasurementProperties(measurement)
For i = 0 To verticalBeams.Length - 2
gratingName = "SUPPORT_BEAM_" & verticalBeams(i)("INDEX")
plane1Name = "Point1@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane1Name, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
gratingName = "SUPPORT_BEAM_" & verticalBeams(i + 1)("INDEX")
plane2Name = "Point1@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane2Name, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
measurement = iDrawing.AddHorizontalDimension2(0, OutLine(3) + 0.005, 0)
iDrawing.ClearSelection2(True)
Set_MeasurementProperties(measurement)
Next
status = False
counter = 0
While status = False
gratingName = "SIMPLIFIED_FLOOR_GRATING_" & Calculate_Fill_Grid.numOfHorizontal + counter * Calculate_Fill_Grid.numOfHorizontal
iDrawing.ClearSelection2(True)
plane1Name = "Point1@SL2@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane1Name, "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
counter += 1
End While
gratingName = "SUPPORT_BEAM_" & verticalBeams(verticalBeams.Length - 1)("INDEX")
plane2Name = "Point1@SM1@" & CompName & "@" & viewName & "/" & gratingName & "-1@" & CompName.Split("-")(0)
status = swExtensions.SelectByID2(plane2Name, "EXTSKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
measurement = iDrawing.AddHorizontalDimension2(0, OutLine(3) + 0.005, 0)
iDrawing.ClearSelection2(True)
Set_MeasurementProperties(measurement)
measurement.ShowParenthesis = True
End If
End If
Dim newName As String
newName = Settings.folderPaths("object_" & Data.objectNum & "_guide") & "\assembly_instructions.SLDDRW"
status = iDrawing.SaveAs3(newName, 0, 0)
status = iDrawing.SaveAs3(newName, 0, 2)
End Sub
Private Shared Sub Set_MeasurementProperties(measurement As IDisplayDimension)
measurement.SetUnits2(False, 0, 1, 0, True, 12)
measurement.CenterText = True
measurement.SetPrecision3(0, 0, 0, 0)
measurement.OffsetText = True
measurement.OffsetText = False ' Helps center the text
End Sub
End Class