or to simplify, this does not work:
Call objProfile.PVIs.Add(1000, 360, aeccProfileTangent)
Call objProfile.PVIs.Add(1200, 380, aeccProfileTangent)
objProfile.Entities.RemoveAll
Call objProfile.PVIs.Add(1000, 360, aeccProfileTangent)
Call objProfile.PVIs.Add(1200, 380, aeccProfileTangent)
something about RemoveAll messes up the PVI's collection.
James Maeding
|>I know this is a dupe post, the one in Civil 3d group was an accident, wrong place.
|>
|>I did a VBA to set profile PVI's.
|>I use this when importing a profile from a text file with PVI's listed.
|>The varNewPVIs is an array of station, elev, VC Length arrays.
|>
|>I know this a bunch of code to digest, all I am looking for is maybe comments on my use of
|>objProfile.Entities.RemoveAll.
|>Essentially, I am wiping the profile clean each time I run, then adding back PVI's.
|>It works great the first time, then if I run again, it is never able to add pvi's.
|>It is able to clear them after the first run, but not add them back.
|>
|>I removed a bunch of error checking code to keep it as clean as possible, curious if anyone can comment on if I missed a
|>method or something. I know my use of mstrReturnMsg to indicate an error is wierd, there is a reason for it though...
|>
|>Here is the code:
|>
|>'function to fill in vert alignment with new pvis
|>Public Sub PutPVIs(ByVal strName As String, ByVal strVAName As String, ByVal varNewPVIs As Variant)
|> Dim intIndex As Integer
|>'get profile object
|> Dim objProfile As AeccProfile
|> Set objProfile = getVAlign(strName, strVAName) 'see function below, no problems though
|>'remove existing PVI's
|> objProfile.Entities.RemoveAll
|>'add pvis
|> Dim objPVIs As AeccProfilePVIs
|> Set objPVIs = objProfile.PVIs
|> 'Test profile type!
|> If objProfile.Type = aeccExistingGround Then
|> 'add EG type PVI's, do in any order
|> For intIndex = LBound(varNewPVIs, 2) To UBound(varNewPVIs, 2)
|> Call objProfile.PVIs.Add(varNewPVIs(0, intIndex), varNewPVIs(1, intIndex), aeccProfileTangent)
|> Next
|> ElseIf objProfile.Type = aeccFinishedGround Then
|> 'add FG type PVI's
|> 'must add first, then last, then any others in between, cannot add VC without ending PVI
|> 'do first and last items, must be aeccProfileTangent
|> Call objProfile.PVIs.Add(varNewPVIs(0, LBound(varNewPVIs, 2)), varNewPVIs(1, LBound(varNewPVIs, 2)),
|>aeccProfileTangent)
|> Call objProfile.PVIs.Add(varNewPVIs(0, UBound(varNewPVIs, 2)), varNewPVIs(1, UBound(varNewPVIs, 2)),
|>aeccProfileTangent)
|> 'make sure we have more than two items
|> If LBound(varNewPVIs, 2) + 1 < UBound(varNewPVIs, 2) Then
|> For intIndex = LBound(varNewPVIs, 2) + 1 To UBound(varNewPVIs, 2) - 1
|> 'handle VC or GB
|> If varNewPVIs(2, intIndex) > 0 Then
|> Call objProfile.PVIs.Add(varNewPVIs(0, intIndex), varNewPVIs(1, intIndex), aeccParabola,
|>varNewPVIs(2, intIndex))
|> Else
|> Call objProfile.PVIs.Add(varNewPVIs(0, intIndex), varNewPVIs(1, intIndex), aeccProfileTangent)
|> End If
|> Next
|> End If
|> End If
|> If Err <> 0 Then
|> mstrReturnMsg = "Error, No PVI's added"
|> Err.Clear
|> Else
|> mstrReturnMsg = "PVI's added"
|> End If
|>
|>EndOut:
|> Set objAlignment = Nothing
|> Set objProfile = Nothing
|> Set objPVIs = Nothing
|>
|>End Sub
|>
|>Private Function getVAlign(ByVal strName As String, ByVal strVAName As String) As AeccProfile
|> On Error Resume Next
|> Dim objAlign As AeccAlignment
|> Dim oProfTmp As AeccProfile
|> Set objAlign = getAlign(strName)
|> 'get vert alignment by name
|> Dim intIndex As Integer
|> Dim intWinnter As Integer
|> intWinnter = -999
|> intIndex = 0
|> For Each oProfTmp In objAlign.Profiles
|> If oProfTmp.Name = strVAName Then intWinnter = intIndex
|> intIndex = intIndex + 1
|> Next
|> Set getVAlign = objAlign.Profiles.Item(intWinnter)
|> If getVAlign Is Nothing Then
|> mstrReturnMsg = "Error, No profile available by name provided"
|> End If
|> Set objAlign = Nothing
|>End Function
|>James Maeding
|>Civil Engineer and Programmer
|>jmaeding - at - hunsaker - dotcom
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom