Create Arbitrary View for DrawingView

Create Arbitrary View for DrawingView

JamieVJohnson2
Collaborator Collaborator
624 Views
1 Reply
Message 1 of 2

Create Arbitrary View for DrawingView

JamieVJohnson2
Collaborator
Collaborator

I see there are a lot of unanswered posts for creating a custom view.  My problem sounds simple.  I have the view direction I want.  It is NOT a standard (front, left, right, top, bottom) direction.  I want to apply it to the document.  My failure is creating the camera object properly.  I have a target center, and a normal unit vector, but when my view is created I get a strange unusable (and massively large) view that tells me my camera is not correct.

 

How about some code:

  Dim sheet1 As Sheet = drawDoc.Sheets(1)
        Dim pViewPosition As Point2d = tg.CreatePoint2d(sheet1.Width * 2 / 5, sheet1.Height * 3 / 5)
        'choose base view rotation
        Dim viewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kArbitraryViewOrientation
Dim viewCamera As Camera = invApp.TransientObjects.CreateCamera() viewCamera.SceneObject = partDoc.ComponentDefinition viewCamera.ViewOrientationType = ViewOrientationTypeEnum.kFrontViewOrientation viewCamera.Target = FindMidPoint3D(partDoc.ComponentDefinition.RangeBox.MinPoint, partDoc.ComponentDefinition.RangeBox.MaxPoint) viewCamera.UpVector = sktNormal viewCamera.Apply()

Dim vBase As DrawingView = sht.DrawingViews.AddBaseView(docModel, pntView, dblScale, viewOrientation, viewStyle, strViewName, viewCamera, viewOptions)

 

I set to viewOrientation Notice there is not an 'eye' to the camera probably my problem, but I don't know what I should set it too.  I know the view will scale the document after I supply a scale, so can eye be target as well?  or should eye be target translated with up/normal vector to a point above the target?  This camera thing is difficult for me to process. Probably thinking too hard. Please help,

 

Thanks,

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Accepted solutions (1)
625 Views
1 Reply
Reply (1)
Message 2 of 2

JamieVJohnson2
Collaborator
Collaborator
Accepted solution

Solved my own problem...  Using the scientific method, I systematically turned off each option, and set one option at a time until I got what I wanted.  Turns out I got lucky pretty quickly this time.  So to create a camera of a view so that you can use it in a drawingview:

 

Get the normal of the view you want from a part component's planar sketch:

sktNormal = CType(skt, PlanarSketch).PlanarEntityGeometry.Normal

Create a camera object and populate its data and apply changes go camera:

 

Dim viewCamera As Camera = invApp.TransientObjects.CreateCamera()
        viewCamera.SceneObject = partDoc.ComponentDefinition
        viewCamera.Target = FindMidPoint3D(partDoc.ComponentDefinition.RangeBox.MinPoint, partDoc.ComponentDefinition.RangeBox.MaxPoint)
        Dim pEye As Point = viewCamera.Target
        pEye.TranslateBy(sktNormal.AsVector)
        viewCamera.Eye = pEye
        'viewCamera.UpVector = sktNormal
        viewCamera.Apply()

Use camera to create view and set view orientation to kAbritratry...:

 

Dim viewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kArbitraryViewOrientation

 Dim vBase As DrawingView = sht.DrawingViews.AddBaseView(docModel, pntView, dblScale, viewOrientation, viewStyle, strViewName, viewCamera, viewOptions)

Manipulate scale to get the object to a preferred size (bonus code for being such a great audience):

 

 'rotate the view if necessary to make long horizontal
        If vBase.Width < vBase.Height Then
            vBase.RotateByAngle(DegreesToRadians(90))
        End If
        'scale the view down if necessary to meet limits
        If vBase.Width > viewWidthLimitInches * 2.54 Then
            Dim modWidth As Double = vBase.Width / vBase.Scale / 2.54
            For i As Integer = scales.Count - 1 To 0 Step -1
                Dim strSplit() As String = scales(i).Split("=")
                Dim top As Double = FeetInchToDecimalInch(strSplit(0))
                Dim bot As Double = FeetInchToDecimalInch(strSplit(1))
                If top / bot * modWidth < viewWidthLimitInches Then
                    strScale = scales(i)
                    Exit For
                End If
            Next
        End If

Fyi, our industry things in inches while Inventor thinks in centimeters hence the 2.54 everywhere.  In addition FindMidPoint3D, DegreesToRadians, and FeetInchToDecimalInch are custom functions I created.

 

 

Thank you, and come again.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes