What's new

Accessing Custom Views or Extrusion Planes

KageDev

Member
The project I've been working on the last few months requires that a user is aware of the orientation of a part before exporting it as a dxf file. My boss wants the ability to have a universal view declared as a custom view that will always have a part in its correct orientation before running the plugin. From what I've researched, the API only supports built in views so I am currently just exporting the front view. I've tried to explain to him that the library files that Alibre provides doesn't support new custom views since library files are hard coded. Am I wrong about this? He says its a requirement and that I need to find a work around. My initial thought was that I find the extrusion plane and then find which view the extrusion plane is on. I haven't found anything in the API that relates to extrusion in this way so I'm thinking that this is something that is not currently possible. I've suggested that the user needs to make a mental note to always use the front view and extrude on that but he insists that it is possible. Wanted to check in here before I try to explain that there really isn't a solution at all. Anybody have any suggestions?
 

HaroldL

Alibre Super User
You can create a custom view for your part, I don't know if it is something that a script can be written for, but it can be done manually.
Select the sketch for the extrusion you want to orient, then click the Reset View Ctrl+Shift+Z). Then in the Orientations dialog (Crtl+U) ADD a new orientation for that view. In your drawing select that new view for the drawing before exporting the dxf.
 

KageDev

Member
You can create a custom view for your part, I don't know if it is something that a script can be written for, but it can be done manually.
Select the sketch for the extrusion you want to orient, then click the Reset View Ctrl+Shift+Z). Then in the Orientations dialog (Crtl+U) ADD a new orientation for that view. In your drawing select that new view for the drawing before exporting the dxf.
I am exporting the dxf through code so I would need to access the custom view through code. I haven't found anything that suggests that I can.
 

KageDev

Member
Pass the transformation to CreateStandardViews -> workspaceOrientation to override the default.
I think what I need to access is the SavedViews property but the program locks up when trying to access a specific view within it. I have no purpose to create a new view because the view should already be created from the GUI. Unless there is a dynamic way to ensure that the extrusion is always facing the front I don't know if it would be possible to use that feature. Thanks for the suggestion though.
 

NateLiquidGravity

Alibre Super User
I can't remember if I reported the problem about trying to access views but even if I did it would probably be good to report it to support yourself.

Do you need a custom view or a standard view? Are they always the same view or how will you determine the correct one to use?
 

KageDev

Member
I can't remember if I reported the problem
You had mentioned it in the post you linked to. Stephan had noted that.
Do you need a custom view or a standard view?
It would be a custom view. The idea is that if someone did not create and extrude a part in the front view. They would orient it to appear as if it was in the front view, and call it universal view.
Are they always the same view or how will you determine the correct one to use?
I would always be looking for a view called 'universal'. If there is a way to reorient a view from say 'Side' view to 'Front' view, that would solve my issue completely and I wouldn't have to worry about custom views. My boss doesn't think that is possible so I haven't even looked into it.
 

KageDev

Member
My example code doesn't work for you?
With how my add-on functions it would be difficult to automatically and dynamically alter the view. I suppose I could develop a view transform add-on that does this specifically. With this, if I always use 'Front view' in my DesignSession, will this alter the orientation and keep the name front view and appear a different way? As long As I can access the built in front view and have it appear as if the extrusion happened in the front view, I think it should work fine.
 

stepalibre

Alibre Super User
With how my add-on functions it would be difficult to automatically and dynamically alter the view. I suppose I could develop a view transform add-on that does this specifically. With this, if I always use 'Front view' in my DesignSession, will this alter the orientation and keep the name front view and appear a different way? As long As I can access the built in front view and have it appear as if the extrusion happened in the front view, I think it should work fine.
You're working with a custom view transformation. This can be any transformation a custom one or a standard view. I use a 4x4 matrix in the example that recreates standard views as well as a custom view.
 

NateLiquidGravity

Alibre Super User
You can't change what the stock views of the model are called in the model. You can't reorient the body relative to the xyz in a part either.

You could make an addon that saves the current view transformation (IADDesignSession.ViewTransform Property) into the part (or somewhere) with the click of a button. This could then be used to create drawing views using the saved view transformation. If you send it directly to the drawing with that button you don't even necessarily have to save the transformation data.
 

stepalibre

Alibre Super User
You can't change what the stock views of the model are called in the model. You can't reorient the body relative to the xyz in a part either.

You could make an addon that saves the current view transformation (IADDesignSession.ViewTransform Property) into the part (or somewhere) with the click of a button. This could then be used to create drawing views using the saved view transformation. If you send it directly to the drawing with that button you don't even necessarily have to save the transformation data.
And the view API's are glitchy so beware. I found many issues throughout my projects, too many to recall. SetViewTransform is a stable method.

Here is a demo program:

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)
    Dim Drawing As AlibreX.IADDrawingSession = Root.CreateEmptyDrawing("asdf")
    Dim point_orgin As Object = Drawing.GeometryFactory.Create2DPoint(25,25)
    Dim mSheet As Object = Drawing.Sheets.ActiveSheet
    mSheet.ModifySheetBlank("test", 150,150, ADUnits.AD_CENTIMETERS)
    Dim DesignFile As String = ".AD_PRT"
    mSheet.CreateStandardViews(DesignFile, ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES,1,1,ADViewOrientation.AD_FRONT Or ADViewOrientation.AD_TOP, point_orgin,Trans) 
    Dim output As String = DesignFile.Replace(".AD_PRT","-output-1.DXF")
    Drawing.ExportDXF(output)
    Trans = ADPartGeoFac.CreateTransform(CustomISO.ToArray())
    AdPart.SetViewTransform(Trans)
End Sub

And for some reason, some things seem to work better in IronPython than in VB or C#. I removed all view related code from my projects because of its inconsistent nature. I use SetViewTransform because it works fine.
 
Last edited:

stepalibre

Alibre Super User
And the view API's are glitchy so beware. I found many issues throughout my projects, too many to recall. SetViewTransform is a stable method.

Here is a demo program:

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)
    Dim Drawing As AlibreX.IADDrawingSession = Root.CreateEmptyDrawing("asdf")
    Dim point_orgin As Object = Drawing.GeometryFactory.Create2DPoint(25,25)
    Dim mSheet As Object = Drawing.Sheets.ActiveSheet
    mSheet.ModifySheetBlank("test", 150,150, ADUnits.AD_CENTIMETERS)
    Dim DesignFile As String = ".AD_PRT"
    mSheet.CreateStandardViews(DesignFile, ADDrawingViewType.AD_STANDARD, ADDetailingOption.AD_TANGENT_EDGES,1,1,ADViewOrientation.AD_FRONT Or ADViewOrientation.AD_TOP, point_orgin,Trans)
    Dim output As String = DesignFile.Replace(".AD_PRT","-output-1.DXF")
    Drawing.ExportDXF(output)
    Trans = ADPartGeoFac.CreateTransform(CustomISO.ToArray())
    AdPart.SetViewTransform(Trans)
End Sub

And for some reason, some things seem to work better in IronPython than in VB or C#. I removed all view related code from my projects because of its inconsistent nature. I use SetViewTransform because it works fine.

I'm not sure if this matters, but it's worth stating. I haven't tried this or much of my v27 code in v28. It's possible internal updates have some effect on our code.
 

NateLiquidGravity

Alibre Super User
I just tested (albeit using the API thru AlibreScript) and it worked just fine to take the part session ViewTransform and throw it right into the end of CreateStandardViews without doing any changes to the transform or doing any array stuff.

A few notes though: The part file must be saved or the view can't be made and if the saved part file is obsolete so will be the DXF made from it.
Since it is projected into the drawing any edge not parallel to the plane of view will not be true length. In this picture the overall scale is off only due to zoom, but since most of those lines are not parallel to the view they will not be true length measure in the DXF either.


view transform.png
 

stepalibre

Alibre Super User
I just tested (albeit using the API thru AlibreScript) and it worked just fine to take the part session ViewTransform and throw it right into the end of CreateStandardViews without doing any changes to the transform or doing any array stuff.

A few notes though: The part file must be saved or the view can't be made and if the saved part file is obsolete so will be the DXF made from it.
Since it is projected into the drawing any edge not parallel to the plane of view will not be true length. In this picture the overall scale is off only due to zoom, but since most of those lines are not parallel to the view they will not be true length measure in the DXF either.


View attachment 41952
Yes, It works via IronPython just fine for some reason but not C# and Vb. I tried many variations and it worked to a point, very odd. Can you post the code?
 
Top