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: 

Profile does not accept PVI's after a call to Profile.Entities.RemoveAll

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
382 Views, 7 Replies

Profile does not accept PVI's after a call to Profile.Entities.RemoveAll

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
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

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
Message 3 of 8
Anonymous
in reply to: Anonymous

this is driving me nuts, so much testing with no clear pattern emerging.
Maybe Peter or someone versed in modifying profiles could chime in, thx

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
Message 4 of 8
Anonymous
in reply to: Anonymous

I don't know you method, and I didn't read the full code, but what about
deleting the profile object and recreating it with each pass instead of
deleting all the PVIs and rebuilding?

I was doing something similar in the RAS tools. Look for a profile by
that name, then delete and rebuild. Just a thought.
--
James Wedding, P.E.
Engineered Efficiency, Inc.
The Site: www.eng-eff.com
The Blog: www.civil3d.com
The Book: www.masteringcivil3d.com
C3D SP2 Mac Book Pro, XP SP2, 3GB
Message 5 of 8
Anonymous
in reply to: Anonymous

actually that is the next thing I will try.
I was concerned that doing that could cause too much "reaction" in the drawing.
I'll find out, but I have to be careful that other profile views showing mine as superimposed, do not freak out from
objects popping in and out of existence.
I'll report back...

while you're here, Peter mentioned we could maybe imitate a true 2:1 side slope by making a subassembly that adjusts its
daylight slope based on the road profile slope. I thought whoever did that first would have a popular blog entry, I
could sure use an assembly like that.

james.wedding <>
|>I don't know you method, and I didn't read the full code, but what about
|>deleting the profile object and recreating it with each pass instead of
|>deleting all the PVIs and rebuilding?
|>
|>I was doing something similar in the RAS tools. Look for a profile by
|>that name, then delete and rebuild. Just a thought.
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 6 of 8
Anonymous
in reply to: Anonymous

I'll be honest, if we write a custom assembly, it's not something we
generally give away. If you want it done quickly, we'd be happy to
discuss a proposal.

--
James Wedding, P.E.
Engineered Efficiency, Inc.
The Site: www.eng-eff.com
The Blog: www.civil3d.com
The Book: www.masteringcivil3d.com
C3D SP2 Mac Book Pro, XP SP2, 3GB
Message 7 of 8
Anonymous
in reply to: Anonymous

I'm not under the gun for it yet, may be a month before I need it bad, I'll see.

james.wedding <>
|>I'll be honest, if we write a custom assembly, it's not something we
|>generally give away. If you want it done quickly, we'd be happy to
|>discuss a proposal.
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom
Message 8 of 8
Anonymous
in reply to: Anonymous

Hey, good call James. Deleting and recreating the profile does run without errors so far.
I'm happy to share code on this stuff for anyone that wants, just be specific what you want.
(not to contrast with EE's charging for subassembly help, that is entirely more difficult and worthy of payment for help
on it.)

james.wedding <>
|>I don't know you method, and I didn't read the full code, but what about
|>deleting the profile object and recreating it with each pass instead of
|>deleting all the PVIs and rebuilding?
|>
|>I was doing something similar in the RAS tools. Look for a profile by
|>that name, then delete and rebuild. Just a thought.
James Maeding
Civil Engineer and Programmer
jmaeding - at - hunsaker - dotcom

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report