Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Examples for StationOffset in C#

4 REPLIES 4
Reply
Message 1 of 5
brianchapmandesign
1361 Views, 4 Replies

Examples for StationOffset in C#

Need an example of how to use StationOffset() in civil3d.  I used point3d to get a var x and var y.... need to know how to select my alignment and report the station/offset for that coordinate. Any help / examples would be most appreciated.


Thanks!


"Very funny, Scotty. Now beam down my clothes.
4 REPLIES 4
Message 2 of 5

Diggin through Sinpac Free Source...maybe I'll figure out


"Very funny, Scotty. Now beam down my clothes.
Message 3 of 5
Jeff_M
in reply to: brianchapmandesign

A word of caution. While the SincpacC3D source code may be of some benefit, it was originally written based on the C3D2007 API's. A lot has changed since then, specifically the .NET API's were born, so those examples do not have anything that deals with these newer API's.

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 5
Jeff_M
in reply to: brianchapmandesign

And some sample code using the .NET API:

        [CommandMethod("AlignmentTest")]
        public void alignmenttest()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            ObjectId alignId = SelectAlignment(doc.Editor);
            if (alignId == ObjectId.Null)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Alignment align = (Alignment)alignId.GetObject(OpenMode.ForRead);
                double station = Double.NaN;
                double offset = Double.NaN;
                PromptPointOptions ptOpts = new PromptPointOptions("\nPick point for Station/Offset:");
                ptOpts.AllowNone = true;
                ptOpts.AllowArbitraryInput = false;                
                PromptPointResult ptRes =  doc.Editor.GetPoint(ptOpts);
                while (ptRes.Status == PromptStatus.OK)
                {
                    try
                    {
                        align.StationOffset(ptRes.Value.X, ptRes.Value.Y, ref station, ref offset);
                        doc.Editor.WriteMessage("\nThe station and offset at the picked point is: {0}, {1}", align.GetStationStringWithEquations(station), offset.ToString("F2"));
                    }
                    catch (Autodesk.Civil.CivilException ex)
                    {
                        string msg = ex.Message;
                    }
                    ptRes = doc.Editor.GetPoint(ptOpts);
                }
            }
        }

        private ObjectId SelectAlignment(Editor ed)
        {
            ObjectId result = ObjectId.Null;
            PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect alignment: ");
            entOpts.SetRejectMessage("...not an Alignment, try again!:");
            entOpts.AddAllowedClass(typeof(Alignment), true);
            PromptEntityResult entRes = ed.GetEntity(entOpts);
            if (entRes.Status == PromptStatus.OK)
                result = entRes.ObjectId;
            return result;
        }

 

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 5

Thanks Jeff!  I was able to finally put something together real late last night... but your code shows me where I worked way too hard lol.... much appreciated!


"Very funny, Scotty. Now beam down my clothes.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report