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.StartTransaction Dim acBlockTable As BlockTable = acTransaction.GetObject(acDrawing.Database.BlockTableId, 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 Try
Anyone have any ideas? It appears to hang on the acpolyline.convertofrm(acpolyline2d, true) line.
Thanks a bunch,
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
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.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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(); }
Hi, Gilles!
Are you sure that Transaction can be using in that context?
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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?
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,
' 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
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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!
Can't find what you're looking for? Ask the community or share your knowledge.