Author Topic: civil 3d alignment by pick points  (Read 2185 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
civil 3d alignment by pick points
« on: January 29, 2012, 11:52:42 AM »
using c3d 2012 and vs2008

I almost have my first net sub working. This insert a civil alignment from 2 screen points. It places the alignment object in the drawing however if I hit
return to repeat the command autodesk editor crashes. am I not closing the transaction coorectly.

Thank you
john

<CommandMethod("AlignpickNET")> _
   Public Sub MyAddALignpickNET()
        Dim civdoc As CivilDocument = CivilApplication.ActiveDocument
        Dim alignstyle As ObjectId = civdoc.Styles.AlignmentStyles(0)
        Dim alignlblstyle As ObjectId = civdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles(0)
        Dim layer As ObjectId = civdoc.Settings.DrawingSettings.ObjectLayerSettings.GetObjectLayerSetting(Autodesk.Civil.Settings.SettingsObjectLayerType.Alignment).LayerId
        Dim alignid As ObjectId = Alignment.Create(civdoc, "MyFirstNETAlign", ObjectId.Null, layer, alignstyle, alignlblstyle)

        Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

        Dim promptPtOp1 As PromptPointOptions = New PromptPointOptions(vbCrLf + "Select start runway : ")
        promptPtOp1.LimitsChecked = True
        promptPtOp1.AllowNone = False
        Dim promptPtRes1 As PromptPointResult = ed.GetPoint(promptPtOp1)

        Dim promptPtOp2 As PromptPointOptions = New PromptPointOptions(vbCrLf + "Select end runway : ")
        promptPtOp2.UseBasePoint = True
        promptPtOp2.BasePoint = promptPtRes1.Value
        promptPtOp2.LimitsChecked = True
        promptPtOp2.AllowNone = False

        Dim promptPtRes2 As PromptPointResult = ed.GetPoint(promptPtOp2)
        Dim pt1 As Point3d = Nothing
        Dim pt2 As Point3d = Nothing
        pt1 = promptPtRes1.Value
        pt2 = promptPtRes2.Value

        Using tr As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()

            Dim align As Alignment = tr.GetObject(alignid, OpenMode.ForWrite)
            align.Entities.AddFixedLine(pt1, pt2)
            tr.Commit()
            tr.Dispose()
        End Using

    End Sub

LE3

  • Guest
Re: civil 3d alignment by pick points
« Reply #1 on: January 29, 2012, 12:07:11 PM »
A quick fix is to remove this line:
tr.Dispose()

jcoon

  • Newt
  • Posts: 157
Re: civil 3d alignment by pick points
« Reply #2 on: January 29, 2012, 12:24:07 PM »
Le,

I removed the tr.dispose and it reacts the same. It adds the alignment correctly but if I hit return crashes.

minutes later, Ok.......I finally read the error message, it complaining about duplicate alignment name. I guess I need a test for that. under vba it would just add (1) to the duplicate name.

I'm off to find out how to add an alignment name test.

Thank you
john 

LE3

  • Guest
Re: civil 3d alignment by pick points
« Reply #3 on: January 29, 2012, 12:40:09 PM »
That line of tr.Dispose() is not needed there inside of the Using.

About the duplicate issue, try by changing the name manually in other words, make two or three test commands with names like "MyFirstNETAlign1", "MyFirstNETAlign2", "MyFirstNETAlign3"...

That way you can debug it.

Test that and see if works.

(and btw, i am not familiar with c3d)

jcoon

  • Newt
  • Posts: 157
Re: civil 3d alignment by pick points
« Reply #4 on: January 29, 2012, 12:46:53 PM »
Le,

hard coding the named worked so I need to get the alignment names in the drawing and check new alignment name being inserted.

Thank you
John

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: civil 3d alignment by pick points
« Reply #5 on: January 29, 2012, 01:55:14 PM »
Creating Alignments indeed crash on duplicate names. While other APIs put a number in the end, like Surfaces, with Alignments or Profile Views you need to be very sure. Even a Try..Catch won't work.

You can write a function which check for existing name.

The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

jcoon

  • Newt
  • Posts: 157
Re: civil 3d alignment by pick points
« Reply #6 on: January 30, 2012, 10:08:10 AM »
Huiz,

That's is what I hope to work on tonight.

Thanks
john