×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

#### Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
To Your Posts
• Keyword Search
• One-Click Access To Your
Favorite Forums
• Automated Signatures
On Your Posts
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

# Macro to create a viewpoint

 Forum Search FAQs Links MVPs

## Macro to create a viewpoint

(OP)
Hello everyone

I have to create a macro that will allow the user to create an specific viewpoint of the main assembly so the user can take an screenshot ( the screenshot is use to update our assembly handbook).
I have analyzed the DMUInfEngineeringView file and with that I have created my own code.
Language="VBSCRIPT"

Sub CATMain()

Dim ProjectionM
Dim FocusD
FocusD = 837.729

' Get the viewer
Set oViewer = CATIA.ActiveWindow.ActiveViewer

' Get the viewpoint
Set oViewpoint = oViewer.Viewpoint3D

Dim origin(2)
Dim sight(2)
Dim up(2)

M = 2568.767
N = -301.194
P = 323.169

X = 0.972
Y = 0.130
Z = 0.195

U = -0.200
V = 2.627
W = 0.979

' Change the viewpoint

oViewpoint.PutUpDirection Array(U, V, W)
oViewpoint.PutOrigin Array(M, N, P)
oViewpoint.PutSightDirection Array(X, Y, Z)

oViewpoint.ProjectionMode = catProjectionCylindric
ProjectionM = oViewpoint.ProjectionMode
MsgBox ProjectionM

oViewpoint.FocusDistance = FocusD

' Update the viewer
oViewer.Update

oViewpoint.GetOrigin origin
oViewpoint.GetSightDirection sight
oViewpoint.GetUpDirection up

For i = 0 to 2
MsgBox origin(i)
Next

For i = 0 to 2
MsgBox sight(i)
Next

For i = 0 to 2
MsgBox up(i)
Next

Set oViewpoint = Nothing
Set oViewer = Nothing

End Sub

However my problem is that instead of getting the viewpoint that I need I always get a rotated version of my desired viewpoint.

Example:

This is the viewpoint that I need, I already know the coordinates for the origin, the sight direction, the up direction and the focus distance (I use another macro to get this data)

This is the viewpoint that I get, as you can see the viewpoint is slightly rotated.

Currently the code is in CATscript but the final version will be in VBA.

I would really appreciate any help you can give me.
Thanks in advance for your support.

Alex

### RE: Macro to create a viewpoint

Hi.

Have you tried your approach on another assembly? What CATIA version do you use?

### RE: Macro to create a viewpoint

(OP)
Hello Little Cthulhu

Thank you for taking the time to answer my post.

Yes I have tried in another assemblies but I still get a different version from my objective viewpoint.
Right now I am using CATIA Version 5-6 Release 2018 Service Pack 3

### RE: Macro to create a viewpoint

Are you sure about the way you retrieve your hard-coded values?

I can't reproduce it in R25. I ran script below up to breakpoint, moved sight and then continued execution.
Viewpoint returned back to initial position as expected.

#### CODE

Option Explicit

Sub CATMain()
Dim v3d As Viewer3D: Set v3d = CATIA.ActiveWindow.ActiveViewer
Dim vp: Set vp = v3d.Viewpoint3D

Dim fd: fd = vp.FocusDistance
Dim origin(2), sight(2), up(2)
vp.GetOrigin origin
vp.GetSightDirection sight
vp.GetUpDirection up
Dim zm: zm = vp.Zoom

' BREAKPOINT HERE
vp.FocusDistance = fd
vp.PutUpDirection up
vp.PutSightDirection sight
vp.PutOrigin origin
vp.Zoom = zm
v3d.Update
End Sub 

### RE: Macro to create a viewpoint

(OP)
Hello everyone

My apologies for taking so long to answer but because of COViD-19 we weren't allowed to go to the office and so I was unable to work on this macro.
Nevertheless I am finally back and I have manage to correct my macro.

Unfortunately I don't know the reason but every time I run the macro the UP Direction vector changes , so my solution was ( probably not the best solution but it works) to modify a second time the UPDirection to correct the viewpoint.

The main part of the code related to the viewpoints is like this:

Option Explicit

Sub CATMain()
Dim v3d As Viewer3D: Set v3d = CATIA.ActiveWindow.ActiveViewer
Dim vp: Set vp = v3d.Viewpoint3D

Dim fd: fd = vp.FocusDistance
Dim origin(2), sight(2), up(2)
vp.GetOrigin origin
vp.GetSightDirection sight
vp.GetUpDirection up
Dim zm: zm = vp.Zoom

' BREAKPOINT HERE
vp.FocusDistance = fd
vp.PutUpDirection up
vp.PutSightDirection sight
vp.PutOrigin origin
vp.Zoom = zm

'In this part I modify for a second time the up direction to correct the viewpoint.
vp.PutUpDirection up

v3d.Update
End Sub

thank you for your support and once again my apologies for letting this thread open for so long.

Alex

### RE: Macro to create a viewpoint

Giving you a star for giving us a feedback despite the circumstances!

### RE: Macro to create a viewpoint

(OP)
Thank you for the star.
The main idea of this macro was to create a matrix of viewpoints in excel to make it easier to update the assembly handbook that we deliver to our client.

So, if anybody is in need of something similar I will be happy to share my code with you.
Please let me know if you need a sample of the code.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

### Reply To This Thread

#### Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login

#### Resources

eBook - The Future of Product Development is Here
Looking to make the design and manufacturing of your products more agile? For engineering and manufacturing organizations, the need for digital transformation of product development processes just became more urgent than ever so we wanted to share an eBook that will help you build a practical roadmap for your journey. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.