VB. net:What is the command to select SolidEdgeGeometry.Face item (1)

Valued Contributor
Valued Contributor

Got my program to switch to flatten and then use flatpattern. Having touble finding the commands to make him auto select a face.Any help?

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.
4 REPLIES

Re: VB. net:What is the command to select SolidEdgeGeometry.Face item (1)

Valued Contributor
Valued Contributor
        oApp.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalModelFlatPattern)
        oApp.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewFit)
        oApp.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView)
        oApp.StartCommand(SolidEdgeConstants.SheetMetalCommandConstants.SheetMetalSketchSketch)

Trying to Create a Sketch to eventually etch on the sheetmetal. I got so far ,selected the right command to make a sketch but now Ihave to select a face or plane. Is this were Mouse Events come in to play?I want the reference plane to be selected automatically. If I have to I'll make the user click it, but thats not exactly what i want. I was about to make a sub routine were the mouse automaticially positions itself in the middle of the screen and clicks but there must be an easier way.

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.

Re: VB. net:What is the command to select SolidEdgeGeometry.Face item (1)

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

You should try something like that :

 

    Public Sub Generate_FlattenModel()
        Dim ExistingFlat As Boolean = False

        Dim objModels As SolidEdgePart.Models
        Dim objModel As SolidEdgePart.Model

        Dim objBody As SolidEdgeGeometry.Body

        Dim objShells As SolidEdgeGeometry.Shells
        Dim objShell As SolidEdgeGeometry.Shell

        Dim objFaces As SolidEdgeGeometry.Faces
        Dim objFace As SolidEdgeGeometry.Face
        Dim objBiggestFace As SolidEdgeGeometry.Face = Nothing

        Dim objEdges As SolidEdgeGeometry.Edges
        Dim objEdge As SolidEdgeGeometry.Edge = Nothing

        Dim objVertex As SolidEdgeGeometry.Vertex = Nothing

        Dim ObjFlatPatternModel As SolidEdgePart.FlatPatternModel = Nothing
        Dim ObjFlatPattern As SolidEdgePart.FlatPattern = Nothing

        Dim objApp As SolidEdgeFramework.Application = Nothing
        Dim ObjDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
        Try
            objApp = CType(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)

        Catch ex As Exception
            If Not (objApp Is Nothing) Then
                Marshal.ReleaseComObject(objApp)
                objApp = Nothing
            End If
            Return
        End Try

        If Not (objApp Is Nothing) Then

            ObjDoc = objApp.ActiveDocument
        End If

        Try
            If Not (ObjDoc Is Nothing) Then

                Dim MaxSurf As Double

                objModels = ObjDoc.Models

                For Each objModel In objModels
                    If objModel.Name = "Design Model" Then
                        objBody = objModel.Body
                        objShells = objBody.Shells
                        objShell = objShells.Item(0)
                        objFaces = objShell.Faces
                        For Each objFace In objFaces
                            If objFace.Area > MaxSurf Then
                                MaxSurf = objFace.Area
                                objBiggestFace = objFace
                            End If
                        Next
                        objEdges = objBiggestFace.Edges
                        objEdge = objEdges.Item(0)

                        objVertex = Nothing
                        For Each objEdge In objEdges
                            objVertex = objEdge.StartVertex
                            If objVertex IsNot Nothing Then
                                Exit For
                            End If
                        Next

                        Exit For
                    End If
                Next

                ObjFlatPatternModel = ObjDoc.FlatPatternModels.Item(1)
                If Not ObjFlatPatternModel Is Nothing Then
                    If Not ObjFlatPatternModel.IsUpToDate Then ObjFlatPatternModel.Update()

                    ObjFlatPattern = ObjFlatPatternModel.FlatPatterns.Item(1)
                    If ObjFlatPattern.Status = SolidEdgePart.FeatureStatusConstants.igFeatureOK Then ExistingFlat = True
                    If Not ExistingFlat Then
                        ObjFlatPattern.Delete()
                    End If
                Else
                    ExistingFlat = False
                End If


                If Not ExistingFlat Then
                    If 0 = ObjDoc.FlatPatternModels.Count Then
                        ObjFlatPatternModel = ObjDoc.FlatPatternModels.Add(ObjDoc.Models.Item(1))
                    Else
                        ObjFlatPatternModel = ObjDoc.FlatPatternModels.Item(1)
                    End If

                    ObjFlatPatternModel.FlatPatterns.Add(objEdge, objBiggestFace, objVertex, SolidEdgeConstants.FlattenPatternModelTypeConstants.igFlattenPatternModelTypeFlattenAnything)
                End If

            End If

        Catch ex As Exception
            objModels = Nothing
            objModel = Nothing
            objBody = Nothing
            objShells = Nothing
            objShell = Nothing
            objFaces = Nothing
            objFace = Nothing
            objBiggestFace = Nothing
            objEdges = Nothing
            objEdge = Nothing
            objVertex = Nothing
            ObjFlatPatternModel = Nothing
            ObjFlatPattern = Nothing
        End Try

        objModels = Nothing
        objModel = Nothing
        objBody = Nothing
        objShells = Nothing
        objShell = Nothing
        objFaces = Nothing
        objFace = Nothing
        objBiggestFace = Nothing
        objEdges = Nothing
        objEdge = Nothing
        objVertex = Nothing
        ObjFlatPatternModel = Nothing
        ObjFlatPattern = Nothing
    End Sub

Romuald BERTIN

Re: VB. net:What is the command to select SolidEdgeGeometry.Face item (1)

Valued Contributor
Valued Contributor

Great!Works, I'll do my best to understand this correctly so I can add to it and complete my program.

Thanks!

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.

Re: VB. net:What is the command to select SolidEdgeGeometry.Face item (1)

Valued Contributor
Valued Contributor
 ObjFlatPatternModel.FlatPatterns.Add(objEdge, objBiggestFace, objVertex, SolidEdgeConstants.FlattenPatternModelTypeConstants.igFlattenPatternModelTypeFlattenAnything)

What I understand is that the important line that I would have to change in order to create a sketch using the same logic is this one?  Replacing FlatpatternModel.FlattPatterns.Add with functionalities to create a sketch and then getting objBiggest face again to select the biggest face for the sketch?

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.