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: 

setting profile style

6 REPLIES 6
Reply
Message 1 of 7
joshlund
266 Views, 6 Replies

setting profile style

Good afternoon,

Can someone please try changing the style of a profile using vba? I tried several times and started over several times but my code keeps failing.

The error number / description is -2147467259 / "Method 'Item' of object 'IAecProfileStyles' failed"

Thanks,
Josh


Dim cAlign As AeccAlignments
Set cAlign = oSite.Alignments
Dim oAlign As AeccAlignment
Dim oProfile As AeccProfile

Dim strProfStyleName As String
strProfStyleName = "xyz"

Dim oProfileStyle As AeccProfileStyle
On Error GoTo errordump

' * * * code fails here
Set oProfileStyle = g_oAeccDb.ProfileStyles.Item(strProfStyleName)
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: joshlund

Based on a post by Nick Z from back in January 2007, there is a real oddity
with the ProfileStyles collection....

Use this and it works as you'd expect:

Set oProfileStyle = g_oAeccDb.LandProfileStyles.Item(strProfStyleName)


"jlund" wrote in message news:5911429@discussion.autodesk.com...
> Good afternoon,
>
> Can someone please try changing the style of a profile using vba? I tried
> several times and started over several times but my code keeps failing.
>
> The error number / description is -2147467259 / "Method 'Item' of object
> 'IAecProfileStyles' failed"
>
> Thanks,
> Josh
>
>
> Dim cAlign As AeccAlignments
> Set cAlign = oSite.Alignments
> Dim oAlign As AeccAlignment
> Dim oProfile As AeccProfile
>
> Dim strProfStyleName As String
> strProfStyleName = "xyz"
>
> Dim oProfileStyle As AeccProfileStyle
> On Error GoTo errordump
>
> ' * * * code fails here
> Set oProfileStyle = g_oAeccDb.ProfileStyles.Item(strProfStyleName)
Message 3 of 7
joshlund
in reply to: joshlund

Thanks, Jeff. Even after changing the code as suggested this is still failing. All code except getObjects is below. . . Any other suggestion?

Dim cAlign As AeccAlignments
Set cAlign = oSite.Alignments
Dim oAlign As AeccAlignment
Dim oProfile As AeccProfile

Dim strProfStyleName As String
strProfStyleName = "PGP"

Dim oProfileStyle As AeccProfileStyle
Set oProfileStyle = g_oAeccDb.LandProfileStyles.Item(strProfStyleName)

For Each oProfileStyle In g_oAeccDb.LandProfileStyles 'this works - outputs all styles to Immediate window
Debug.Print oProfileStyle.Name
Next

For Each oAlign In cAlign
Debug.Print g_oAeccDb.LandProfileStyles.Item(strProfStyleName).Name 'this works
'Debug.Print oProfileStyle.Name 'fails here - oProfileStyle not set

For Each oProfile In oAlign.Profiles
If Left(oProfile.Name, 2) = "EG" Then
Set oProfile.Style = g_oAeccDb.LandProfileStyles.Item(strProfStyleName) ' this fails but works above
End If
Next
Next
Message 4 of 7
joshlund
in reply to: joshlund

1. This is Civil 3D 2008 SP2
2. The error msg is "Object doesn't support this property or method" / run-time error 438

Thanks,
Josh
Message 5 of 7
Anonymous
in reply to: joshlund

You're welcome.
Remove the "Set" from this line and it works fine.

Set oProfile.Style = g_oAeccDb.LandProfileStyles.Item(strProfStyleName)


wrote in message news:5912096@discussion.autodesk.com...
Thanks, Jeff. Even after changing the code as suggested this is still
failing. All code except getObjects is below. . . Any other suggestion?
Message 6 of 7
joshlund
in reply to: joshlund

Thanks, Jeff. That did it!

When should the Set keyword be used? This is something the frequently trips me up. Are there some guidelines for using it?

Thanks,
Josh
Message 7 of 7
Anonymous
in reply to: joshlund

You're welcome, Josh.

Like you, I thought a Set was necessary for this since you are assigning an
object to something. But since it is a property we are assigning the object
to, it isn't needed (or wanted, evidently). I've been playing with .NET (VB
& C#) for too long I guess, neither of which use the Set statement, so I'm
drawing a blank for a good explanation....

I do know that when assigning a variable which has been cast as an object,
you MUST use Set.



"jlund" wrote in message news:5913375@discussion.autodesk.com...
> Thanks, Jeff. That did it!
>
> When should the Set keyword be used? This is something the frequently
> trips me up. Are there some guidelines for using it?
>
> Thanks,
> Josh

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report