Author Topic: Sweep solid across polyline  (Read 290 times)

0 Members and 1 Guest are viewing this topic.

ROYNIJKAMP

  • Mosquito
  • Posts: 9
Sweep solid across polyline
« on: May 14, 2018, 10:06:25 AM »
I am trying to sweep a profile across a polyline.

I have found several methods on the internet, but none of these methods seem to work.
Below is my code, mostly found while using Google.
Code - vb.net: [Select]
  1. Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  2.        Dim acCurDb As Database = acDoc.Database
  3.        Dim acEd As Editor = acDoc.Editor
  4.  
  5.        Using acLockDoc As DocumentLock = acDoc.LockDocument()
  6.            Dim per As PromptEntityResult
  7.            Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Select path: ")
  8.            peo.SetRejectMessage(vbLf & "Wrong Entity.")
  9.            peo.AddAllowedClass(GetType(Curve), False)
  10.            per = acEd.GetEntity(peo)
  11.            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
  12.                Try
  13.                    Dim pathEnt As Curve = TryCast(acTrans.GetObject(per.ObjectId, OpenMode.ForRead), Curve)
  14.                    Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite)
  15.                    Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
  16.  
  17.                    Dim sweepEnt As Polyline = New Polyline()
  18.                    sweepEnt.AddVertexAt(0, New Point2d(0, 0), 0, 0, 0)
  19.                    sweepEnt.AddVertexAt(1, New Point2d(0, 0.1), 0, 0, 0)
  20.                    sweepEnt.AddVertexAt(2, New Point2d(0.1, 0.1), 0, 0, 0)
  21.                    sweepEnt.AddVertexAt(3, New Point2d(0.1, 0), 0, 0, 0)
  22.                    sweepEnt.AddVertexAt(4, New Point2d(0, 0), 0, 0, 0)
  23.  
  24.  
  25.                    Dim ent3D As New Solid3d()
  26.                    Dim sob As SweepOptionsBuilder = New SweepOptionsBuilder()
  27.                    sob.Align = SweepOptionsAlignOption.AlignSweepEntityToPath
  28.                    sob.BasePoint = pathEnt.StartPoint
  29.                    sob.Bank = True
  30.  
  31.                    ent3D.CreateSweptSolid(sweepEnt, pathEnt, sob.ToSweepOptions())
  32.                    acBlkTblRec.AppendEntity(ent3D)
  33.                    acTrans.AddNewlyCreatedDBObject(ent3D, True)
  34.                    acTrans.Commit()
  35.                Catch ex As Autodesk.AutoCAD.Runtime.Exception
  36.                    MsgBox("Error: " & ex.Message & vbCrLf & "Source: " & ex.Source & vbCrLf & "Status: " & ex.ErrorStatus)
  37.                End Try
  38.            End Using
  39.        End Using
  40.  
When i run my code i get the following error:
Error: eGeneralModelingFailure
Source: Acdbmgd
Status: 150

The Exception is Thrown by the following line of code:
Code - vb.net: [Select]
  1. ent3D.CreateSweptSolid(sweepEnt, pathEnt, sob.ToSweepOptions())

what am I missing or what am I doing wrong?

Thanks in advance for any help!

Roy

WILL HATCH

  • Bull Frog
  • Posts: 448
Re: Sweep solid across polyline
« Reply #1 on: May 15, 2018, 12:06:20 AM »
Likely requires adding sweepEnt to the database

ROYNIJKAMP

  • Mosquito
  • Posts: 9
Re: Sweep solid across polyline
« Reply #2 on: May 15, 2018, 03:18:40 AM »
Likely requires adding sweepEnt to the database
adding sweepEnt to the database does not solve the problem.

Some one else??

SEANT

  • Bull Frog
  • Posts: 316
Re: Sweep solid across polyline
« Reply #3 on: May 16, 2018, 02:23:21 AM »
Try this substitution:

sob.BasePoint = sweepEnt.StartPoint

Also check that the selected path is appropriate for the size of the sweeping profile.
Sean Tessier
AutoCAD 2016 Mechanical

ROYNIJKAMP

  • Mosquito
  • Posts: 9
Re: Sweep solid across polyline
« Reply #4 on: May 16, 2018, 04:16:32 AM »
Try this substitution:

sob.BasePoint = sweepEnt.StartPoint

Also check that the selected path is appropriate for the size of the sweeping profile.
To bad, this was not the sollution.
Changing the BasePoint returns the exact same error.

The path and profile are Ok, a manual sweep functions without problems.

SEANT

  • Bull Frog
  • Posts: 316
Re: Sweep solid across polyline
« Reply #5 on: May 16, 2018, 04:37:37 AM »
I was able to get you code to run.  Post your setup drawing.
Sean Tessier
AutoCAD 2016 Mechanical

SEANT

  • Bull Frog
  • Posts: 316
Re: Sweep solid across polyline
« Reply #6 on: May 16, 2018, 04:50:02 AM »
I used a filleted poly.  If the polyline has sharp corners, you may need to set this:

sob.Bank = False


Similar to the AutoCAD drawing editor, it will fail depending on the Bank option
Sean Tessier
AutoCAD 2016 Mechanical

ROYNIJKAMP

  • Mosquito
  • Posts: 9
Re: Sweep solid across polyline
« Reply #7 on: May 17, 2018, 07:16:23 AM »
I was able to get you code to run.  Post your setup drawing.
I tested my code on another computer with the same AutoCAD version and the code runs without problems on the same drawing.
After a repair of my AutoCAD installation my code also runs fine on my own machine.

I do not know what caused the problem but is is resolved.