Runtime Error in VBA Code

Runtime Error in VBA Code

sergiopedroza
Participant Participant
2,637 Views
7 Replies
Message 1 of 8

Runtime Error in VBA Code

sergiopedroza
Participant
Participant

Hi All,

I am trying to execute a vba code in Civil 3D but it is giving a runtime error: Invalid use of property. The code follows below

Sub list_alignment_entyties()
Dim i As Integer
Dim oTangent As AeccAlignmentTangent
Dim oArc As AeccAlignmentArc
Dim oSpiral As AeccAlignmentSpiral
Dim oSCSGroup As AeccAlignmentSCSGroup

Debug.Print "Number of Entities: "; oAlignment.Entities.Count
For i = 0 To oAlignment.Entities.Count - 1
Select Case (oAlignment.Entities.Item(i).Type)
Case aeccTangent
Set oTangent = oAlignment.Entities.Item(i)
Debug.Print "Tangent length:" & oTangent.Length
Case aeccArc
Set oArc = oAlignment.Entities.Item(i)
Debug.Print "Arc radius:" & oArc.Radius
Case aeccSpiral
Set oSpiral = oAlignment.Entities.Item(i)
Debug.Print "Spiral A value:" & oSpiral.A
Case aeccSpiralCurveSpiralGroup
Set oSCSGroup = oAlignment.Entities.Item(i)
Debug.Print "Radius of curve in SCS group:" _
& oSCSGroup.Arc.Radius
' And so on for AeccAlignmentSTSGroup,
' AeccAlignmentSTGroup, AeccAlignmentTSGroup
' AeccAlignmentSCGroup, and AeccAlignmentCSGroup types.
End Select
Next i
End Sub


I can't identify why the error occurs as this code is in AutoCAD Civil 3D API Developers Guide

0 Likes
Accepted solutions (1)
2,638 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

Can you set a breakpoint and step through the code to identify which line gives the error?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 8

sergiopedroza
Participant
Participant

Hi EdJobe, thanks for answeringError occurs early in code

Debug.Print "Number of Entities: "; oAlignment.Entities.Count

 

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

Did you add the Debug statement? Are you sure you copied the code correctly? The reason I say this is because that's the first line after the dim statements and oAlignment has not been set yet. Any reference to it will be null. You can't get the Count property of something that doesn't exist.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 5 of 8

sergiopedroza
Participant
Participant
0 Likes
Message 6 of 8

Ed__Jobe
Mentor
Mentor
Accepted solution

That isn't a complete code sample, it doesn't have anything that gets/selects an alignment. It doesn't even have a Sub/Function statement. My guess is that it assumes you are already familiar with basic AutoCAD programming before attempting the C3D api.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 7 of 8

sergiopedroza
Participant
Participant

ok. I have a little knowledge of vba with Excel, but in Civil 3D it's the first time I'm working. I don't know Civil's methods, objects and entities and I'm learning. I thought the Developer's Guide could give me a notion but I'm seeing that I need to study further. Thanks for the help and sorry for your time wasted on me. Thank you very much

0 Likes
Message 8 of 8

Ed__Jobe
Mentor
Mentor

No Problem.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature