159 lines
6.8 KiB
VB.net
159 lines
6.8 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
|
|
' -- 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, OutLine(3) + 0.005, 0)
|
|
|
|
iDrawing.ClearSelection2(True)
|
|
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
|
|
Next
|
|
|
|
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, OutLine(3) + 0.005 + 0.01, 0)
|
|
|
|
measurement.SetUnits2(False, 0, 1, 0, True, 12)
|
|
measurement.CenterText = True
|
|
measurement.SetPrecision3(0, 0, 0, 0)
|
|
measurement.ShowParenthesis = True
|
|
measurement.OffsetText = True
|
|
measurement.OffsetText = False
|
|
|
|
' -- 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(OutLine(0) - 0.005, 0, 0)
|
|
|
|
iDrawing.ClearSelection2(True)
|
|
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
|
|
Next
|
|
|
|
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(OutLine(0) - 0.005 - 0.01, 0, 0)
|
|
|
|
measurement.SetUnits2(False, 0, 1, 0, True, 12)
|
|
measurement.CenterText = True
|
|
measurement.SetPrecision3(0, 0, 0, 0)
|
|
measurement.ShowParenthesis = True
|
|
measurement.OffsetText = True
|
|
measurement.OffsetText = False
|
|
|
|
|
|
Dim a = 1
|
|
|
|
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
End Class
|