 Pythonscript Rotate Object Azimuth and Elevation

Hello,
I am using the pythonscript tool in rhino to create a command, so not rhinocommon. I am trying to create a line that rotates in azimuth and then rotates in elevation. The issue I am finding is if you keep to one elevation axis, it begins to swirl. For example, if I did the [1,0,0] axis, then it will swirl around -45-45 degrees and 135- -135 degrees. Is there a way to rotate so that the elevation is consistent? I have been looking all over the place for an example, but have yet to come across it. Some of my code is below.

i = -180
while i <= 180:
p = rs.RotateObject(line,startpoint,i,[0,0,1])
startp = rs.CurveStartPoint(p)
endp = rs.CurveEndPoint(p)
j = -45
while j <= 90:
rs.RotateObject(t,startp,j,[1,0,0])
j = j+1
i = i+1

pls post the full code and use 3 backticks to display your code as code ```

Just realized I didn’t reply to your thread. I am trying to rotate on the azimuth plane, then rotate in elevation. In grasshopper, to do the same thing, you have to rotate the axis plane for elevation along with the azimuth angle. I have tried using sin for x and cos for y, but have yet to get it to work like I want it to. Any help would be much appreciated. I think I did what you asked with the 3 backticks, please let me know if I did it wrong.

import rhinoscriptsyntax as rs
import math

__commandname__ = "Test1"

def RunCommand( is_interactive ):
x = 0
y = 0
z = 0
for i in range(-180, 180, 1):
q = rs.RotateObject(p,point,i,[0,0,1])
startp = rs.CurveStartPoint(q)
endp = rs.CurveEndPoint(q)
for j in range(-45,90,1):
r = rs.RotateObject(t,startp,j,[1,0,0])

not sure, but is it something like this?

import rhinoscriptsyntax as rs
import math
import System.Drawing.Color as clr
x = 0
y = 0
z = 0
for i in range(-45, 90, 5):
color = clr.FromArgb(i*2+90,0,0)
q = rs.RotateObject(p,point,i,[1,0,0])
startp = rs.CurveStartPoint(q)
endp = rs.CurveEndPoint(q)
for j in range(-180,180,5):
r = rs.RotateObject(t,startp,j,[0,0,1])
rs.ObjectColor(t, color)

note that if you want to do this faster, it’s better to turn display off:

rs.EnableRedraw(False)