.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Although I have found code that should allow me to convert 2dpolylines to regular polylines, I am having troubles implementing it. At first I got the eInvalid Input but have since fixed that. However, the error now is that there is no error. Autocad just seems to lock up but I can still switch to visual studio and look at my code. It as though Autocad thinks it is doing something but my code is not doing anything. I can scroll around.
My code is this:
Try
Dim acDrawing As Document = Application.DocumentManager.MdiActiveDocument
Using acDrawingLock As DocumentLock = acDrawing.LockDocument
Using acTransaction As Transaction = acDrawing.Database.TransactionManager.StartTransac tion
Dim acBlockTable As BlockTable = acTransaction.GetObject(acDrawing.Database.BlockTa bleId, OpenMode.ForWrite)
Dim acBlockTableRecord As BlockTableRecord = acTransaction.GetObject(acBlockTable("*MODEL_SPACE "), OpenMode.ForWrite)
For Each Id As ObjectId In acBlockTableRecord
If Id.ObjectClass.Name = "AcDb2dPolyline" Then
Dim acPolyline2d As Polyline2d = Id.GetObject(OpenMode.ForWrite, True)
Dim acPolyLine As New Polyline()
acPolyLine.ConvertFrom(acPolyline2d, True)
End If
Next
acTransaction.Commit()
End Using
End Using
Catch ex As System.Exception
MsgBox(ex.ToString)
End TryAnyone have any ideas? It appears to hang on the acpolyline.convertofrm(acpolyline2d, true) line.
Thanks a bunch,
Solved! Go to Solution.
Re: converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
As I know one of the problems - using transactions.
Try samples and explanation:
Converting a Polyline2d to Polyline
Converting a Polyline to Polyline2d
Also Polyline2d have to be simple (SimplePoly) or fit (FitCurvePoly) and has not any Xdata attached to vertexes.
Re : converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
You have to add the newly created polyline to the Database (and erase the polyline 2d).
Here's a quick and dirty C# snippet:
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (doc.LockDocument())
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord mSpace =
(BlockTableRecord)SymbolUtilityServices
.GetBlockModelSpaceId(db)
.GetObject(OpenMode.ForWrite);
RXClass rxc = RXClass.GetClass(typeof(Polyline2d));
foreach (ObjectId id in mSpace)
{
if (id.ObjectClass == rxc)
{
Polyline2d pl2d = (Polyline2d)tr.GetObject(id, OpenMode.ForWrite);
if (pl2d.PolyType != Poly2dType.CubicSplinePoly &&
pl2d.PolyType != Poly2dType.QuadSplinePoly)
using (Polyline pline = new Polyline())
{
pline.ConvertFrom(pl2d, false);
mSpace.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
pl2d.Erase();
}
}
}
tr.Commit();
}
Re : converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I tried the code from that link, but I was having troubles getting it to work. It could have something to do with me translating to VB.net. Perhaps my translation was messed up. Do you have a quick translation?
Re : converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks Gile,
I had come across that code at one point in my travels, but didnt think it did what I wanted it to do. I will try that next.
Thanks,
Re : converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
' Translated C#->VB.NET code: ' http://adndevblog.typepad.com/autocad/2012/05/converting-a-polyline2d-to-polyline.html <CommandMethod("TestConvertPoly")> _ Public Sub testConvertPoly() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor ' select the entity Dim res As PromptEntityResult = ed.GetEntity("Select PolyLine: ") ' if ok If res.Status = PromptStatus.OK Then ' use the using keyword so that the objects auto-dispose '(close) at the end of the brace ' open for write otherwise ConvertFrom will fail Using ent As Entity = DirectCast(res.ObjectId.Open(OpenMode.ForRead), Entity) ' if it's a polyline2d If TypeOf ent Is Polyline2d Then Dim poly2d As Polyline2d = DirectCast(ent, Polyline2d) poly2d.UpgradeOpen() ' again use the using keyword to ensure auto-closing Using poly As New Autodesk.AutoCAD.DatabaseServices.Polyline() poly.ConvertFrom(poly2d, True) End Using End If End Using End If End Sub
Re : converting 2dpolyline to regular polyline
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks Alexander and everyone who has help so far.
The vb.net code actually worked. I think what happened to me preivously when attempting to use that code is that I saw a message about the Open function being obsolete to use GetObject instead. So I did, but that didnt work. When I actually used the Open the way you have it in your example code and ignored that little message, everything worked beautifully.
Thanks for your help. I greatly appreciate it!



