224 lines
9.7 KiB
VB.net
224 lines
9.7 KiB
VB.net
Imports SldWorks
|
|
Public Class Multiple_Drawing
|
|
Public Shared Sub Generate_Drawing()
|
|
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("Assembly")
|
|
|
|
Dim layMgr As LayerMgr
|
|
layMgr = iDrawing.GetLayerManager()
|
|
status = layMgr.SetCurrentLayer("Svenska")
|
|
|
|
Dim myView As View
|
|
myView = iDrawing.CreateDrawViewFromModelView3(Settings.folderPaths("object_" & Data.objectNum & "_models3D_frames_sw_support") & "\gratings_assembly_simplified.SLDASM",
|
|
"*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 modelsDT As DataTable = Multiple_3D_Simplified.partDT
|
|
Dim gratingName, plane1Name, plane2Name As String
|
|
Dim counter As Integer
|
|
Dim measurement As IDisplayDimension
|
|
|
|
Dim mesOffsets(3) As Double
|
|
mesOffsets(0) = OutLine(3) + 0.005
|
|
mesOffsets(1) = OutLine(2) + 0.005
|
|
mesOffsets(2) = OutLine(1) - 0.005
|
|
mesOffsets(3) = OutLine(0) - 0.005
|
|
|
|
' -- Recess measurements --
|
|
Dim recessDT = modelsDT.Select("parentName = '" & modelsDT.Rows(Grating_Fill.numOfHorizontal * (Grating_Fill.numOfVertical - 1))("partName") & "'")
|
|
For i = 0 To Data.recessData.Rows.Count - 1
|
|
Dim DR As DataRow = Data.recessData.Rows(i)
|
|
Dim recessName As String = recessDT(i)("partName")
|
|
|
|
If DR("RECESS TYPE") = "ANGLE" Then
|
|
If DR("CORNER") = 1 Then
|
|
'A = horizontal uppåt, B = Veritcal vänster
|
|
iDrawing.ClearSelection2(True)
|
|
Create_Measurement("A", False, mesOffsets(0), CompName, myView, recessName, swExtensions, iDrawing)
|
|
mesOffsets(0) += 0.01
|
|
Create_Measurement("B", True, mesOffsets(3), CompName, myView, recessName, swExtensions, iDrawing)
|
|
mesOffsets(3) -= 0.01
|
|
|
|
'FORSÄTT HÄR!!!
|
|
|
|
ElseIf DR("CORNER") = 2 Then
|
|
'A = Veritcal höger, B = horizontal uppåt
|
|
ElseIf DR("CORNER") = 3 Then
|
|
'A = horizontal nedåt, B = Veritcal höger
|
|
Else
|
|
'A = Veritcal vänster, B = horizontal nedåt
|
|
End If
|
|
|
|
|
|
|
|
|
|
|
|
ElseIf DR("RECESS TYPE") = "SQUARE" Then
|
|
|
|
ElseIf DR("RECESS TYPE") = "SIDE SQUARE" Then
|
|
|
|
ElseIf DR("RECESS TYPE") = "MIDDLE SQUARE" Then
|
|
|
|
End If
|
|
Next
|
|
|
|
'recessData.Columns.Add("RECESS TYPE", GetType(String))
|
|
'recessData.Columns.Add("NAME", GetType(String))
|
|
'recessData.Columns.Add("CORNER", GetType(Integer))
|
|
'recessData.Columns.Add("SIDE", GetType(Integer))
|
|
'recessData.Columns.Add("WIDTH", GetType(Integer))
|
|
'recessData.Columns.Add("LENGTH", GetType(Integer))
|
|
'recessData.Columns.Add("OFFSET", GetType(Integer))
|
|
'recessData.Columns.Add("OFFSET X", GetType(Integer))
|
|
'recessData.Columns.Add("OFFSET Y", GetType(Integer))
|
|
'recessData.Columns.Add("GRATINGS", GetType(List(Of Integer)))
|
|
|
|
|
|
' -- Loop Horizontal --
|
|
For i = 0 To Grating_Fill.numOfHorizontal - 1
|
|
status = False
|
|
counter = 0
|
|
While status = False
|
|
gratingName = modelsDT.Rows(i + counter * Grating_Fill.numOfHorizontal)("partName")
|
|
iDrawing.ClearSelection2(True)
|
|
plane1Name = "L1@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane1Name, "PLANE", 0, 0, 0, False, 0, Nothing, 0)
|
|
plane2Name = "L2@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane2Name, "PLANE", 0, 0, 0, True, 0, Nothing, 0)
|
|
counter += 1
|
|
End While
|
|
|
|
measurement = iDrawing.AddHorizontalDimension2(0, mesOffsets(0), 0)
|
|
iDrawing.ClearSelection2(True)
|
|
|
|
Set_MeasurementProperties(measurement)
|
|
Next
|
|
mesOffsets(0) += 0.01
|
|
|
|
status = False
|
|
counter = 0
|
|
While status = False
|
|
gratingName = modelsDT.Rows(counter * Grating_Fill.numOfHorizontal)("partName")
|
|
iDrawing.ClearSelection2(True)
|
|
plane1Name = "L1@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane1Name, "PLANE", 0, 0, 0, False, 0, Nothing, 0)
|
|
counter += 1
|
|
End While
|
|
|
|
status = False
|
|
counter = 0
|
|
While status = False
|
|
gratingName = modelsDT.Rows(Grating_Fill.numOfHorizontal - 1 + counter * Grating_Fill.numOfHorizontal)("partName")
|
|
plane2Name = "L2@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane2Name, "PLANE", 0, 0, 0, True, 0, Nothing, 0)
|
|
counter += 1
|
|
End While
|
|
|
|
measurement = iDrawing.AddHorizontalDimension2(0, mesOffsets(0), 0)
|
|
iDrawing.ClearSelection2(True)
|
|
|
|
Set_MeasurementProperties(measurement)
|
|
|
|
' -- Loop Vertical --
|
|
For i = 0 To Grating_Fill.numOfVertical - 1
|
|
status = False
|
|
counter = 0
|
|
While status = False
|
|
gratingName = modelsDT.Rows(i * Grating_Fill.numOfHorizontal + counter)("partName")
|
|
iDrawing.ClearSelection2(True)
|
|
plane1Name = "W1@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane1Name, "PLANE", 0, 0, 0, False, 0, Nothing, 0)
|
|
plane2Name = "W2@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane2Name, "PLANE", 0, 0, 0, True, 0, Nothing, 0)
|
|
counter += 1
|
|
End While
|
|
|
|
measurement = iDrawing.AddVerticalDimension2(mesOffsets(3), 0, 0)
|
|
iDrawing.ClearSelection2(True)
|
|
|
|
Set_MeasurementProperties(measurement)
|
|
Next
|
|
mesOffsets(3) -= 0.01
|
|
|
|
status = False
|
|
counter = 0
|
|
While status = False
|
|
gratingName = modelsDT.Rows(counter)("partName")
|
|
iDrawing.ClearSelection2(True)
|
|
plane1Name = "W1@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane1Name, "PLANE", 0, 0, 0, False, 0, Nothing, 0)
|
|
counter += 1
|
|
End While
|
|
|
|
status = False
|
|
counter = 0
|
|
While status = False
|
|
gratingName = modelsDT.Rows(Grating_Fill.numOfHorizontal * (Grating_Fill.numOfVertical - 1) + counter)("partName")
|
|
plane2Name = "W2@" & CompName & "@" & myView.GetName2 & "/" & gratingName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane2Name, "PLANE", 0, 0, 0, True, 0, Nothing, 0)
|
|
counter += 1
|
|
End While
|
|
|
|
measurement = iDrawing.AddVerticalDimension2(mesOffsets(3), 0, 0)
|
|
iDrawing.ClearSelection2(True)
|
|
|
|
Set_MeasurementProperties(measurement)
|
|
|
|
|
|
Dim a = 1
|
|
|
|
|
|
End Sub
|
|
|
|
Private Shared Sub Create_Measurement(mesName As String, verticalDim As Boolean, mesOffset As Double, CompName As String, myView As View,
|
|
recessName As String, swExtensions As SldWorks.ModelDocExtension, iDrawing As DrawingDoc)
|
|
Dim status As Boolean
|
|
Dim plane1Name As String = mesName & "1@" & CompName & "@" & myView.GetName2 & "/" & recessName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane1Name, "PLANE", 0, 0, 0, False, 0, Nothing, 0)
|
|
Dim plane2Name As String = mesName & "2@" & CompName & "@" & myView.GetName2 & "/" & recessName & "-1@" & CompName.Split("-")(0)
|
|
status = swExtensions.SelectByID2(plane2Name, "PLANE", 0, 0, 0, True, 0, Nothing, 0)
|
|
|
|
Dim measurement As IDisplayDimension
|
|
If verticalDim = True Then
|
|
measurement = iDrawing.AddVerticalDimension2(0, mesOffset, 0)
|
|
Else
|
|
measurement = iDrawing.AddHorizontalDimension2(mesOffset, 0, 0)
|
|
End If
|
|
|
|
Set_MeasurementProperties(measurement)
|
|
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
|