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: 

how to delete alignment using .net api?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
JamesMaeding
720 Views, 2 Replies

how to delete alignment using .net api?

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


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

2 REPLIES 2
Message 2 of 3
Jeff_M
in reply to: JamesMaeding

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
EESignature
Message 3 of 3
JamesMaeding
in reply to: Jeff_M

workie, good call!


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

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

Post to forums  

Rail Community


Autodesk Design & Make Report