Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Command Line Camera.dump Height and Width in API?

jkotowicz1
Explorer Explorer
636 Views
3 Replies
Message 1 of 4

Command Line Camera.dump Height and Width in API?

jkotowicz1
Explorer
Explorer

Hi. Im working on an adding, that will set the size of a model to 1:1 scale and lock the ability to zoom-in and zoom-out.

 

In txt command line camera.dump gives values height and width, and it seems like the height is what I need- it seems like its height of the camera in ortographic view, when viewing from TOP or any side (left, right etc.). But I don't see this value in API. I tried to get distance from Eye to Target, or length of a vector, but the values are different.

 

Does anybody have any suggestions how should I set my view to 1:1 and lock the scale/distance/zoom for a while, so that I'm forced to see object in real scale?

0 Likes
637 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

I think what you're trying to do will be difficult. It's not possible to block the user from zooming in and out. Also, to set the view to be "true" scale, you would need to know the resolution of the monitor. I know the Fusion API doesn't expose that. The size that's being returned by the text command you mentioned is the bounding box of the geometry that the current camera is considering. You can get the bounding box from the various geometry, but you would need to combine those to get the overall bounds. With a perspective view, things will appear smaller or larger depending on how far from the eye they are, so you might also want to limit it to an orthographic camera.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like
Message 3 of 4

kandennti
Mentor
Mentor

Hi @jkotowicz1 .

 

What affects the size in the screen is not the distance between eye and target, but the Camera.viewExtents property.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-1962e74e-2fc2-4821-887f-7abe2bc4c09a 


Also, the resolution of the display can be obtained by using Tkinter.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
from tkinter import *

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        tk = Tk()
        monitor_height = tk.winfo_screenheight()
        monitor_width = tk.winfo_screenwidth()
        
        print(f'width x height = {monitor_width} x {monitor_height} (pixels)')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 4 of 4

kandennti
Mentor
Mentor

@jkotowicz1 .

 

We tried our hand at "displaying at full size".

The following script creates a sketch in a new document, draws a rectangle of 50 mm on each side, and displays it full-size.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
from tkinter import *

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        # sketch
        skt: adsk.fusion.Sketch = root.sketches.add(
            root.xYConstructionPlane
        )
        skt.sketchCurves.sketchLines.addTwoPointRectangle(
            adsk.core.Point3D.create(-2.5,-2.5,0),
            adsk.core.Point3D.create(2.5,2.5,0),
        )

        # full size
        execFullSize()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def execFullSize():
    validation_Length = 254
    app: adsk.core.Application = adsk.core.Application.get()
    ui: adsk.core.UserInterface = app.userInterface

    def get_dpi():
        screen = Tk()
        return screen.winfo_fpixels('1i')

    def getViewLength():
        app: adsk.core.Application = adsk.core.Application.get()
        vp: adsk.core.Viewport = app.activeViewport

        p0 = adsk.core.Point3D.create(0,0,0)
        p1 = adsk.core.Point3D.create(validation_Length*0.1,0,0)
        m0 = vp.modelToViewSpace(p0)
        m1= vp.modelToViewSpace(p1)
        return m0.distanceTo(m1)

    def dumpmsg(s):
        adsk.core.Application.get().log(s)
        print(s)

    try:
        vp: adsk.core.Viewport = app.activeViewport
        cam: adsk.core.Camera = vp.camera
        cam.eye = adsk.core.Point3D.create(0,0,1)
        cam.target = adsk.core.Point3D.create(0,0,0)
        cam.upVector = adsk.core.Vector3D.create(0,1,0)
        cam.cameraType = adsk.core.CameraTypes.OrthographicCameraType
        vp.camera = cam
        vp.refresh()

        pixel2millimeter = 25.4 / get_dpi()
        dumpmsg(f'DPI {get_dpi()}')

        dist = getViewLength()
        dumpmsg(f'ViewSpace Dist {dist}-{dist * pixel2millimeter}')

        viewLength = dist * pixel2millimeter
        ratio = (viewLength / validation_Length) ** 2

        cam = vp.camera
        cam.viewExtents = cam.viewExtents * ratio
        vp.camera = cam
        vp.refresh()

        dist = getViewLength()
        dumpmsg(f'ViewSpace Dist {dist}-{dist * pixel2millimeter}')
        dumpmsg('**')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Try running the script in Fusion360 with different window sizes.
It is displayed full-size on my PC at work, but a little smaller on my laptop at home. The cause is unknown.

1 Like