Design View Representations

Design View Representations

navbor
Enthusiast Enthusiast
1,842 Views
14 Replies
Message 1 of 15

Design View Representations

navbor
Enthusiast
Enthusiast

I am busy writing some VBA code to copy the viewing eye, target and upvector from one design view rep to several others. My code is not working and I do not understand why not. Any ideas / suggestions please.

 

Private Sub ProcessViews(frmViewCameraCopy As frm_ViewCameraCopy)
Dim oView As Inventor.DesignViewRepresentation
Dim activeViewName As String

Dim oBaseView As Inventor.DesignViewRepresentation
Dim oColTargetViews As New Collection

Dim oCompDef As ComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
For Each oView In _
oCompDef.RepresentationsManager.DesignViewRepresentations
If oView.Name = frmViewCameraCopy.BaseViewName Then
Set oBaseView = oView
End If
For Each Item In frmViewCameraCopy.ViewsToProcess
If Item = oView.Name Then
oColTargetViews.Add oView
End If
Next
Next
activeViewName = oCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

Dim waslocked As Boolean
Set oActiveView = ThisApplication.ActiveView
For Each oView In oColTargetViews
If oView.Locked Then
waslocked = True
oView.Locked = False
Else
waslocked = False
End If
oView.Activate
oView.Camera.Target = oBaseView.Camera.Target
oView.Camera.Eye = oBaseView.Camera.Eye
oView.Camera.UpVector = oBaseView.Camera.UpVector
oView.Camera.Apply
oView.Locked = waslocked
Next

oCompDef.RepresentationsManager.DesignViewRepresentations.Item(activeViewName).Activate


End Sub

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
1,843 Views
14 Replies
Replies (14)
Message 2 of 15

MechMachineMan
Advisor
Advisor

You need to actually assign the camera object to a variable.

 

Every new call to the camera object grabs a new variable, and would thus likely be why you are seeing issues.

 

Good luck.

 


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

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 15

navbor
Enthusiast
Enthusiast

Hello Justin,

 

Thanks for your feedback.

 

I tried that but it makes not difference. It still runs through each view rep and I can see the camera properties change in the watch window as I step through the code, but the view is not updating in the graphics window.

 

At the line "oView.Activate" the graphic window changes to the correct view, but, at the line "oCamera.Apply" the viewing eye, target and upvector do not appear to be changing in the graphics window. The view remains in exactly the same as it was before, and then the code steps on to the next design view representation in the collection.

 

Private Sub ProcessViews(frmViewCameraCopy As frm_ViewCameraCopy)
Dim oView As Inventor.DesignViewRepresentation
Dim activeViewName As String
Dim oCamera As Inventor.Camera

Dim oBaseView As Inventor.DesignViewRepresentation
Dim oColTargetViews As New Collection

Dim oCompDef As ComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
For Each oView In _
oCompDef.RepresentationsManager.DesignViewRepresentations
If oView.Name = frmViewCameraCopy.BaseViewName Then
Set oBaseView = oView
End If
For Each Item In frmViewCameraCopy.ViewsToProcess
If Item = oView.Name Then
oColTargetViews.Add oView
End If
Next
Next
activeViewName = oCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

Dim waslocked As Boolean
Set oActiveView = ThisApplication.ActiveView
For Each oView In oColTargetViews
If oView.Locked Then
waslocked = True
oView.Locked = False
Else
waslocked = False
End If
oView.Activate
Set oCamera = oView.Camera

oCamera.Target = oBaseView.Camera.Target
oCamera.Eye = oBaseView.Camera.Eye
oCamera.UpVector = oBaseView.Camera.UpVector
oCamera.Apply

'oView.Camera.Target = oBaseView.Camera.Target
'oView.Camera.Eye = oBaseView.Camera.Eye
'oView.Camera.UpVector = oBaseView.Camera.UpVector
'oView.Camera.Apply

oView.Locked = waslocked
Next

oCompDef.RepresentationsManager.DesignViewRepresentations.Item(activeViewName).Activate


End Sub

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
Message 4 of 15

MechMachineMan
Advisor
Advisor

Hmmm. Yeah I've tried a couple things as well and can't get it to work either.


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

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @navbor,

 

Try the following VBA code

 

Set oCamera = oView.Camera

oCamera.Target = oBaseView.Camera.Target.Copy
oCamera.Eye = oBaseView.Camera.Eye.Copy oCamera.UpVector = oBaseView.Camera.UpVector.Copy Call oCamera.ApplyWithoutTransition

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 15

navbor
Enthusiast
Enthusiast

Hello Chandra,

 

Thanks very much for the advice, but the results are the same as before.

 

I will try to explain as best I can.

 

I have 10 design view representations in an assembly (iam file). I activate each design view rep, and orientate the view randomly, and zoom in / out to various heights so that each of the 10 views appears different. There will be certain items visible / not visible, and certain items colored differently between the views also.

 

I run my VBA macro. (screen shots attached). After I run the macro, I want all the views that I selected as target views to look exactly like the base view, but I only want the view orientation (upvector), zoom height(camera.eye) and view (camera.target) to be the same as the base view. In other words and colors or part visibility settings must be maintained and not copied from the base view. This is very handy for screen capturing for presentation purposes when you want to represent different parts in the assembly in a specific sequence.

 

Right now the code does not do this (even with the changes you suggested). If you have any other suggestions, i would be happy to try them.

 

 

Private Sub ProcessViews(frmViewCameraCopy As frm_ViewCameraCopy)
Dim oView As Inventor.DesignViewRepresentation
Dim activeViewName As String
Dim oCamera As Inventor.Camera
Dim oBaseView As Inventor.DesignViewRepresentation
Dim oColTargetViews As New Collection
Dim oCompDef As ComponentDefinition
Dim width, height As Double
Dim waslocked As Boolean
Dim viewInfo As String
Dim cameraHeight As Double
Dim cameraWidth As Double
Dim oTG As Inventor.TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim upVector As Inventor.UnitVector
Dim cameraPosition As Inventor.Point
Dim targetPosition As Inventor.Point

Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition

For Each oView In _
oCompDef.RepresentationsManager.DesignViewRepresentations
If oView.Name = frmViewCameraCopy.BaseViewName Then
Set oBaseView = oView
End If
For Each Item In frmViewCameraCopy.ViewsToProcess
If Item = oView.Name Then
oColTargetViews.Add oView
End If
Next
Next

cameraHeight = GetCameraHeight(oBaseView.DesignViewInfo)
cameraWidth = GetCameraWidth(oBaseView.DesignViewInfo)
Set upVector = oTG.CreateUnitVector(GetUpVectorX(oBaseView.DesignViewInfo), GetUpVectorY(oBaseView.DesignViewInfo), GetUpVectorZ(oBaseView.DesignViewInfo))
Set cameraPosition = oTG.CreatePoint(GetCameraPointX(oBaseView.DesignViewInfo), GetCameraPointY(oBaseView.DesignViewInfo), GetCameraPointZ(oBaseView.DesignViewInfo))
Set targetPosition = oTG.CreatePoint(GetTargetPointX(oBaseView.DesignViewInfo), GetTargetPointY(oBaseView.DesignViewInfo), GetTargetPointZ(oBaseView.DesignViewInfo))

activeViewName = oCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

Set oActiveView = ThisApplication.ActiveView

For Each oView In oColTargetViews
ThisApplication.ActiveView.Fit
If oView.Locked Then
waslocked = True
oView.Locked = False
Else
waslocked = False
End If
oView.Activate
'Debug.Print oView.DesignViewInfo
Set oCamera = ThisApplication.ActiveView.Camera

oCamera.Target = oBaseView.Camera.Target.Copy
oCamera.Eye = oBaseView.Camera.Eye.Copy
oCamera.upVector = oBaseView.Camera.upVector.Copy


oCamera.Apply

Application.Wait Now + #12:00:02 AM#


oView.Locked = waslocked
Next
End Sub

 

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
Message 7 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @navbor,

 

