diff --git a/Wardrobe/GUI/Individual.vb b/Wardrobe/GUI/Individual.vb index 285d227..21920aa 100644 --- a/Wardrobe/GUI/Individual.vb +++ b/Wardrobe/GUI/Individual.vb @@ -250,8 +250,8 @@ Public Class Individual Model_3D_Fill.BuildGrid() Else - Model_3D.BuildGrating() - Drawing.CreateDrawing() + 'Model_3D.BuildGrating() + Drawing.Create_Model_For_Drawing() End If End Sub diff --git a/Wardrobe/Recess Functions/Middle_Rectangle.vb b/Wardrobe/Recess Functions/Middle_Rectangle.vb index f2d0196..518072b 100644 --- a/Wardrobe/Recess Functions/Middle_Rectangle.vb +++ b/Wardrobe/Recess Functions/Middle_Rectangle.vb @@ -129,11 +129,55 @@ pointRow4("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") + middleSquareValues(2) / Data.scaleDiff pointRow4("GUI Y") = Data.grossAreaPoints.Rows(3)("GUI Y") - middleSquareValues(3) / Data.scaleDiff + numOfMiddleRectangles += 1 + + + + If sidePressed = 3 Then + For j = 2 To Data.gratingPoints.Rows.Count - 1 + If Data.gratingPoints.Rows(j)("GUI Y") = Data.grossAreaPoints.Rows(2)("GUI Y") Then + sidePoints.Add(j) + End If + Next + Index = sidePoints(0) + If sidePoints.Count > 2 Then + For i = sidePoints.Count / 2 To 2 Step -1 + If Data.gratingPoints.Rows(sidePoints(i * 2 - 2))("GUI X") > + Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff Then + Index = sidePoints(i * 2 - 2) + Exit For + End If + Next + End If + + Else + For j = 3 To Data.gratingPoints.Rows.Count - 1 + If Data.gratingPoints.Rows(j)("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") Then + sidePoints.Add(j) + End If + Next + sidePoints.Add(0) + Index = sidePoints(0) + If sidePoints.Count > 2 Then + For i = sidePoints.Count / 2 To 2 Step -1 + If Data.gratingPoints.Rows(sidePoints(i * 2 - 2))("GUI Y") > + Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff Then + Index = sidePoints(i * 2 - 2) + Exit For + End If + Next + End If + End If + + + + ' Add recess measuements (SW) + Data.pointsMeasurements.Add("MS1_" & mesNum, {Data.grossAreaPoints.Rows(3), numOfMiddleRectangles * 4 - 1, 3}) + Data.pointsMeasurements.Add("MS1_" & mesNum + 1, {sidePoints(0) + 1, numOfMiddleRectangles * 4 - 1, 4}) + Data.pointsMeasurements.Add("MS_" & mesNum + 2, {numOfMiddleRectangles * 4 - 1, numOfMiddleRectangles * 4 - 2, 3}) + Data.pointsMeasurements.Add("MS_" & mesNum + 3, {numOfMiddleRectangles * 4 - 4, numOfMiddleRectangles * 4 - 1, 4}) + - '' Add recess measuements (SW) - 'Data.pointsMeasurements.Add("SS1_" & mesNum, {sidePoints(0) + 1, index + 2, 1}) - 'Data.pointsMeasurements.Add("SS_" & mesNum + 1, {Index + 2, Index + 5, 1}) - 'Data.pointsMeasurements.Add("SS_" & mesNum + 2, {index + 2, index + 3, 4}) '' Add support line data for sidesquare measurement 'Draw_Grating.sideSquareMesLine.Add("SS1_" & mesNum, {Data.gratingPoints.Rows(Index)("GUI X"), @@ -162,7 +206,7 @@ Data.recessData.Rows(Data.recessData.Rows.Count - 1)("OFFSET X") = CInt(Individual.Panel_Recesses.Controls("OffX_TextBox").Text) Data.recessData.Rows(Data.recessData.Rows.Count - 1)("OFFSET Y") = CInt(Individual.Panel_Recesses.Controls("OffY_TextBox").Text) - numOfMiddleRectangles += 1 + Data.gratingMiddlePoints.Rows.InsertAt(pointRow1, numOfMiddleRectangles * 4 - 4) Data.gratingMiddlePoints.Rows.InsertAt(pointRow2, numOfMiddleRectangles * 4 - 3) diff --git a/Wardrobe/SolidWorks/Drawing.vb b/Wardrobe/SolidWorks/Drawing.vb index 37c816e..a966d5e 100644 --- a/Wardrobe/SolidWorks/Drawing.vb +++ b/Wardrobe/SolidWorks/Drawing.vb @@ -2,11 +2,12 @@ Public Class Drawing Private Shared sideCounter As Integer() - Public Shared Sub CreateDrawing() + Public Shared Sub Create_Model_For_Drawing() Dim pointTable As DataTable pointTable = Data.gratingPoints - Dim gratingHeight As Decimal = 0.025 ' Behövs variabel + Dim gratingHeight As Decimal = User_Input.gratingHeight / 1000 + Dim swApp As SldWorks.SldWorks swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) Dim Model As ModelDoc2 @@ -51,12 +52,6 @@ Public Class Drawing skLine = swSkMgr.CreateLine(pX1, pY1, 0, pX2, pY2, 0) Next - boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) - Model.FeatureManager.InsertRefPlane(8, gratingHeight, 0, 0, 0, 0) - - - 'Rename sketch? - swSkMgr.InsertSketch(True) Dim swModelDocExtension As ModelDocExtension @@ -72,9 +67,52 @@ Public Class Drawing swFeature = swFeatureMgr.FeatureExtrusion3(True, False, False, 0, 0, gratingHeight, 0, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False) - 'swSkMgr.InsertSketch(True) - boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) + For i = 0 To Data.gratingMiddlePoints.Rows.Count / 4 - 1 + Model.ClearSelection2(True) + boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) + swSkMgr.InsertSketch(True) + Model.ClearSelection2(True) + + 'For Each DR As DataRow In Data.gratingMiddlePoints.Rows + For j = 0 To 3 + Dim skPoint As SketchPoint + Dim pX = Data.gratingMiddlePoints.Rows(i * 4 + j)("X") + Dim pY = Data.gratingMiddlePoints.Rows(i * 4 + j)("Y") + skPoint = swSkMgr.CreatePoint(pX, pY, 0) + Next + + 'For Each DR1 As DataRow In Data.gratingMiddlePoints.Rows + For j = 0 To 3 + Dim skLine As SketchLine + Dim pX1 = Data.gratingMiddlePoints.Rows(i * 4 + j)("X") + Dim pY1 = Data.gratingMiddlePoints.Rows(i * 4 + j)("Y") + Dim pX2, pY2 As Double + If j = 3 Then + pX2 = Data.gratingMiddlePoints.Rows(i * 4)("X") + pY2 = Data.gratingMiddlePoints.Rows(i * 4)("Y") + Else + pX2 = Data.gratingMiddlePoints.Rows(i * 4 + j + 1)("X") + pY2 = Data.gratingMiddlePoints.Rows(i * 4 + j + 1)("Y") + + End If + skLine = swSkMgr.CreateLine(pX1, pY1, 0, pX2, pY2, 0) + + Next + + swSkMgr.InsertSketch(True) + + status = swModelDocExtension.SelectByID2("Sketch" & i + 2, "SKETCH", 0, 0, 0, False, 0, Nothing, 0) + + swFeature = swFeatureMgr.FeatureCut4(True, False, False, 6, 0, gratingHeight * 4, 0.01, False, False, False, False, 0.01, 0.01, False, False, False, False, False, True, True, True, True, False, 0, 0, False, False) + + Next + Model.ClearSelection2(True) + boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) + Model.FeatureManager.InsertRefPlane(8, gratingHeight, 0, 0, 0, 0) + + 'boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) + 'Model.ClearSelection2(True) Dim iPart As PartDoc iPart = swApp.ActiveDoc @@ -191,16 +229,38 @@ Public Class Drawing For j = 0 To Data.pointsMeasurements.Count - 1 Dim measureName As String = Data.pointsMeasurements.Keys(j) Dim measureDist As Double - If Data.pointsMeasurements(measureName)(2) = 1 OrElse Data.pointsMeasurements(measureName)(2) = 3 Then - Dim x1 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("X") - Dim x2 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("X") - measureDist = Math.Abs(x1 - x2) - Else - Dim y1 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("Y") - Dim y2 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("Y") - measureDist = Math.Abs(y1 - y2) - End If + If mesName.Split("_")(0) = "MS" Then + If Data.pointsMeasurements(measureName)(2) = 1 OrElse Data.pointsMeasurements(measureName)(2) = 3 Then + Dim x1 As Double = Data.gratingMiddlePoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("X") + Dim x2 As Double = Data.gratingMiddlePoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("X") + measureDist = Math.Abs(x1 - x2) + Else + Dim y1 As Double = Data.gratingMiddlePoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("Y") + Dim y2 As Double = Data.gratingMiddlePoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("Y") + measureDist = Math.Abs(y1 - y2) + End If + ElseIf mesName.Split("_")(0) = "MS1" Then + If Data.pointsMeasurements(measureName)(2) = 1 OrElse Data.pointsMeasurements(measureName)(2) = 3 Then + Dim x1 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("X") + Dim x2 As Double = Data.gratingMiddlePoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("X") + measureDist = Math.Abs(x1 - x2) + Else + Dim y1 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("Y") + Dim y2 As Double = Data.gratingMiddlePoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("Y") + measureDist = Math.Abs(y1 - y2) + End If + Else + If Data.pointsMeasurements(measureName)(2) = 1 OrElse Data.pointsMeasurements(measureName)(2) = 3 Then + Dim x1 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("X") + Dim x2 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("X") + measureDist = Math.Abs(x1 - x2) + Else + Dim y1 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(0) - 1)("Y") + Dim y2 As Double = Data.gratingPoints.Rows(Data.pointsMeasurements(measureName)(1) - 1)("Y") + measureDist = Math.Abs(y1 - y2) + End If + End If If measureDist < lowestValue Then lowestValue = measureDist mesName = measureName @@ -219,11 +279,11 @@ Public Class Drawing For i = 2 To sortedMeasurments.Count - 1 Dim mesName As String = sortedMeasurments.Keys(i) - Add_Dimensions(sortedMeasurments(mesName), CompName, myView, iDrawing, swExtensions, OutLine, scaleDecimal, X_Mid, Y_Mid) + Add_Dimensions(sortedMeasurments(mesName), CompName, myView, iDrawing, swExtensions, OutLine, scaleDecimal, X_Mid, Y_Mid, mesName) Next - Add_Dimensions(sortedMeasurments("Lmes"), CompName, myView, iDrawing, swExtensions, OutLine, scaleDecimal, X_Mid, Y_Mid) - Add_Dimensions(sortedMeasurments("Wmes"), CompName, myView, iDrawing, swExtensions, OutLine, scaleDecimal, X_Mid, Y_Mid) + Add_Dimensions(sortedMeasurments("Lmes"), CompName, myView, iDrawing, swExtensions, OutLine, scaleDecimal, X_Mid, Y_Mid, "Lmes") + Add_Dimensions(sortedMeasurments("Wmes"), CompName, myView, iDrawing, swExtensions, OutLine, scaleDecimal, X_Mid, Y_Mid, "Wmes") Dim myView2 As View myView2 = iDrawing.CreateDrawViewFromModelView3(Individual.filepath & "\Temp\TESTPART1.SLDPRT", "*Bottom", swSheetWidth / 2, OutLine(3) + sideCounter(0) * 0.01 + 0.03, 0) myView2.UseSheetScale() = True @@ -273,7 +333,7 @@ Public Class Drawing End Sub Private Shared Sub Add_Dimensions(points() As Integer, CompName As String, myView As View, iDrawing As DrawingDoc, swExtensions As SldWorks.ModelDocExtension _ - , OutLine() As Double, scaleDecimal As Double, X_Mid As Double, Y_Mid As Double) + , OutLine() As Double, scaleDecimal As Double, X_Mid As Double, Y_Mid As Double, mesName As String) Dim measurement As IDisplayDimension Dim point1NameSW As String = "Point" & points(0) & "@Sketch1@" & CompName & "@" & myView.GetName2 @@ -286,9 +346,18 @@ Public Class Drawing Dim mesOffset = 0.01 If points(2) = 1 OrElse points(2) = 3 Then - Dim point1 As Double = Data.gratingPoints.Rows(points(0) - 1)("X") - Dim point2 As Double = Data.gratingPoints.Rows(points(1) - 1)("X") + Dim point1, point2 As Double + If mesName.Split("_")(0) = "MS" Then + point1 = Data.gratingMiddlePoints.Rows(points(0) - 1)("X") + point2 = Data.gratingMiddlePoints.Rows(points(1) - 1)("X") + ElseIf mesName.Split("_")(0) = "MS1" Then + point1 = Data.gratingPoints.Rows(points(0) - 1)("X") + point2 = Data.gratingMiddlePoints.Rows(points(1) - 1)("X") + Else + point1 = Data.gratingPoints.Rows(points(0) - 1)("X") + point2 = Data.gratingPoints.Rows(points(1) - 1)("X") + End If Dim xPos As Double If Math.Abs(point1) > Math.Abs(point2) Then xPos = point2 + (point1 - point2) / 2 @@ -302,8 +371,18 @@ Public Class Drawing measurement = iDrawing.AddHorizontalDimension2(X_Mid + xPos * scaleDecimal, OutLine(1) - 0.005 - mesOffset * sideCounter(2), 0) End If Else - Dim point1 As Double = Data.gratingPoints.Rows(points(0) - 1)("Y") - Dim point2 As Double = Data.gratingPoints.Rows(points(1) - 1)("Y") + Dim point1, point2 As Double + If mesName.Split("_")(0) = "MS" Then + point1 = Data.gratingMiddlePoints.Rows(points(0) - 1)("Y") + point2 = Data.gratingMiddlePoints.Rows(points(1) - 1)("Y") + ElseIf mesName.Split("_")(0) = "MS1" Then + point1 = Data.gratingPoints.Rows(points(0) - 1)("Y") + point2 = Data.gratingMiddlePoints.Rows(points(1) - 1)("Y") + Else + point1 = Data.gratingPoints.Rows(points(0) - 1)("Y") + point2 = Data.gratingPoints.Rows(points(1) - 1)("Y") + + End If Dim yPos As Double If Math.Abs(point1) > Math.Abs(point2) Then