AutoCAD Civil 3D Customization

Reply
Distinguished Contributor
jmaeding
Posts: 927
Registered: ‎12-27-2006
Message 1 of 3 (287 Views)
Accepted Solution

how to delete alignment using .net api?

287 Views, 2 Replies
04-16-2012 02:39 PM

I thought that finding the alignmentId, and using the code:

doc.GetAlignmentIds().Remove(delId);

would do it.

 

I know i have the right alignmentId, it all cheaks out, there must be something I have to do after removing from the ID collection.

I am doing a Tr.Commit(); but that does not seem to be good enough.

 

full code is: (_returnMsg is a local var for the class containing this method)

 

public void DelC3DHAlign(string name) {
      _returnMsg = "Error, No alignments available";
      //access Civil 3D
      CivilDocument doc = CivilApplication.ActiveDocument;
      try {
        using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) {
          ObjectId delId = ObjectId.Null;
          foreach (ObjectId alignId in doc.GetAlignmentIds()) {
            C3LD.Alignment alg = alignId.GetObject(OpenMode.ForRead) as C3LD.Alignment;
            if (name.ToUpper() == alg.Name.ToUpper())
              delId = alignId;
          }
          if (delId != ObjectId.Null)
            doc.GetAlignmentIds().Remove(delId);
          tr.Commit();
          _returnMsg = "Alignment deleted";
        }
      }
      catch {
        _returnMsg = "Error, Alignment not deleted";
      }
    }

 

 

thx

*Expert Elite*
Jeff_M
Posts: 4,175
Registered: ‎07-22-2003
Message 2 of 3 (283 Views)

Re: how to delete alignment using .net api?

04-16-2012 03:11 PM in reply to: jmaeding

Did you try this?

 C3LD.Alignment alg = alignId.GetObject(OpenMode.ForRead) as C3LD.Alignment;
            if (name.ToUpper() == alg.Name.ToUpper())
            {
              alg.UpgradeOpen();
              alg.Erase();
             }

 

Jeff_M, also a frequent Swamper
Distinguished Contributor
jmaeding
Posts: 927
Registered: ‎12-27-2006
Message 3 of 3 (280 Views)

Re: how to delete alignment using .net api?

04-16-2012 04:52 PM in reply to: Jeff_M

workie, good call!

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