ViewOrientationFromBase question

ViewOrientationFromBase question

machiel.veldkamp
Collaborator Collaborator
731 Views
8 Replies
Message 1 of 9

ViewOrientationFromBase question

machiel.veldkamp
Collaborator
Collaborator

Im working on this:
http://forums.autodesk.com/t5/inventor-customization/how-to-tackle-this-idea/m-p/6829858#M69613

 

 

And I'm not getting on how to make a view that is dependent on the vieworientation of another base view. 

 

I tried

 

SyntaxEditor Code Snippet

Dim DrawingView.ViewOrientationFromBase As oOrientation =  True

Dim oOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kRightViewOrientation

But that doesn't work.

 

I can't find documentation on this ViewOrientationFromBase but it seems this is the thing I need.

 

Anyone that dealt with this before? 

 

 

 

What I have until now:

 

SyntaxEditor Code Snippet

'Get the active document
Dim oDoc As Document = ThisApplication.ActiveDocument
'Exit if the document isn't drawing
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub

'Get the correct sheet
Dim oSheet As Sheet = oDoc.ActiveSheet

'Exit if the sheet have no views
If oSheet.DrawingViews.Count = 0 Then Exit Sub

'Get the selection from user
Dim oSelect As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick a view")

'Exit if nothing is selected
If oSelect Is Nothing Then Exit Sub

'Get the view
Dim oView As DrawingView = oSelect

'Get the first document from the view
Dim oModel As Document = oDoc.ReferencedDocuments.Item(1)

'Exit if the referenced document isn't sheet metal
If oModel.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub

'Get the view position
Dim oPosition As Point2d = oView.Position
'Get the view size
Dim oSpace As Double = oView.Width
'Offset the position
oPosition.X = oPosition.X + oSpace
'Get the view scale
Dim oScale As Double = oView.Scale
'Set the orientation
'Dim DrawingView.ViewOrientationFromBase As oOrientation =  True  NOT WORKING

Dim oOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kRightViewOrientation


'Set the view style
Dim oViewStyle As DrawingViewStyleEnum = oView.ViewStyle

'Add the new view
oSheet.DrawingViews.AddBaseView(oModel, oPosition, oScale, oOrientation, oViewStyle, False)

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Accepted solutions (1)
732 Views
8 Replies
Replies (8)
Message 2 of 9

Owner2229
Advisor
Advisor

Hey, you can't add the view as projected, because you want one view fold and the other unfold.

BTW. This is the function to add the projected view:

oSheet.DrawingViews.AddProjectedView(ParentView As DrawingView, Position As Point2d, ViewStype As DrawingViewStyleEnum, Optional Scale As Object)

 

This will give you the orientation of the base view:

 

Dim oOrientation As ViewOrientationTypeEnum = oView.Camera.ViewOrientationType 

 

But since you want the view to be "turned right" as described in your original post, we have to create a translating function for that.

First put your code in "Sub Main()", like this:

 

Sub Main()
     'Your code
End Sub

Now the code:

Sub Main()
     'Your code
     '...
     'Get the base view orientation
     Dim oOrientation As ViewOrientationTypeEnum = oView.Camera.ViewOrientationType
     Dim NewOrientation As ViewOrientationTypeEnum = TurnRight(oOrientation)
     '... now use NewOrientation instead of oOrientation
End Sub

Private Function TurnRight(oOrientation As ViewOrientationTypeEnum) As ViewOrientationTypeEnum
     Dim NOR As ViewOrientationTypeEnum
     Select Case oOrientation
     Case ViewOrientationTypeEnum.kFrontViewOrientation:	NOR = ViewOrientationTypeEnum.kLeftViewOrientation
     Case ViewOrientationTypeEnum.kBackViewOrientation:		NOR = ViewOrientationTypeEnum.kRightViewOrientation
     Case ViewOrientationTypeEnum.kTopViewOrientation:		NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case ViewOrientationTypeEnum.kBottomViewOrientation:	NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kLeftViewOrientation:		NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kRightViewOrientation:	NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case Else: NOR = oOrientation
End Select Return NOR End Function

 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 9

machiel.veldkamp
Collaborator
Collaborator

Hey @Owner2229

 

 

Thanks for the tremendous help so far. 

 

I got this message: 

 

Error in rule: Flat Pattern View Placer, in document: DrawingName.dwg

Type komt niet overeen. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

I made this from your tips:

 

SyntaxEditor Code Snippet

Sub Main()
    'Get the active document
    Dim oDoc As Document = ThisApplication.ActiveDocument
    'Exit if the document isn't drawing
    If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
    
    'Get the correct sheet
    Dim oSheet As Sheet = oDoc.ActiveSheet
    
    'Exit if the sheet have no views
    If oSheet.DrawingViews.Count = 0 Then Exit Sub
    
    'Get the selection from user
    Dim oSelect As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick a view")
    
    'Exit if nothing is selected
    If oSelect Is Nothing Then Exit Sub
    
    'Get the view
    Dim oView As DrawingView = oSelect
    
    'Get the first document from the view
    Dim oModel As Document = oDoc.ReferencedDocuments.Item(1)
    
    'Exit if the referenced document isn't sheet metal
    If oModel.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub
    
    'Get the view position
    Dim oPosition As Point2d = oView.Position
    'Get the view size
    Dim oSpace As Double = oView.Width
    'Offset the position
    oPosition.X = oPosition.X + oSpace
    'Get the view scale
    Dim oScale As Double = oView.Scale
    
    'Set the view style
    Dim oViewStyle As DrawingViewStyleEnum = oView.ViewStyle
    
    'Set the orientation
    Dim oOrientation As ViewOrientationTypeEnum = oView.Camera.ViewOrientationType
    Dim NewOrientation As ViewOrientationTypeEnum = TurnRight(oOrientation)
  
        
    'Add the new view
    oSheet.DrawingViews.AddBaseView(oModel, oPosition, oScale, NewOrientation, oViewStyle)
End Sub

Private Function TurnRight(oOrientation As ViewOrientationTypeEnum) As ViewOrientationTypeEnum
     Dim NOR As ViewOrientationTypeEnum
     Select Case oOrientation
     Case ViewOrientationTypeEnum.kFrontViewOrientation:    NOR = ViewOrientationTypeEnum.kLeftViewOrientation
     Case ViewOrientationTypeEnum.kBackViewOrientation:        NOR = ViewOrientationTypeEnum.kRightViewOrientation
     Case ViewOrientationTypeEnum.kTopViewOrientation:        NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case ViewOrientationTypeEnum.kBottomViewOrientation:    NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kLeftViewOrientation:        NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kRightViewOrientation:    NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case Else: NOR = oOrientation
     End Select
     Return NOR
End Function

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 4 of 9

Owner2229
Advisor
Advisor

That's strange. I've just tested it and it worked on first go. You can try to debug it by writing a debug message every few rows. This way you'll find out how far did your code make it and what function is causing the issue. E.g.:

MsgBox("Passed: 1")
MsgBox("Passed: 2")

Let me know which it was and I'll look at it.

You can also post the second page of the error message, it would do as well.

 

Also if you want your views aligned, you can use this:

Dim oView2 As DrawingView = oSheet.DrawingViews.AddBaseView...
oView2.Align(oView, AlignmentTypeEnum.kHorizontalAlignment)
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 9

machiel.veldkamp
Collaborator
Collaborator

Yeah I did that and it stopped right before theSyntaxEditor Code Snippet

oSheet.DrawingViews.AddBaseView

So I tried it on a normal view (sheetmetal but folded) and that seemed to work.

 

Is it a mismatch between the selected view and the view it want's to place? 

 

 

 

2nd page! Never knew that! 

 

 

System.Runtime.InteropServices.COMException (0x80020005): Type komt niet overeen. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DrawingViews.AddBaseView(_Document Model, Point2d Position, Double Scale, ViewOrientationTypeEnum ViewOrientation, DrawingViewStyleEnum ViewStyle, String ModelViewName, Object ArbitraryCamera, Object AdditionalOptions)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 6 of 9

machiel.veldkamp
Collaborator
Collaborator

@Owner2229

 

I tried a few things and the orientation is the issue I think. 

 

If I make a new sheet and place 1 baseview with flat pattern it's okay at first but when I turn the flat pattern 90 degrees (a small change) the code breaks. 

 

 

 

________

 

I just found out that the orientation of the Flat pattern doesn't compare to the folded view. Front on the Flat Pattern is not Front in the Folded view. 

 

 

So........ I don't think It'll work! 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 7 of 9

Owner2229
Advisor
Advisor
Accepted solution

Ok, so I've finally managed to reproduce to issue. The problem is not with the unfolded view. It's that you have the view turned (when you double click the view, the text on the view cube is turned sideway). It changes the view type to "kArbitraryViewOrientation" and that's the issue. We'll have to use the camera here:

 

Sub Main()
    'Get the active document
    Dim oDoc As Document = ThisApplication.ActiveDocument
    'Exit if the document isn't drawing
    If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
    
    'Get the correct sheet
    Dim oSheet As Sheet = oDoc.ActiveSheet
    
    'Exit if the sheet have no views
    If oSheet.DrawingViews.Count = 0 Then Exit Sub
    
    'Get the selection from user
    Dim oSelect As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick a view")
    
    'Exit if nothing is selected
    If oSelect Is Nothing Then Exit Sub
    
    'Get the view
    Dim oView As DrawingView = oSelect
    
    'Get the first document from the view
    Dim oModel As Document = oDoc.ReferencedDocuments.Item(1)
    
    'Exit if the referenced document isn't sheet metal
    If oModel.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub
    
    'Get the view position
    Dim oPosition As Point2d = oView.Position
    'Get the view size
    Dim oSpace As Double = oView.Width
    'Offset the position
    oPosition.X = oPosition.X + oSpace
    'Get the view scale
    Dim oScale As Double = oView.Scale
    
    'Set the view style
    Dim oViewStyle As DrawingViewStyleEnum = oView.ViewStyle
    
    'Set the orientation
    Dim oOrientation As ViewOrientationTypeEnum = oView.Camera.ViewOrientationType
    Dim NewOrientation As ViewOrientationTypeEnum = TurnRight(oOrientation)
    
    'Add the new view
    Dim oView2 As DrawingView
    If NewOrientation = ViewOrientationTypeEnum.kArbitraryViewOrientation Then
        oView2 = oSheet.DrawingViews.AddBaseView(oModel, oPosition, oScale, NewOrientation, oViewStyle, , oView.Camera)
    Else
        oView2 = oSheet.DrawingViews.AddBaseView(oModel, oPosition, oScale, NewOrientation, oViewStyle)
    End If
End Sub

Private Function TurnRight(oOrientation As ViewOrientationTypeEnum) As ViewOrientationTypeEnum
     Dim NOR As ViewOrientationTypeEnum
     Select Case oOrientation
     Case ViewOrientationTypeEnum.kFrontViewOrientation:    NOR = ViewOrientationTypeEnum.kLeftViewOrientation
     Case ViewOrientationTypeEnum.kBackViewOrientation:     NOR = ViewOrientationTypeEnum.kRightViewOrientation
     Case ViewOrientationTypeEnum.kTopViewOrientation:      NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case ViewOrientationTypeEnum.kBottomViewOrientation:   NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kLeftViewOrientation:     NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kRightViewOrientation:    NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case Else: NOR = oOrientation
     End Select
     Return NOR
End Function

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 8 of 9

machiel.veldkamp
Collaborator
Collaborator

You know... I was about to give in. 

 

This is madness. How are you so good with iLogic? 

 

 

 

In any case. It works! Just one more (small) thing that I can probably fix myself:

 

in the case that a sheet has more than one parts (thus more baseviews) the selection isn't proper. (click on part 23 and part 12 (that's also on the drawing) gets placed.)

 

I'll figure out how later. For now, a huge thank you for this. Amazing!

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 9 of 9

machiel.veldkamp
Collaborator
Collaborator

The completed code up until now. Fixed the weird thing where it would grab the wrong view. 

 

SyntaxEditor Code Snippet

Dim oModel As Document = oSelect.ReferencedDocumentDescriptor.ReferencedDocument

The camera thing is still something but for now this is great. 

 

SyntaxEditor Code Snippet

Sub Main()
    'Get the active document
    Dim oDoc As Document = ThisApplication.ActiveDocument
    'Exit if the document isn't drawing
    If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
    
    'Get the correct sheet
    Dim oSheet As Sheet = oDoc.ActiveSheet
    
    'Exit if the sheet have no views
    If oSheet.DrawingViews.Count = 0 Then Exit Sub
    
    'Get the selection from user
    Dim oSelect As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Pick a view")
    
    'Exit if nothing is selected
    If oSelect Is Nothing Then Exit Sub
    
    'Get the view
    Dim oView As DrawingView = oSelect
    
    'Get the first document from the view
    Dim oModel As Document = oSelect.ReferencedDocumentDescriptor.ReferencedDocument
    
    'Exit if the referenced document isn't sheet metal
    If oModel.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Sub
    
    'Get the view position
    Dim oPosition As Point2d = oView.Position
    'Get the view size
    Dim oSpace As Double = oView.Width
    'Offset the position
    oPosition.X = oPosition.X + oSpace
    'Get the view scale
    Dim oScale As Double = oView.Scale
    
    'Set the view style
    Dim oViewStyle As DrawingViewStyleEnum = oView.ViewStyle
    
    'Set the orientation
    Dim oOrientation As ViewOrientationTypeEnum = oView.Camera.ViewOrientationType
    Dim NewOrientation As ViewOrientationTypeEnum = TurnRight(oOrientation)
    
    'Add the new view
    Dim oView2 As DrawingView
    If NewOrientation = ViewOrientationTypeEnum.kArbitraryViewOrientation Then
        oView2 = oSheet.DrawingViews.AddBaseView(oModel, oPosition, oScale, NewOrientation, oViewStyle, , oView.Camera)
    Else
        oView2 = oSheet.DrawingViews.AddBaseView(oModel, oPosition, oScale, NewOrientation, oViewStyle)
    End If
End Sub

Private Function TurnRight(oOrientation As ViewOrientationTypeEnum) As ViewOrientationTypeEnum
     Dim NOR As ViewOrientationTypeEnum
     Select Case oOrientation
     Case ViewOrientationTypeEnum.kFrontViewOrientation:    NOR = ViewOrientationTypeEnum.kLeftViewOrientation
     Case ViewOrientationTypeEnum.kBackViewOrientation:     NOR = ViewOrientationTypeEnum.kRightViewOrientation
     Case ViewOrientationTypeEnum.kTopViewOrientation:      NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case ViewOrientationTypeEnum.kBottomViewOrientation:   NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kLeftViewOrientation:     NOR = ViewOrientationTypeEnum.kBackViewOrientation
     Case ViewOrientationTypeEnum.kRightViewOrientation:    NOR = ViewOrientationTypeEnum.kFrontViewOrientation
     Case Else: NOR = oOrientation
     End Select
     Return NOR
End Function

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes