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?
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}
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}
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?
As I remember from Help file the allowed types
for creating region does not contains 3Dpoly
See your self, mybe I'm wrong
~'J'~
Can't find what you're looking for? Ask the community or share your knowledge.