Export to CNC/ISO

From little time I am trying to learn VB(A) and SoliWorks, my experience it is based particularly on AutoLisp/AutoCAD.
I should create a program to export information in CNC/ISO language, the parts to be examined are enough simple: - Panel (of wood) rectangular [Extrusion] - Hole [LibraryFeature] [Cut] [swEndCondBlind] [LPattern] - Hole [LibraryFeature] [Cut] [swEndCondThroughAll] [LPattern] - Hole [LibraryFeature] [Cut] [swEndCondBlind] [LPattern] +[Chamfer] - Hole [LibraryFeature] [Cut] [swEndCondThroughAll] [LPattern] +[Chamfer] All the holes are perpendicular to the surfaces of the panel. The informations I need are: - measures of the panel - holes: face, center, diameter, depth, chamfer, (lPattern?) I have taken I sprout from: "Select Edges of All Holes on Face Example (VB)" in SW API Help and I have written the program (see below). For the holes: it is possible to get the center of the hole and the face, getting the rest of information from the [LibraryFeature]? Am I on the correct road? Links? Suggestions?
My apoligies for my english.
[code] Option Explicit
Function GetFaceNormalAtMidCoEdge(swCoEdge As SldWorks.CoEdge) As Variant Dim swFace As SldWorks.Face2 Dim swSurface As SldWorks.Surface Dim swLoop As SldWorks.Loop2 Dim varParams As Variant Dim varPoint As Variant Dim dblMidParam As Double Dim dblNormal(2) As Double Dim bFaceSenseReversed As Boolean varParams = swCoEdge.GetCurveParams If varParams(6) > varParams(7) Then dblMidParam = (varParams(6) - varParams(7)) / 2 + varParams(7) Else dblMidParam = (varParams(7) - varParams(6)) / 2 + varParams(6) End If varPoint = swCoEdge.Evaluate(dblMidParam) ' Get the face of the given coedge ' Check for the sense of the face Set swLoop = swCoEdge.GetLoop Set swFace = swLoop.GetFace Set swSurface = swFace.GetSurface bFaceSenseReversed = swFace.FaceInSurfaceSense varParams = swSurface.EvaluateAtPoint(varPoint(0), varPoint(1), varPoint(2)) If bFaceSenseReversed Then ' Negate the surface normal as it is opposite from the face normal dblNormal(0) = -varParams(0) dblNormal(1) = -varParams(1) dblNormal(2) = -varParams(2) Else dblNormal(0) = varParams(0) dblNormal(1) = varParams(1) dblNormal(2) = varParams(2) End If GetFaceNormalAtMidCoEdge = dblNormal End Function
Function GetTangentAtMidCoEdge(swCoEdge As SldWorks.CoEdge) As Variant Dim varParams As Variant Dim dblMidParam As Double Dim dblTangent(2) As Double varParams = swCoEdge.GetCurveParams If varParams(6) > varParams(7) Then dblMidParam = (varParams(6) - varParams(7)) / 2# + varParams(7) Else dblMidParam = (varParams(7) - varParams(6)) / 2# + varParams(6) End If varParams = swCoEdge.Evaluate(dblMidParam) dblTangent(0) = varParams(3) dblTangent(1) = varParams(4) dblTangent(2) = varParams(5) GetTangentAtMidCoEdge = dblTangent End Function
Function GetCrossProduct(varVec1 As Variant, varVec2 As Variant) As Variant Dim dblCross(2) As Double dblCross(0) = varVec1(1) * varVec2(2) - varVec1(2) * varVec2(1) dblCross(1) = varVec1(2) * varVec2(0) - varVec1(0) * varVec2(2) dblCross(2) = varVec1(0) * varVec2(1) - varVec1(1) * varVec2(0) GetCrossProduct = dblCross End Function
Function VectorsAreEqual(varVec1 As Variant, varVec2 As Variant) As Boolean Dim dblMag As Double Dim dblDot As Double Dim dblUnit1(2) As Double Dim dblUnit2(2) As Double dblMag = (varVec1(0) * varVec1(0) + varVec1(1) * varVec1(1) + varVec1(2) * varVec1(2)) ^ 0.5 dblUnit1(0) = varVec1(0) / dblMag: dblUnit1(1) = varVec1(1) / dblMag: dblUnit1(2) = varVec1(2) / dblMag dblMag = (varVec2(0) * varVec2(0) + varVec2(1) * varVec2(1) + varVec2(2) * varVec2(2)) ^ 0.5 dblUnit2(0) = varVec2(0) / dblMag: dblUnit2(1) = varVec2(1) / dblMag: dblUnit2(2) = varVec2(2) / dblMag dblDot = dblUnit1(0) * dblUnit2(0) + dblUnit1(1) * dblUnit2(1) + dblUnit1(2) * dblUnit2(2) dblDot = Abs(dblDot - 1#) ' Compare within a tolerance If dblDot < 0.0000000001 Then '1.0e-10 VectorsAreEqual = True Else VectorsAreEqual = False End If End Function
Sub SelectHoleEdges(swFace As SldWorks.Face2) Dim swThisLoop As SldWorks.Loop2 Dim swThisCoEdge As SldWorks.CoEdge Dim swPartnerFace As SldWorks.Face2 Dim swPartnerLoop As SldWorks.Loop2 Dim swPartnerCoEdge As SldWorks.CoEdge Dim swEntity As SldWorks.Entity Dim varThisNormal As Variant Dim varPartnerNormal As Variant Dim varCrossProduct As Variant Dim varTangent As Variant Dim vEdgeArr As Variant Dim swEdge As SldWorks.Edge Dim swCurve As SldWorks.Curve Dim bRet As Boolean Dim edgeParams As Variant Dim edgeRadius As Variant Set swThisLoop = swFace.GetFirstLoop Do While Not swThisLoop Is Nothing ' Hole is inner loop ' Circular or elliptical hole has only one edge If swThisLoop.IsOuter = False And 1 = swThisLoop.GetEdgeCount Then Set swThisCoEdge = swThisLoop.GetFirstCoEdge Set swPartnerCoEdge = swThisCoEdge.GetPartner varThisNormal = GetFaceNormalAtMidCoEdge(swThisCoEdge) varPartnerNormal = GetFaceNormalAtMidCoEdge(swPartnerCoEdge) If Not VectorsAreEqual(varThisNormal, varPartnerNormal) Then ' There is a sufficient change between the two faces to determine ' what kind of transition is being made varCrossProduct = GetCrossProduct(varThisNormal, varPartnerNormal) varTangent = GetTangentAtMidCoEdge(swThisCoEdge) If VectorsAreEqual(varCrossProduct, varTangent) Then ' hole vEdgeArr = swThisLoop.GetEdges Debug.Assert 0 = UBound(vEdgeArr) Set swEdge = vEdgeArr(0) Set swCurve = swEdge.GetCurve ' Ignore elliptical holes If swCurve.IsCircle Then Set swEntity = swEdge 'bRet = swEntity.Select4(True, swSelData) edgeParams = swCurve.CircleParams ' The return value is the following array of 7 double values: ' [ center.x, center.y, center.z, axis.x, axis.y, axis.z, radius ] ' Center and radius values are in meters. Debug.Print "Center X,Y,Z = " + Str(edgeParams(0)); "," _ ; Str(edgeParams(1)); ","; Str(edgeParams(2)) Debug.Print "Axis X,Y,Z = " + Str(edgeParams(3)); "," _ ; Str(edgeParams(4)); ","; Str(edgeParams(5)) edgeRadius = edgeParams(6) Debug.Print "Radius = " + Str(edgeRadius) 'Stop 'Debug.Assert bRet End If End If End If End If ' Move on to the next Set swThisLoop = swThisLoop.GetNext Loop End Sub
Sub ALE_GetPanelInfo() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swPart As SldWorks.PartDoc Dim swBody As SldWorks.Body2 Dim swFace As SldWorks.Face2 Dim edgeList As Variant Dim edgeCount As Long Dim i As Long Dim edgeObj As Object ' Edge object Dim startVertexObj As Object ' Vertex objects Dim endVertexObj As Object Dim startPt As Variant ' Edge startpoint and endpoint arrays Dim endPt As Variant Set swApp = CreateObject("SldWorks.Application") Set swModel = swApp.ActiveDoc Set swPart = swModel Set swBody = swPart.Body Set swFace = swBody.GetFirstFace Do While Not swFace Is Nothing edgeCount = swFace.GetEdgeCount Debug.Print "Number of edges on this face: " & edgeCount edgeList = swFace.GetEdges ' Get the edges on the selected face For i = 0 To (edgeCount - 1) Set edgeObj = edgeList(i) Set startVertexObj = edgeObj.GetStartVertex ' Get the "Start" vertex Set endVertexObj = edgeObj.GetEndVertex ' Get the "End" vertex If (Not startVertexObj Is Nothing) Then startPt = startVertexObj.GetPoint ' Get the xyz vertex location Debug.Print "Edge: " + Str$(i) + " StartP " + Str$(startPt(0)) + _ "," + Str$(startPt(1)) + "," + Str$(startPt(2)) End If If (Not endVertexObj Is Nothing) Then endPt = endVertexObj.GetPoint ' Get the xyz vertex location Debug.Print "Edge: " + Str$(i) + " EndP " + Str$(endPt(0)) + _ "," + Str$(endPt(1)) + "," + Str$(endPt(2)) End If Next i SelectHoleEdges swFace Set swFace = swFace.GetNextFace Loop End Sub
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
Add image file

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.