.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Extruding Faces

0 REPLIES 0
Reply
Message 1 of 1
SOMAR_engineering
712 Views, 0 Replies

Extruding Faces

To all,

I am trying to write a .NET add-in to select a 3D solid and a line (where one endpoint of the line lies on a face of the solid).  The add-in will then extrude the face in which the endpoint lies, using the line as the path of extrusion.  See starting conditions in picture:

 

extrudefaceexample2.png

 

My code in its current form is below.  But it is not currently working.  I have been scratching my head over this one for awhile, any ideas?

Thanks in advance for any help,
Will

Acad 2009, VB Express 2008

 

 

Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.BoundaryRepresentation
Imports BrFace = Autodesk.AutoCAD.BoundaryRepresentation.Face

<Assembly: CommandClass(GetType(Autodesk.AutoCAD.ExtrudeFace.SOMRClass))> 

Namespace Autodesk.AutoCAD.ExtrudeFace

    Public Class SOMRClass

        <CommandMethod("exf")> _
       Public Sub ExtrudeFace()

            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database
            Dim acDocEd As Editor = acDoc.Editor

            'set up prompt selection options
            Dim acPromptEntOpt1 As PromptEntityOptions = New PromptEntityOptions("")

            acPromptEntOpt1.Message = vbLf & "Select a 3D Solid: "
            acPromptEntOpt1.SetRejectMessage(vbLf & "Select a 3D Solid only!")
            acPromptEntOpt1.AddAllowedClass(GetType(Solid3d), True)

            'ask the user to select the 3d solid
            Dim acPromptEntRes1 As PromptEntityResult = acDocEd.GetEntity(acPromptEntOpt1)

            If acPromptEntRes1.Status = PromptStatus.OK Then

                'set up prompt selection options
                Dim acPromptEntOpt2 As PromptEntityOptions = New PromptEntityOptions("")

                acPromptEntOpt2.Message = vbLf & "Select the path of extrusion: "
                acPromptEntOpt2.SetRejectMessage(vbLf & "Select a line only!")
                acPromptEntOpt2.AddAllowedClass(GetType(Line), True)

                'ask the user to select the path of extrusion
                Dim acPromptEntRes2 As PromptEntityResult = acDocEd.GetEntity(acPromptEntOpt2)

                If acPromptEntRes2.Status = PromptStatus.OK Then

                    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                        Try

                            'get the solid
                            Dim acSolid As Solid3d = acTrans.GetObject(acPromptEntRes1.ObjectId, OpenMode.ForRead)
                            'get the line
                            Dim acLine As Line = acTrans.GetObject(acPromptEntRes2.ObjectId, OpenMode.ForRead)
                            'get the startpoint of the line
                            Dim acStartPt As Point3d = acLine.StartPoint
                            'get the end point of the line
                            Dim acEndPt As Point3d = acLine.EndPoint


                            'convert the line to a curve
                            Dim acCurve As Curve = TryCast(acLine, Curve)

                            If acCurve <> Nothing Then

                                'Build the BRep topology object to traverse
                                Using acBrep As Brep = New Brep(acSolid)

                                    Dim acFaceColl As BrepFaceCollection = acBrep.Faces

                                    For Each acFace As BrFace In acFaceColl

                                        'test to see if either point lies on the face
                                        Dim ContainmentVal1 As PointContainment = New PointContainment()
                                        acFace.GetPointContainment(acStartPt, ContainmentVal1)
                                        Dim ContainmentVal2 As PointContainment = New PointContainment()
                                        acFace.GetPointContainment(acEndPt, ContainmentVal2)

                                        'if the point lies on the face, then extrude the face
                                        If ContainmentVal1 = PointContainment.Inside Or ContainmentVal2 = PointContainment.Inside Then

                                            'extrude the face, this line throws an exception
                                            Dim FaceSubEntIds() As SubentityId = New SubentityId() {acFace.SubentityPath.SubentId}
                                            acSolid.ExtrudeFacesAlongPath(FaceSubEntIds, acCurve)

                                        End If

                                    Next

                                End Using

                            End If

                        Catch ex As System.Exception

                            acDocEd.WriteMessage(vbLf & "Exception: " & ex.Message)

                        End Try

                        'commit the transaction
                        acTrans.Commit()

                    End Using

                End If

            End If

        End Sub

    End Class

End Namespace

 

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report