What's new

Changing the view for the user

Hello everyone

Is there a function in Alibre Script where I can change the current view?
Example: The User opens a file withing a script and the file is automatically opened in ISO view.

Thanks
 

Cator

Senior Member
Hi Daniel,
not directly. You should create a script in AutoHotKey that types the shortcut that sets the desired view, then later turn it into an .exe.
Alibre script could call this script and set the desired view by playing well with the timing.
I hope I've given you an idea.
Regards,
Francesco
 

idslk

Alibre Super User
You don't need auto bla...
you can do it using the Alibre API with Alibre Script

Regards
Stefan
 

stepalibre

Alibre Super User
Can you? I tried accessing DesignSession.SavedViews and my Alibre froze.
Yes, SavedViews.Item appear to be broken and is on my AlibreAPI bug/issue list. The COM object seemed to lock up the GUI and crash under headless mode.
Code:
System.Runtime.InteropServices.COMException (0x8000FFFF): Object reference not set to an instance of an object.
   at com.alibre.automation.ExceptionMap.handleException(Exception inputException)
   at com.alibre.automation.AlibreDesignSession.get_SavedViews()
SavedViews.Count did work so this confirmed to me that there is an issue with the interface and not user error. I added new views and the count increased.

But I don’t think we can change a view in this way even if it did work, and all those properties are read-only no create or set methods.

I guess this is why SavedViews or view related code is excluded from AlibreScript.

It is possible to use the IADDesignSession.SetViewTransform and the IADGeometryFactory.CreateTransform methods to change the view manually via 4x4 matrixes creating the standard views yourself. Here is a working example in vb.
Code:
Sub Main()
    Dim Session As IADSession
    Dim Hook As IAutomationHook
    Dim Root As IADRoot
    Dim AdPart As AlibreX.IADPartSession
    Hook = GetObject(, "AlibreX.AutomationHook")
    Root = Hook.Root
    Session = Root.TopmostSession
    AdPart = Session
    Dim GetCurrentViewTransform As New List(Of Double)
    GetCurrentViewTransform.AddRange(AdPart.ViewTransform.Array)
    Dim ADPartGeoFac As AlibreX.IADGeometryFactory
    ADPartGeoFac = AdPart.GeometryFactory
    Dim TopMatrix As New List(Of Double) From {
        -1, 0, 0, 0,
        0, 0, 1, 0,
        0, 1, 0, 0,
        0, 0, 0, 1
    }
    Dim FrontMatrix As New List(Of Double) From {
    -1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    0, 0, 0, 1
}
    Dim CustomISO As New List(Of Double) From {
        0.70710676908493,
        0.40824830532074,
        -0.577350258827209,
        0,
        0,
        0.816496610641479,
        0.577350258827209,
        0,
        0.70710676908493,
        -0.40824830532074,
        0.577350258827209,
        0,
        0,
        0,
        0,
        1
    }
    Dim Trans As AlibreX.IADTransformation
    Trans = ADPartGeoFac.CreateTransform(FrontMatrix.ToArray())
    AdPart.SetViewTransform(Trans)
    Trans = ADPartGeoFac.CreateTransform(TopMatrix.ToArray())
    AdPart.SetViewTransform(Trans)
    Trans = ADPartGeoFac.CreateTransform(GetCurrentViewTransform.ToArray())
    AdPart.SetViewTransform(Trans)
    Trans = ADPartGeoFac.CreateTransform(CustomISO.ToArray())
    AdPart.SetViewTransform(Trans)
End Sub

These lines apply what would be the Front View:
Code:
    Trans = ADPartGeoFac.CreateTransform(FrontMatrix.ToArray())
    AdPart.SetViewTransform(Trans)

Top View:
Code:
    Trans = ADPartGeoFac.CreateTransform(TopMatrix.ToArray())
    AdPart.SetViewTransform(Trans)

Current view transform:
Code:
    Trans = ADPartGeoFac.CreateTransform(GetCurrentViewTransform.ToArray())
    AdPart.SetViewTransform(Trans)

Custom view transform based on my model and units:
Code:
    Trans = ADPartGeoFac.CreateTransform(CustomISO.ToArray())
    AdPart.SetViewTransform(Trans)

You can use Alibre to get the view transforms from existing views in an automated way or create all the view matrixes by hand which are 3D standards. This is how I think you would create view and camera features yourself. I went down this rabbit hole because a want to script zoom and panning in on a selection. I'll use IADDesignSession.SetViewTransform as a basis. I haven't fully evaluated the API just yet so not sure of limitations.

I still find it more useful to control views, menus, commands through keyboard shortcuts using win32, autoit or autohotkey from my apps and scripts. This can give you much more control and the ability to connect apps together easily. For example switching the views of 3 CAD apps to ISO view, a custom layout, etc. Updating views in code is more usefully to me when I need to zoom in, rotate and or move to a position or view during an interactive or automated process.

@daniel.greil you can search inside AlibreScriptAPI
Use the standard Ctrl + F to find something you're looking for or download it.

Hope this helps.
 
Top