.NET

Reply
Valued Contributor
hericson
Posts: 69
Registered: ‎12-03-2006
Message 1 of 4 (145 Views)

GetObject from cloned object not yet in database

145 Views, 3 Replies
07-18-2013 10:10 PM

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

 

Valued Contributor
amanero
Posts: 73
Registered: ‎12-03-2003
Message 2 of 4 (126 Views)

Re: GetObject from cloned object not yet in database

07-18-2013 11:56 PM in reply to: hericson

Hello,

 

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)

Luis Alberto Manero, Geograma.com
Valued Contributor
hericson
Posts: 69
Registered: ‎12-03-2006
Message 3 of 4 (108 Views)

Re: GetObject from cloned object not yet in database

07-19-2013 03:19 AM in reply to: amanero

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.

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 4 of 4 (102 Views)

Re: GetObject from cloned object not yet in database

07-19-2013 05:01 AM in reply to: hericson

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.

 

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.