I want to clone a polyline3d and set all vertices Z to 0.0 and use that one in my program. I don't want to add it to the database, just use it in memory and then dispose it. I know how to access all vertices in a polyline3d that exists in the database using a transaction, but this will not work with my cloned polyline3d in memory. What's the solution?
Here's part of my code:
Dim acDoc As Document = DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim idArray As ObjectId() = sSet.GetObjectIds() For Each id In idArray Dim entity As Entity = acTrans.GetObject(id, OpenMode.ForWrite, True) Select Case entity.GetType().FullName Case "Autodesk.AutoCAD.DatabaseServices.Polyline3d" Dim pl3d As Polyline3d = CType(entity, Polyline3d) dim clonedPl3d as Polyline3d = pl3d.Clone() ' accessing the vertices from the original polyline For Each vId As ObjectId In pl3d Dim vObj As Object = acTrans.GetObject(vId, OpenMode.ForWrite) Dim v3d As PolylineVertex3d = CType(vObj, PolylineVertex3d) v3d.Position = New Point3d(v3d.Position.X, v3d.Position.Y, 0.0) Next ' accessing the vertices from the cloned polyline For Each vId As ObjectId In clonedPl3d Dim vObj As Object = acTrans.GetObject(vId, OpenMode.ForWrite) ' how should this line look like? Dim v3d As PolylineVertex3d = CType(vObj, PolylineVertex3d) v3d.Position = New Point3d(v3d.Position.X, v3d.Position.Y, 0.0) Next clonedPl3d.Dispose() End Select Next End Using
Only a sugestion: Why do not create a new polyline from scratch?
You could create an Point3dCollection with the vertices and then create a new polyline with it like this (NOT TESTED):
Dim clonedPl3d As Polyline3d = New Polyline3d(Poly3dType.SimplePoly, myPoint3dCollection, isClosed)
Good point! The reason i used .Clone() is because I used that on other object and I want to have similar code for every object.
I also tried to first add the cloned 3dPolyline to the database and afterwards deleting it.
You will have to implement your own object using your own Clone() method via .NET reflection and copy/access all the properties with your own mutators and accessors. That way you can even serialize/desirialize and send them across the wire, do whatever you like. Currently Clone() will just create acad objects that are not serializable because of the COM objects they contain. Additionally many fields are marked read only and you cannot change them. That's just a guess. I think the solution is something along these lines plus you will also have to write custom methods for ACAD properties where simply invoking accessors or mutators doesn't suffice ie. you will have to catch eNotImplemented exceptions. I am not promising anything but if there is no one else with better ideas in the next couple hours/days I'll try to get some code example in during the weekend time permitting.