VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Runtime Error in VBA Code

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
sergiopedroza
2107 Views, 7 Replies

Runtime Error in VBA Code

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

7 REPLIES 7
Message 2 of 8
ed57gmc2
in reply to: sergiopedroza

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
in reply to: ed57gmc2

Hi EdJobe, thanks for answeringError occurs early in code

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

 

Message 4 of 8
ed57gmc2
in reply to: sergiopedroza

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
in reply to: ed57gmc2
Message 6 of 8
ed57gmc2
in reply to: sergiopedroza

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
in reply to: ed57gmc2

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

Message 8 of 8
ed57gmc2
in reply to: sergiopedroza

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

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report