Try the following VBA code to copy one design view to another design view.

 

Sub Main()
    
    Dim oDef As ComponentDefinition
    Set oDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim copyDesign As DesignViewRepresentation
    Dim oView As DesignViewRepresentation
    Dim eye, target As Point
    Dim upVector As UnitVector

    Set copyDesign = oDef.RepresentationsManager.DesignViewRepresentations.Item("BaseView") ' View1
    Call copyDesign.Activate

    Dim currentView As View
    Set currentView = ThisApplication.ActiveView

    Dim currentCamera As Camera
    Set currentCamera = currentView.Camera

    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    Set eye = tg.CreatePoint(currentCamera.eye.X, currentCamera.eye.Y, currentCamera.eye.Z)
    Set target = tg.CreatePoint(currentCamera.target.X, currentCamera.target.Y, currentCamera.target.Z)
    Set upVector = tg.CreateUnitVector(currentCamera.upVector.X, currentCamera.upVector.Y, currentCamera.upVector.Z)

    Set oView = oDef.RepresentationsManager.DesignViewRepresentations.Item("TargetView") ' View 3
    Call oView.Activate

    Dim docCamera As Camera
    Dim docView As View
    Set docView = ThisApplication.ActiveView

    Set docCamera = docView.Camera

    docCamera.eye = eye
    docCamera.upVector = upVector
    docCamera.target = target

    'Call docCamera.Fit

    Call docCamera.Apply

    Call docView.Update
    
    oView.AutoSaveCamera = True
    
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 15

navbor
Enthusiast
Enthusiast

Hell Chandra,

 

I tried this code, but the results are the same.

 

If you have any other suggestions I would be very happy to try them.

 

Please see attached.

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
Message 9 of 15

MechMachineMan
Advisor
Advisor

At this point, I'm almost thinking it's a bug with the DVR camera; would be worth some extra testing.


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

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @navbor,

 

 

I did some modifications to the code. try the following VBA code.

 

Sub Main()
    
    Dim oDef As ComponentDefinition
    Set oDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim copyDesign As DesignViewRepresentation
    Dim oView As DesignViewRepresentation
    Dim eye, target As Point
    Dim upVector As UnitVector

    Set copyDesign = oDef.RepresentationsManager.DesignViewRepresentations.Item("Bottom")
    Call copyDesign.Activate

    Dim currentView As View
    Set currentView = ThisApplication.ActiveView

    Dim currentCamera As Camera
    Set currentCamera = currentView.Camera

    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    Set eye = tg.CreatePoint(currentCamera.eye.X, currentCamera.eye.Y, currentCamera.eye.Z)
    Set target = tg.CreatePoint(currentCamera.target.X, currentCamera.target.Y, currentCamera.target.Z)
    Set upVector = tg.CreateUnitVector(currentCamera.upVector.X, currentCamera.upVector.Y, currentCamera.upVector.Z)
    
    Dim width As Double
    Dim height As Double
    Call currentCamera.GetExtents(width, height)
    Call currentCamera.Fit
    
    Dim widthfit As Double
    Dim heightfit As Double
    Call currentCamera.GetExtents(widthfit, heightfit)

    Call currentCamera.SetExtents(width, height)
    
    Dim widthratio As Double
    Dim heightratio As Double

    widthratio = width / widthfit
    heightratio = height / heightfit

    Set oView = oDef.RepresentationsManager.DesignViewRepresentations.Item("Left")
    Call oView.Activate

    Dim docCamera As Camera
    Dim docView As View
    Set docView = ThisApplication.ActiveView

    Set docCamera = docView.Camera

    docCamera.eye = eye
    docCamera.upVector = upVector
    docCamera.target = target

    Call docCamera.Fit
    
    Dim Docwidth As Double
    Dim Docheight As Double
    Call docCamera.GetExtents(Docwidth, Docheight)
    Call docCamera.SetExtents(Docwidth * widthratio, Docheight * heightratio)

    Call docCamera.Apply

    Call docView.Update
    
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo"

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 15

