Showing results for 
Search instead for 
Did you mean: 

Chamfers in .net 2005

Valued Contributor
Valued Contributor



Hello, somebody can help me with an example to do chamfers and/or roundings using visual basic .net




Posted by: Alfonso Tafur
Post date: 10/16/2008 2:47:41 PM


RE: Chamfers in .net 2005

Valued Contributor
Valued Contributor


Hello, I have been making a small program VB6, I was update to .net 2005 and with some corrections I have been able to conduct two operations, but the program fails when doing roundnesses and chamfers. Somebody can indicate to me where is the error? Thanks!

Public Class Form1

    Dim D As Double

    Dim S As Double = 15 / 1000

    Dim a As Double

    Dim l As Double = 60 / 1000

    Dim K As Double = 5 / 1000

    Dim C As Double = 1 / 1000

    Dim Dn As Double = 10 / 1000

    Dim r As Double = 1 / 1000

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Variables para abrir

        Dim objApp As SolidEdgeFramework.Application

        Dim objDoc As SolidEdgePart.PartDocument

        Dim objDocs As Object

        Dim lngCount As Integer

        Dim lngStatus As Integer


        'Variables para la protrusion

        Dim objRPProfile(2) As SolidEdgePart.Profile

        Dim objLines As SolidEdgeFrameworkSupport.Lines2d

        Dim objRPCSection(6) As SolidEdgeFrameworkSupport.Line2d

        Dim objRelns As SolidEdgeFrameworkSupport.Relations2d

        Dim objModel As SolidEdgePart.Model

        Dim objRefPln As SolidEdgePart.RefPlane

        Dim objProf As SolidEdgePart.Profile

        Dim objExtProt As SolidEdgePart.ExtrudedProtrusion

        Dim aprofiles As Array

        Dim objProfile As SolidEdgePart.Profile

        Dim objModels As SolidEdgePart.Models


        'Variables para el chaflán

        Dim objChmfrs As SolidEdgePart.Chamfers

        Dim objEdgs As Object

        Dim objEdgArr(1) As Object

        Dim objChmfr As SolidEdgePart.Chamfer

        Dim objFacs As Object

        'Variables para el redondez

        Dim objRounds As SolidEdgePart.Rounds

        Dim objRPProfArray(3) As SolidEdgePart.Profile

        Dim objEdges As Object

        Dim objEdgeArray(2) As SolidEdgeGeometry.Edge

        Dim dblRadiusArray(1) As Double

        Dim objRound As SolidEdgePart.Round

        D = S * 2 / System.Math.Sqrt(3)

        a = D / 2


        'Crear/Capturar Solid Edge con propiedades específicas

        On Error Resume Next

        objApp = GetObject(, "SolidEdge.Application")

        If Err.Number Then


            objApp = CreateObject("SolidEdge.Application")

            objDoc = objApp.Documents.Add("SolidEdge.PartDocument")

            objApp.Visible = True


            'Accede a la colección de documentos.

            objDocs = objApp.Documents

            'Examina si existen documentos abiertos.

            If objDocs.Count = 0 Then

                'Si no existen documentos abiertos agrega un documento de Pieza.

                objDoc = objDocs.Add("SolidEdge.PartDocument")


                'accede al docuemnto abierto.

                objDoc = objApp.ActiveDocument

            End If

            objDoc = objApp.ActiveDocument

            'Revisa si el documento abierto es de pieza, si no es así agrega un documento de pieza.

            If objApp.ActiveEnvironment "Part" Then

                objDoc = objDocs.Add("SolidEdge.PartDocument")

                objDoc = objApp.ActiveDocument


                'Si el documento abierto es de pieza examina si tiene un modelo, si tiene alguno, agrega un documento de pieza

                lngCount = objDoc.Models.Count

                If lngCount 0 Then

                    objDoc = objDocs.Add("SolidEdge.PartDocument")

                    objDoc = objApp.ActiveDocument

                End If

            End If

        End If


        '***Cabeza del perno

        'Dibuja el perfil de la cabeza (Hexagono)

        objRPProfile(1) = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objDoc.RefPlanes.Item(1))

        objLines = objRPProfile(1).Lines2d

        objRPCSection(1) = objRPProfile(1).Lines2d.AddBy2Points(x1:=a / 2, y1:=-S / 2, x2:=-a / 2, y2:=-S / 2)

        objRPCSection(2) = objRPProfile(1).Lines2d.AddBy2Points(x1:=-a / 2, y1:=-S / 2, x2:=-D / 2, y2:=0)

        objRPCSection(3) = objRPProfile(1).Lines2d.AddBy2Points(x1:=-D / 2, y1:=0, x2:=-a / 2, y2:=S / 2)

        objRPCSection(4) = objRPProfile(1).Lines2d.AddBy2Points(x1:=-a / 2, y1:=S / 2, x2:=a / 2, y2:=S / 2)

        objRPCSection(5) = objRPProfile(1).Lines2d.AddBy2Points(x1:=a / 2, y1:=S / 2, x2:=D / 2, y2:=0)

        objRPCSection(6) = objRPProfile(1).Lines2d.AddBy2Points(x1:=D / 2, y1:=0, x2:=a / 2, y2:=-S / 2)

        ' Define las relaciones para cerrar el perfil

        objRelns = objRPProfile(1).Relations2d

        Call objRelns.AddKeypoint(Object1:=objRPCSection(1), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objRPCSection(2), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)

        Call objRelns.AddKeypoint(Object1:=objRPCSection(2), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objRPCSection(3), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)

        Call objRelns.AddKeypoint(Object1:=objRPCSection(3), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objRPCSection(4), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)

        Call objRelns.AddKeypoint(Object1:=objRPCSection(4), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objRPCSection(5), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)

        Call objRelns.AddKeypoint(Object1:=objRPCSection(5), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objRPCSection(6), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)

        Call objRelns.AddKeypoint(Object1:=objRPCSection(6), Index1:=SolidEdgeConstants.KeypointIndexConstants.igLineEnd, Object2:=objRPCSection(1), Index2:=SolidEdgeConstants.KeypointIndexConstants.igLineStart)

        ' Verifica que el perfil sea cerrado


        If lngStatus 0 Then

            MsgBox("El perfil no está cerrado")

        End If

        ' Crea un array del objeto perfil

        aprofiles = Array.CreateInstance(GetType(SolidEdgePart.Profile), 1)

        aprofiles.SetValue(objRPProfile(1), 0)

        ' Obtiene una referencia para la colleccion Modelos

        objModels = objDoc.Models

        ' Crea una protrusion

        objModel = objModels.AddFiniteExtrudedProtrusion(aprofiles.Length, aprofiles, _

        SolidEdgePart.FeaturePropertyConstants.igRight, K)

        objRPProfile(1).Visible = False

        ' Verifica la operación protrusión

        If objModel.ExtrudedProtrusions.Item(1).Status SolidEdgeConstants.FeatureStatusConstants.igFeatureOK Then

            MsgBox("Error en la operación Protrusión")

        End If


        ' Dibuja un círculo

        objRefPln = objDoc.RefPlanes.AddParallelByDistance(ParentPlane:=objDoc.RefPlanes.Item(1), Distance:=0, NormalSide:=SolidEdgeConstants.FeaturePropertyConstants.igLeft)

        objProf = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRefPln)

        Call objProf.Circles2d.AddByCenterRadius(x:=0, y:=0, Radius:=Dn / 2)

        ' Verifica que el perfil sea cerrado

        lngStatus = objProf.End(ValidationCriteria:=SolidEdgeConstants.ProfileValidationType.igProfileClosed)

        If lngStatus 0 Then

            MsgBox("El perfil no está cerrado")

        End If

        'Crea la operación Protrusión

        objExtProt = objModel.ExtrudedProtrusions.AddFinite(Profile:=objProf, ProfileSide:=SolidEdgeConstants.FeaturePropertyConstants.igRight, ProfilePlaneSide:=SolidEdgeConstants.FeaturePropertyConstants.igLeft, Depth:=l)

        objProf.Visible = False

        If objExtProt.Status SolidEdgeConstants.FeatureStatusConstants.igFeatureOK Then

            MsgBox("Error en la creación de la operación Protrusión")

        End If



        objChmfrs = objModel.Chamfers

        ' Obtiene la colección de bordes

        objEdgs = objModel.ExtrudedProtrusions.Item(2).Edges(EdgeType:=SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)

        ' Obtiene los bordes y los almacena en un array

        objEdgArr(1) = objEdgs(1)


        ' Obtiene las caras

        objFacs = objExtProt.Faces(FaceType:=SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll)

        ' Crea un objeto Achaflanar

        objChmfr = objModel.Chamfers.AddEqualSetback(NumberOfEdgeSets:=1, EdgeSetArray:=objEdgArr(1), SetbackDistance:=C)

        If objChmfr.Status SolidEdgeConstants.FeatureStatusConstants.igFeatureOK Then

            MsgBox("Error en la creación de la operación Achaflanar")

        End If


        objRounds = objModel.Rounds

        ' define el radio de una cara

        objEdges = objModel.ExtrudedProtrusions.Item(2).Edges(EdgeType:=SolidEdgeConstants.FeatureTopologyQueryTypeConstants.igQueryAll)

        objEdgeArray(1) = objEdges(2)

        dblRadiusArray(1) = r

        ' Crea la operación redondear

        objRound = objRounds.Add(NumberOfEdgeSets:=1, EdgeSetArray:=objEdgeArray, RadiusArray:=dblRadiusArray)

        If objRound.Status SolidEdgeConstants.FeatureStatusConstants.igFeatureOK Then

            MsgBox("Error en la creación de la operación Redondear")

        End If

    End Sub

End Class


Posted by: Alfonso Tafur
Post date: 10/20/2008 9:31:52 AM