chromoly script how to?

can someone give an idea how the tic lines on the sides are done ?

if possible would like to make another type of grid !

but could not find how it even begins to work!

thanks for any feedback

not sure how chromoly works exactly, but here’s an example:

import bpy
import bgl
import blf

step = 30

def draw_callback_px(self, context):

    font_id = 0  # XXX, need to find out how best to get this.
    x, y = self.mouse
    width = context.region.width
    height = context.region.height

    # draw some text
    blf.size(font_id, 11, 72)
    #blf.position(font_id, 15, 30, 0)
    #blf.draw(font_id, "Hello Word ")

    for i in range(0, height+step, step):
        blf.position(font_id, 2, i+2, 0)
        blf.draw(font_id, str(i))
        
    blf.position(font_id, x+15, y-20, 0)
    blf.draw(font_id, "%i, %i" % (x, y))
    
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 0, 0, 1)
    bgl.glLineWidth(1)

    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2i(x, 0)
    bgl.glVertex2i(x, height)
    bgl.glVertex2i(0, y)
    bgl.glVertex2i(width, y)
    bgl.glColor4f(1, 1, 1, 0.5)
    for i in range(0, height+step, step):
        bgl.glVertex2i(0, i)
        bgl.glVertex2i(30, i)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)


class ModalDrawOperator(bpy.types.Operator):
    """Draw a line with the mouse"""
    bl_idname = "view3d.modal_operator"
    bl_label = "Simple Modal View3D Operator"

    def modal(self, context, event):
        context.area.tag_redraw()

        if event.type == 'MOUSEMOVE':
            self.mouse = (event.mouse_region_x, event.mouse_region_y)

        elif event.type == 'LEFTMOUSE':
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'FINISHED'}

        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'CANCELLED'}

        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            # the arguments we pass the the callback
            args = (self, context)
            # Add the region OpenGL drawing callback
            # draw in view space with 'POST_VIEW' and 'PRE_VIEW'
            self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL')

            self.mouse = (0, 0)

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(ModalDrawOperator)


def unregister():
    bpy.utils.unregister_class(ModalDrawOperator)

if __name__ == "__main__":
    register()


interesting and I think it could work

how to make it stick to the viewport ?

right now looks like that each time the mouse move the cursor you need to call it back
it does not stick on viewport !

note:
in chromoly there was a button in N panel to enable it or not!

and don’t really need to show the cursor’s location on viewport
guess I can remove that !

thanks

just store an offset and set up an event handler for the N keypress. If enabled, add the relative change to the offset so you can draw the ticks accordingly.

I found how to make the verti lines too

but how many times is it drawn on viewport?

thanks

is there a test to determine if viewport is in front - side or top view ?

thanks

there’s a workaround:

so basically no way to know if in a certain view = side = front or top
without looking at the angle in a view matrix I guess!

now played a little to make some lines with this opengl
and looks like it is doing vector line so have to give in sequence 2 points X and Y and it makes a line

is there some sort of simple lib already made to make other object type may be ?

if u have many lines to draw on screen it is hard to center any complicated object with many lines !

thanks