navbor
Enthusiast
Enthusiast

Hello Chandra,

 

Firstly, thanks very much for all your efforts trying to help with resolving this. I really appreciate it.

 

Sadly however, even the latest code listed above does not improve the situation.

 

The result is very much like the result from the previous test and that is; the view is correctly orientated, but not in the correct (i.e. identical position on screen).

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
Message 12 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @navbor,

 

Try the following VBA code.

 

Sub Main()
    
    Dim oDef As ComponentDefinition
    Set oDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim baseView As DesignViewRepresentation
    Dim targetView As DesignViewRepresentation

    Set copyDesign = oDef.RepresentationsManager.DesignViewRepresentations.Item("Bottom") ' View1

    Set oView = oDef.RepresentationsManager.DesignViewRepresentations.Item("Left") ' View 3
    
    Call CopyDesignView(copyDesign, oView)
    
End Sub

Sub CopyDesignView(ByVal baseView As DesignViewRepresentation, ByVal targetView As DesignViewRepresentation)

    Dim targetViewName As String
    targetViewName = targetView.Name
    
    Call targetView.Delete
    
    Call baseView.Copy(targetViewName)

End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 15

navbor
Enthusiast
Enthusiast

Hello Chandra,

 

This works, but sadly it is not a solution that will work for me. I have certain components in the target view that are colored differently, and in some cases hidden or transparent. Using the delete and copy (latest) method causes me to lose all the color and visibility settings.

 

To me this looks like a bug, or perhaps a limitation with VBA.

 

Thanks very much for all your help.

Regards
Rob
-------------------------------------------
Windows 7 Pro (X64)
Intel(R) core (TM) i5-4690 CPU @ 3.50GHz
32.0 GB RAM
Nvidia Quadro K2000
Autodesk Inventor 2015 Professional Ultimate Design Suite
0 Likes
Message 14 of 15

MechMachineMan
Advisor
Advisor

This topic has been escalated, so hopefully the software team will be able to look at it and correct it if it is indeed a bug. For now, sadly, I think you will have to make do with a workaround.


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

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 15 of 15

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @navbor,

 

I did some more modifications to the code. Try the following VBA code.

 

Sub Main()
    
    Dim oDef As ComponentDefinition
    Set oDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim copyDesign As DesignViewRepresentation
    Dim oView As DesignViewRepresentation
    Dim Eye As Point, Target As Point
    Dim UpVector As UnitVector

    Set copyDesign = oDef.RepresentationsManager.DesignViewRepresentations.Item("Bottom")
    Call copyDesign.Activate
    
    Dim currentView As View
    Set currentView = ThisApplication.ActiveView

    Dim currentCamera As camera
    Set currentCamera = currentView.camera
    
    Set Eye = currentCamera.Eye
    Set Target = currentCamera.Target
    Set UpVector = currentCamera.UpVector
    
    Dim Width As Double
    Dim Height As Double
    Call currentCamera.GetExtents(Width, Height)

    Set oView = oDef.RepresentationsManager.DesignViewRepresentations.Item("Left")
    Call oView.Activate

    Dim docCamera As camera
    Dim docView As View
    Set docView = ThisApplication.ActiveView

    Set docCamera = docView.camera
    SetCameraData docCamera, Eye, Target, UpVector, Width, Height
    SetCameraData docCamera, Eye, Target, UpVector, Width, Height

    ' save the camera for the design view
    oView.SaveCurrentCamera
    Call docView.Update

End Sub

Sub SetCameraData(oCamera As camera, oEye As Point, oTarget As Point, oUpVector As UnitVector, dWidth As Double, dHeight As Double)
    
oCamera.UpVector = oUpVector oCamera.Eye = oEye oCamera.Target = oTarget oCamera.SetExtents dWidth, dHeight oCamera.Apply
End Sub

In the above code, "SetCameraData" function is used to twice. Because, if it called once. Still there is a bit tolerance between Design View Representations.

 

It is observed in the result of previous VBA code.

 

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes