iLogic, make specific view, Set Current View as Home, Fit to View?

iLogic, make specific view, Set Current View as Home, Fit to View?

engilic
Advocate Advocate
4,954 Views
14 Replies
Message 1 of 15

iLogic, make specific view, Set Current View as Home, Fit to View?

engilic
Advocate
Advocate

Hi,

 

Simple for exerts, how to make this view, like pressing on the corner of a cube, Top-Front-Right

Screenshot 2021-04-23 130909.png

 

 

 

 

and then Set Current View as Home, Fit to View?

Screenshot 2021-04-23 131039.png

 

 

 

 

 

 

 

 

 

without any prompts, silent.

 

Thank you.

0 Likes
Accepted solutions (4)
4,955 Views
14 Replies
Replies (14)
Message 2 of 15

J-Camper
Advisor
Advisor
Accepted solution

I think this should give you what you need:

Dim cam As Camera = ThisApplication.ActiveView.Camera
cam.ViewOrientationType = ViewOrientationTypeEnum.kFrontViewOrientation
cam.ApplyWithoutTransition 'Apply Front View
cam.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
cam.ApplyWithoutTransition 'Apply IsoTopRight View
cam.Fit
cam.ApplyWithoutTransition 'Apply View Extents
cam.Parent.SetCurrentAsHome 'Set New Hom View

 

Let me know if you have any questions, or if this is not working as intended.

Message 3 of 15

engilic
Advocate
Advocate

This is great and so quick, thank you @J-Camper .

I forgot to ask is it possible to say View XY, XY plane, looking from the top of Z-axis is new Home and similar to that, View XZ, XZ plane, looking from the top of Y-axis is new Top view?

That would be awesome.

 

Screenshot 2021-04-23 161025.png

0 Likes
Message 4 of 15

J-Camper
Advisor
Advisor
Accepted solution

 Here is code to set the Home to the Front view:

Dim cam As Camera = ThisApplication.ActiveView.Camera

'Set new home to Front
cam.ViewOrientationType = ViewOrientationTypeEnum.kFrontViewOrientation
cam.ApplyWithoutTransition 'Apply Front View
cam.Parent.SetCurrentAsHome 'Set New Hom View

 

I'm a little confused by the second part of your request.  "View XZ, XZ plane, looking from the top of Y-axis is new Top view" is the default Top view.  Do you have parts where the Top/Front views has been changed from the default settings?

 

This should reset you View Cube to default settings [does not overwrite Home]:

Dim cam As Camera = ThisApplication.ActiveView.Camera

'Reset View cube to Default
cam.Parent.ResetFront

 

Let me know if I'm not understanding your request properly, or if you have any questions

 

Message 5 of 15

engilic
Advocate
Advocate

Thank you @J-Camper ,

 

I cannot access Inventor during the weekend so cannot do anything now.

 

I think I can do what I wanted using your help and codes.

First to reset to default, then to go to the view I want to be Front (XY), make it default Front View, go to the view I want to be Top (XZ), make it default Top View, go to Isometric view, Fit the view,  make it Home (default).

 

Thank you very much.

Will try it soon.

0 Likes
Message 6 of 15

J-Camper
Advisor
Advisor

@engilic,

 

Basically yes, but setting both the Front and Top Views is redundant.  You can't break the view cube, so the Front & Top faces always share the same edge.  When you move one, the other moves with it.

 

Reset, Set Front, Set Iso, Fit, and Set As Home

Message 7 of 15

engilic
Advocate
Advocate

Thank you @J-Camper.

 

As I said no Inventor right now so cannot check.

Will check it asap.

 

One more questions for you regarding making post a solution, maybe it is not a question for you.

 

Not sure how that works, do the person whose post is marked as a solution get any credit, points, or some kind of a reward?

 

I am asking that because I am not sure should I mark a post as a solution since many times someone answer gives a code that is very close to what I want, I change it a little bit and post it at the end.

 

Should I mark both posts as a solutions, also should all other posts that helped me to make the full code for the solution be marked or just the last code, usually mine since I know what I wanted to achieve and I adjust the code?

 

If they get some kind of reward I do not want to take it from them, they deserved it since they helped me.

0 Likes
Message 8 of 15

J-Camper
Advisor
Advisor

@engilic,

 

I believe Solutions are a factor in community ranks, for the person posting the solution, but more importantly the marked solution helps other users that search for answers to their own questions on the forum.

 

I would say the most important solution to mark would be one that answers the title of the post.  With that being said, solutions don't always come in a single reply which is why you have the ability to mark multiple replys as solution if necessary.

 

Some posts have a very specific question regarding code that is doing a particular task but isn't functioning properly.  Those solutions are usually very clear to mark, since they likely have the OP's end goal incorporated in the question. 

 

Other times it's just a concept that is asked, and a "solution" to that concept might not be all that is needed to solve the OP's end goals.  Those solutions are more ambiguous, since the OP is interested in their end goal but a separate user down the line might be looking for the solution the concept in the Post title.

 

In the end I would focus on marking solutions to the original forum post topic, as this is what will help someone using the forum's search feature find "Solved" posts on their search topic.

Message 9 of 15

engilic
Advocate
Advocate

Thank you @J-Camper .

 

I intend to mark both final code and the post that helped me to get there as solutions.

 

Will continue with it.

0 Likes
Message 10 of 15

engilic
Advocate
Advocate

Hi @J-Camper ,

 

I need more of your help if you can.

 

I want to:

1. reset (cam.Parent.Reset Front) - ok, you already showed me that

2. go to top view orientation (cam.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation) -ok

3. now rotate the camera 180 degrees - here I need help

4. apply (cam.Apply) - ok

5. then go to iso and make it home - ok

 

Try to find the code for it but unsuccessful.
Just need the code to rotate the camera 180 deg.

 

Thank you

0 Likes
Message 11 of 15

J-Camper
Advisor
Advisor
Accepted solution

@engilic,

 

In order to rotate the view 180°, you should just need to invert the camera's UpVector:

Dim cam As Camera = ThisApplication.ActiveView.Camera

Dim camUp As UnitVector = cam.UpVector
camUp.X = -camUp.X
camUp.Y = -camUp.Y
camUp.Z = -camUp.Z
cam.UpVector = camUp

cam.ApplyWithoutTransition

 

Let me know if you have any questions, or if this is not working as intended

 

Message 12 of 15

engilic
Advocate
Advocate

Thank you @J-Camper ,

Your code helped me a lot.

Actually, I wanted whenever you press the Home button to have XYZ like in the picture.
Maybe I did not explain it properly in my 1st post. Excuse me for that.

Screenshot 2021-04-27 180535.png

 

 

 

 

 

Here is the code I made, whit 99% of your help.
It does exactly what I wanted, every time, just do not understand why x, y, x of Vector need to be 0, 1, 1.
I would expect 1, 1, 1 but no, that doesn't work, so I played with numbers and found what works.

 

Would like to understand why but I guess you and everyone else don't have time to explain.



Dim cam As Camera = ThisApplication.ActiveView.Camera
Dim camUp As UnitVector = cam.UpVector

cam.Parent.ResetFront 'Reset Front View
cam.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation 'Top View
cam.ApplyWithoutTransition 'Apply Top View
camUp.X = 0 'Up Vector X
camUp.Y = 1 'Up Vector Y
camUp.Z = 1 'Up Vector Z
cam.UpVector = camUp 'Up Vector
cam.ApplyWithoutTransition 'Apply Up Vector
cam.Parent.SetCurrentAsFront 'Current as Front
cam.ApplyWithoutTransition 'Apply Current as Front
cam.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation 'IsoTopRight View
cam.ApplyWithoutTransition 'Apply IsoTopRight View
cam.Fit 'View Extents
cam.Apply 'Apply View Extents
cam.Parent.SetCurrentAsHome 'Set New Home View 

 

Message 13 of 15

engilic
Advocate
Advocate

I think I understood what is what.

It seems that UpVector defines the position of the top of the model.

Once more final code.

 

Dim cam As Camera = ThisApplication.ActiveView.Camera
Dim camUp As UnitVector = cam.UpVector

cam.Parent.ResetFront 'Reset Front View
cam.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation 'Top View
cam.ApplyWithoutTransition 'Apply Top View
camUp.X = 0 'Up Vector of Current Top View X
camUp.Y = 1 'Up Vector of Current Top View  Y
camUp.Z = 0 'Up Vector of Current Top View  Z
cam.UpVector = camUp 'Up Vector
cam.ApplyWithoutTransition 'Apply Up Vector
cam.Parent.SetCurrentAsFront 'Current as Front
cam.ApplyWithoutTransition 'Apply Current as Front
cam.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation 'IsoTopRight View
cam.ApplyWithoutTransition 'Apply IsoTopRight View
cam.Fit 'View Extents
'cam.Apply 'Apply View Extents
cam.ApplyWithoutTransition 'Apply View Extents Without Transition
cam.Parent.SetCurrentAsHome 'Set New Home View

 

0 Likes
Message 14 of 15

engilic
Advocate
Advocate

Not that simple.

Finally understood.

 

Need to set Camera Eye, Camera Target, Camera UpVector.

 

Will post the code soon.

0 Likes
Message 15 of 15

engilic
Advocate
Advocate
Accepted solution

The code

 

Dim oView As View = ThisApplication.ActiveView
Dim oCam As Camera = oView.Camera
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oEye As Inventor.Point
Dim oTarget As Inventor.Point
Dim oUpVector As UnitVector

'RESET VIEW
oView.ResetFront 'oCam.Parent.ResetFront

'DEFINE TOP
oEye = oTG.CreatePoint(0, 1, 0)
oCam.Eye = oEye
oTarget = oTG.CreatePoint(0, 0, 0)
oCam.Target = oTarget
oUpVector = oTG.CreateUnitVector(0, 0, 1)
oCam.UpVector = oUpVector
oCam.ApplyWithoutTransition
oView.SetCurrentAsTop

'DEFINE HOME
oEye = oTG.CreatePoint(1, 1, 1)
oCam.Eye = oEye
oTarget = oTG.CreatePoint(0, 0, 0)
oCam.Target = oTarget
oUpVector = oTG.CreateUnitVector(0, 1, 0)
oCam.UpVector = oUpVector
oCam.ApplyWithoutTransition
oCam.Fit 'probably not needed since SetCurrentAsHome(True), View.SetCurrentAsHome( [FitToView] As Boolean )
oCam.ApplyWithoutTransition
oView.SetCurrentAsHome(True)

 

0 Likes