.NET

Reply
Contributor
fantarama
Posts: 17
Registered: ‎04-16-2007
Message 1 of 5 (562 Views)

Create an extruded Solid3d from a polyline

562 Views, 4 Replies
02-11-2012 06:00 AM

I'm trying to create a Solid3d that is the extrusion solid af a closed polyline by a given height

 

I select the polyline that i do this

 

Solid3d s = new Solid3d();

s.CreateExtrudedSolid(selectedPolyline, new Vector3d(0, 0, 20), new SweepOptions());

 

but Autocad throw an eInvalidInput exception.

 

What is wrong in this code?

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 5 (560 Views)

Re: Create an extruded Solid3d from a polyline

02-11-2012 06:48 AM in reply to: fantarama

Give this a shot

{code}

       <CommandMethod("mysolid")> _
        Public Sub CreateExtruded()
            Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = acDoc.Editor
            Dim db As Database = acDoc.Database
            Try

                Using tr As Transaction = db.TransactionManager.StartTransaction

                    Dim peo As New PromptEntityOptions(vbLf & "Select closed curve >>")

                    peo.SetRejectMessage(vbLf & "Selected is not a curve>>")

                    peo.AddAllowedClass(GetType(Curve), False)

                    Dim res As PromptEntityResult

                    res = ed.GetEntity(peo)

                    If res.Status <> PromptStatus.OK Then

                        Return

                    End If

                    Dim ent As Entity = DirectCast(tr.GetObject(res.ObjectId, OpenMode.ForRead), Entity)

                    If ent Is Nothing Then

                        Return

                    End If

                    Dim curv As Curve = DirectCast(ent, Curve)

                    Dim coll As DBObjectCollection = New DBObjectCollection()

                    coll.Add(curv)

                    Dim dbcoll As DBObjectCollection = New DBObjectCollection()

                    dbcoll = Region.CreateFromCurves(coll)

                    Dim reg As Region = dbcoll(0)

                    Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) '<-- get current space

                    btr.AppendEntity(reg)

                    tr.AddNewlyCreatedDBObject(reg, True)

                    peo = New PromptEntityOptions(vbLf & "Select extruded path >>")

                    peo.SetRejectMessage(vbLf & "Selected is not a curve>>")

                    peo.AddAllowedClass(GetType(Polyline3d), False)

                    peo.AddAllowedClass(GetType(Line), False)

                   '' ----------------   add other types here    --------------- ''

                    res = ed.GetEntity(peo)

                    If res.Status <> PromptStatus.OK Then

                        Return

                    End If

                    ent = DirectCast(tr.GetObject(res.ObjectId, OpenMode.ForRead), Entity)

                    If ent Is Nothing Then

                        Return

                    End If

                    Dim expath As Curve = Nothing

                    Dim ln As Line = Nothing

                    Dim pline As Polyline3d = Nothing

                    If TypeOf ent Is Line Then

                        expath = DirectCast(ent, Curve)

                    ElseIf TypeOf ent Is Polyline3d Then

                        expath = DirectCast(ent, Curve)

                    End If


                    Dim sold As Solid3d = New Solid3d()

                    sold.RecordHistory = True

                    sold.ExtrudeAlongPath(reg, expath, 0.0)

                    btr.AppendEntity(sold)

                    tr.AddNewlyCreatedDBObject(sold, True)

                    tr.Commit()

                End Using
            Catch ex As System.Exception
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(String.Format( _
                                   "ERROR: " & Environment.NewLine & "{0}" & Environment.NewLine _
                                   & "TRACE: " + Environment.NewLine + "{1}", ex.Message, ex.StackTrace))
            Finally
                'do nothing
            End Try
        End Sub

{code}

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 5 (553 Views)

Re: Create an extruded Solid3d from a polyline

02-11-2012 07:25 AM in reply to: fantarama

In addition, by my limited test the following code is working too

{code}

-----------------------------------------

Dim sold AsSolid3d = NewSolid3d()

sold.RecordHistory = True

' sold.ExtrudeAlongPath(reg, expath, 0.0)'<-- works in 2009 / 2010

' sold.CreateExtrudedSolid(curv, New Vector3d(0, 0, 20), New SweepOptions()) ' <-- works in 2010

sold.CreateExtrudedSolid(curv,NewVector3d(1, 2, 20), NewSweepOptions()) ' <-- works in 2010

btr.AppendEntity(sold)

tr.AddNewlyCreatedDBObject(sold,

True)

tr.Commit()

-----------------------------------------

{code}

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
fantarama
Posts: 17
Registered: ‎04-16-2007
Message 4 of 5 (505 Views)

Re: Create an extruded Solid3d from a polyline

03-15-2012 04:09 AM in reply to: Hallex

Dim curv As Curve = DirectCast(ent, Curve)

Dim coll As DBObjectCollection = New DBObjectCollection()

coll.Add(curv)

Dim dbcoll As DBObjectCollection = New DBObjectCollection()

dbcoll = Region.CreateFromCurves(coll)

 

The above code don't work (throw eInvalidInput) if the curve (curv) is a Polyline3D!

 

Why?

 

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 5 (499 Views)

Re: Create an extruded Solid3d from a polyline

03-15-2012 07:32 AM in reply to: fantarama

As I remember from Help file the allowed types

for creating region does not contains 3Dpoly

See your self, mybe I'm wrong

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!