AutoCAD Civil 3D Customization

Reply
Active Contributor
RasmusB
Posts: 35
Registered: ‎04-12-2012
Message 1 of 5 (187 Views)

Updating a Feature Line's geometry

187 Views, 4 Replies
11-03-2012 08:26 AM

Does anyone know  of a way to update a Feature Line's geometry? Say, you have a db-resident Feature Line you want to keep (i.e. its ObjectId etc), but update, and a non-db resident Feature Line which has the new/updated geometry. I have tried opening the db-resident Feature Line as an Entity and calling Entity::handOverTo with the non-db resident Feature Line as input, but the resultng Feature Line behaves very strange (e.g. it disappears and reappears at different places during REGEN)...just removing and adding PIs is not so easy either, as there can be no less than two PIs on a Feature Line, and they have to be inserted close to a segment.

---
2B or not 2B? That is the question! The answer is FF.
ADN Support Specialist
Partha.Sarkar
Posts: 543
Registered: ‎06-09-2009
Message 2 of 5 (158 Views)

Re: Updating a Feature Line's geometry

11-17-2012 02:56 AM in reply to: RasmusB

Hi Rasmus,

 

I don't have any ready answer for this; I need to investigate this.

 

Thanks,

Partha



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

*Expert Elite*
Jeff_M
Posts: 4,192
Registered: ‎07-22-2003
Message 3 of 5 (149 Views)

Re: Updating a Feature Line's geometry

11-17-2012 09:10 AM in reply to: RasmusB

Just trying to do this inside one drawing, using the COM interops (since there is essentially no .NET functionality for Featurelines). This seems like it should work, and it all does, except for the part to InsertFeaturePoint(s) where it errors with E_FAIL.

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.Land.DatabaseServices;
using Autodesk.AECC.Interop.Land;

namespace FeaturelineTools
{
    public class EditFeatureLine
    {
        [CommandMethod("CopyFLData")]
        public void CopyFLDatacommand()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect Source Featureline line: ");
            entOpts.SetRejectMessage("\n...not an allowed object type, try again.");
            entOpts.AddAllowedClass(typeof(FeatureLine), true);
            entOpts.AddAllowedClass(typeof(Polyline3d), true);
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                PromptEntityResult res = ed.GetEntity(entOpts);
                if (res.Status != PromptStatus.OK)
                    return;
                FeatureLine sourceFL = (FeatureLine)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                entOpts.Message = "\nSelect Target Featureline: ";
                res = ed.GetEntity(entOpts);
                if (res.Status != PromptStatus.OK)
                    return;
                FeatureLine targetFL = (FeatureLine)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                AeccLandFeatureLine src=(AeccLandFeatureLine)sourceFL.AcadObject;
                AeccLandFeatureLine trgt = (AeccLandFeatureLine)targetFL.AcadObject;
                double[] trgtelevpts = (double[])trgt.GetPoints(AeccLandFeatureLinePointType.aeccLandFeatureLinePointElevation);
                double[] trgtpipts = (double[])trgt.GetPoints(AeccLandFeatureLinePointType.aeccLandFeatureLinePointPI);
                double[] srcelevpts = (double[])src.GetPoints(AeccLandFeatureLinePointType.aeccLandFeatureLinePointElevation);
                double[] srcpipts = (double[])src.GetPoints(AeccLandFeatureLinePointType.aeccLandFeatureLinePointPI);
                double[] trgtstart = new double[3];
                trgtstart[0] = trgtpipts[0];
                trgtstart[1] = trgtpipts[1];
                trgtstart[2] = trgtpipts[2];
                int len = trgtpipts.GetLength(0);
                double[] trgtend = new double[3];
                trgtend[0] = trgtpipts[len - 3];
                trgtend[1] = trgtpipts[len - 2];
                trgtend[2] = trgtpipts[len - 1];

                for (int i = 3; i < (trgtelevpts.GetLength(0) - 3); i = i + 3)
                {
                    double[] pt = new double[3];
                    pt[0] = trgtelevpts[i];
                    pt[1] = trgtelevpts[i + 1];
                    pt[2] = trgtelevpts[i + 2];
                    trgt.DeleteFeaturePoint((object)pt);
                }
                for (int i = 3; i < (trgtpipts.GetLength(0) - 3); i = i + 3)
                {
                    double[] pt = new double[3];
                    pt[0] = trgtpipts[i];
                    pt[1] = trgtpipts[i + 1];
                    pt[2] = trgtpipts[i + 2];
                    trgt.DeleteFeaturePoint((object)pt);
                }
                trgt.Update();
                //the 2 following lines fail, so tried to set each point individually...which also fails with the same error E_FAIL
                //trgt.InsertFeaturePoints((object)srcpipts, AeccLandFeatureLinePointType.aeccLandFeatureLinePointPI);
                //trgt.InsertFeaturePoints((object)srcelevpts, AeccLandFeatureLinePointType.aeccLandFeatureLinePointElevation);
                for (int i = 0; i < srcpipts.GetLength(0); i++)
                {
                    double[] pt = new double[3];
                    pt[0] = srcpipts[i];
                    pt[1] = srcpipts[i + 1];
                    pt[2] = srcpipts[i + 2];
                    trgt.InsertFeaturePoint((object)pt, AeccLandFeatureLinePointType.aeccLandFeatureLinePointPI);
                }
                for (int i = 0; i < srcelevpts.GetLength(0); i++)
                {
                    double[] pt = new double[3];
                    pt[0] = srcelevpts[i];
                    pt[1] = srcelevpts[i + 1];
                    pt[2] = srcelevpts[i + 2];
                    trgt.InsertFeaturePoint((object)pt, AeccLandFeatureLinePointType.aeccLandFeatureLinePointElevation);
                }
                trgt.DeleteFeaturePoint((object)trgtstart);
                trgt.DeleteFeaturePoint((object)trgtend);
                tr.Commit();
            }
        }
    }
}

 

Jeff_M, also a frequent Swamper
Contributor
rafrbu
Posts: 16
Registered: ‎04-01-2008
Message 4 of 5 (144 Views)

Re: Updating a Feature Line's geometry

11-17-2012 10:49 AM in reply to: Jeff_M

My point exactly. I have tried this and similar strategies, but they all fail as long as the points you try to insert are not sufficiently close to the (single) segment on the Feature Line of interest (and in general, the points are not close). This is expected as it is the same behaviour one get when trying to insert PIs on a Feature Line within Civil 3D.

ADN Support Specialist
Partha.Sarkar
Posts: 543
Registered: ‎06-09-2009
Message 5 of 5 (124 Views)

Re: Updating a Feature Line's geometry

11-20-2012 02:18 AM in reply to: rafrbu

This functionality needs to be exposed in .NET API for FeatureLine class.

 

I would suggest to submit a wish list for the same.

 

Thanks,



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community


Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Civil 3D

Twitter

Facebook

Blogs