Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

View Cube Buttons, Access Through API

11 REPLIES 11
Reply
Message 1 of 12
stuartmp74
732 Views, 11 Replies

View Cube Buttons, Access Through API

Hi All

Is it possible to access the View Cube buttons through the API.

I would like to map them on to a macro run by my space explorer.
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: stuartmp74


Sorry, but the view cube is not currently
accessible through the API.
--
Brian Ekins
Autodesk Inventor API

href="http://blogs.autodesk.com/modthemachine">http://blogs.autodesk.com/modthemachine


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi
All Is it possible to access the View Cube buttons through the API. I would
like to map them on to a macro run by my space
explorer.
Message 3 of 12
stuartmp74
in reply to: stuartmp74

Hi Brian this is my code

Please try running the Function 'Positive90'

I am having Rotate the Model about the horizontal Axis.

I have no trouble with rotating the model about the up vector (vertical axis) which is the 'Positive90' function less the 'RotateMatrix90' sub.

But I can't seam to Rotate the Matrix to a position normal to the up vector so I can Rotate the Model about the horizontal Axis

Could you help me out on this one. I have actually be tiring on and off for years to do it but I just can't seem to get my head

around how the matrix translation works.

I am drawing a circle just as a reference until I perfect the code

I really work appreciate you time on this one.

As I said before. I would like to map them these functions onto run by my space Explorer




Option Explicit


'LoadBaseValues
Dim oApp As Inventor.Application
Dim oDoc As Document
Dim oView As View
Dim oCompDef As ComponentDefinition
Dim oClientGraphics As ClientGraphics
Dim oTransGeom As TransientGeometry
Dim MyCamera As Camera
Dim oCurvesNode As GraphicsNode
Dim oCenter As Point
Dim oNormal As UnitVector
Dim oTransformMatrix As Matrix
'LoadBaseValues

'DrawCircle
Dim oCircle As Inventor.Circle
Dim oCircleGraphics As CurveGraphics
'DrawCircle

'RotateCameraAbout
Dim oCurveEval As CurveEvaluator
Dim dPi As Double
Dim dIncrement As Double
Dim dCurrent As Double
Dim adEye(2) As Double
Dim adGuessparams() As Double
Dim adMaxDeviations() As Double
Dim adParams(0) As Double
Dim aenSolTypes() As SolutionNatureEnum
Dim adPoint(2) As Double
Dim oNewEye As Point
'RotateCameraAbout



Public Function Positive90()

LoadBaseValues
RotateMatrix90
DrawCircle
RotateCameraAbout -90
DeleteCircle


End Function

Public Function Negitive90()

LoadBaseValues
RotateMatrix90
DrawCircle
RotateCameraAbout 90
DeleteCircle

End Function

Sub LoadBaseValues()

Set oApp = ThisApplication
Set oDoc = oApp.ActiveDocument
Set oView = oApp.ActiveView


' Set a reference to component definition of the active document.
' This assumes that a part or assembly document is active.
Set oCompDef = oDoc.ComponentDefinition


' Check to see if the test graphics data object already exists.
' If it does clean up by removing all associated of the client graphics
' from the document. If it doesn't create it.
On Error Resume Next
Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID")
If Err.Number = 0 Then
On Error GoTo 0
' An existing client graphics object was successfully obtained so clean up.
oClientGraphics.Delete

' update the display to see the results.
oView.Update
GoTo Continue:
Else
Continue:
Err.Clear
On Error GoTo 0

' Set a reference to the transient geometry object for user later.
Set oTransGeom = oApp.TransientGeometry

'The Camera is analogous to a real-world camera.
'You can define its position in space, the direction in which it is pointed and how it is tipped.
'You can also control the type of lens by setting the perspective angle.'
'Each time the Camera property of the View is used a new Camera object is returned.'
'The Camera object returned contains the current camera settings of the view.'
'This is important to understand because changing the camera may not behave as expected.
'For example the following code will result in no changes to the view contents.

Set MyCamera = oView.Camera


' Create the ClientGraphics object.
Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("SampleGraphicsID")

' Create a new graphics node within the client graphics objects.
Set oCurvesNode = oClientGraphics.AddNode(1)

Set oCenter = MyCamera.Target

Set oNormal = MyCamera.UpVector

' Create a matrix. A new matrix is initialized with an identity matrix.
Set oTransformMatrix = oTransGeom.CreateMatrix

End If



End Sub


Sub DrawCircle()

' Create a transient circle object
Set oCircle = oTransGeom.CreateCircle(oCenter, oNormal, MyCamera.Target.DistanceTo(MyCamera.Eye))

' Create a circle graphics object within the node.
Set oCircleGraphics = oCurvesNode.AddCurveGraphics(oCircle)

ThisApplication.ActiveView.Update

End Sub

Sub RotateCameraAbout(ByVal dAngle As Double)


' Get the evaluator from the circle to get points along the circle.
Set oCurveEval = oCircle.Evaluator

' Calculate the angle to step with each increment.
' Define Pi
dPi = Atn(1) * 4
dIncrement = (dPi / 180) * dAngle


' Determine the position along the circle where the eye currently is.
adEye(0) = MyCamera.Eye.x
adEye(1) = MyCamera.Eye.Y
adEye(2) = MyCamera.Eye.Z

Call oCurveEval.GetParamAtPoint(adEye, adGuessparams, adMaxDeviations, adParams, aenSolTypes)

' Initialize the position using the current eye position.
dCurrent = adParams(0)

' Calculate a point on the circle using the current parameter.
adParams(0) = dCurrent + dIncrement

Call oCurveEval.GetPointAtParam(adParams, adPoint)

' Create a point that defines the eye position.
Set oNewEye = ThisApplication.TransientGeometry.CreatePoint(adPoint(0), adPoint(1), adPoint(2))

' Set the eye and apply the camera.
MyCamera.Eye = oNewEye
MyCamera.ApplyWithoutTransition


End Sub


Sub DeleteCircle()

Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID")
If Err.Number = 0 Then
On Error GoTo 0
' An existing client graphics object was successfully obtained so clean up.
oClientGraphics.Delete

' update the display to see the results.
oView.Update
End If

End Sub

Sub RotateMatrix90()

Debug.Print MyCamera.UpVector.x
Debug.Print MyCamera.UpVector.Y
Debug.Print MyCamera.UpVector.Z

' Set the rotation of the matrix for a 90 degree rotation about the Z axis.

'I think the problem located here on the next line. **** ,oTransGeom.CreateVector(0, 1, 0) **********
' but I don't know how to fix it. I think the coordinates need to change as the up vector changes .
' Although I don't know how to do it.

Call oTransformMatrix.SetToRotation(3.14159265358979 / 2, oTransGeom.CreateVector(0, 1, 0), oCenter)
oNormal.TransformBy oTransformMatrix



End Sub Edited by: Stuartmp74 on Dec 13, 2008 5:09 AM
Message 4 of 12
Anonymous
in reply to: stuartmp74


Please post code using Rich Text
format.

 

Joe ...

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi
Brian this is my code Please try running the Function 'Positive90' I am having
Rotate the Model about the horizontal Axis. I have no trouble with rotating
the model about the up vector (vertical axis) which is the 'Positive90'
function less the 'RotateMatrix90' sub. But I can't seam to Rotate the Matrix
to a position normal to the up vector so I can Rotate the Model about the
horizontal Axis Could you help me out on this one. I have actually be tiring
on and off for years to do it but I just can't seem to get my head around how
the matrix translation works. I am drawing a circle just as a reference until
I perfect the code I really work appreciate you time on this one. As I said
before. I would like to map them these functions onto run by my space Explorer
Option Explicit 'LoadBaseValues Dim oApp As Inventor.Application Dim oDoc As
Document Dim oView As View Dim oCompDef As ComponentDefinition Dim
oClientGraphics As ClientGraphics Dim oTransGeom As TransientGeometry Dim
MyCamera As Camera Dim oCurvesNode As GraphicsNode Dim oCenter As Point Dim
oNormal As UnitVector Dim oTransformMatrix As Matrix 'LoadBaseValues
'DrawCircle Dim oCircle As Inventor.Circle Dim oCircleGraphics As
CurveGraphics 'DrawCircle 'RotateCameraAbout Dim oCurveEval As CurveEvaluator
Dim dPi As Double Dim dIncrement As Double Dim dCurrent As Double Dim adEye(2)
As Double Dim adGuessparams() As Double Dim adMaxDeviations() As Double Dim
adParams(0) As Double Dim aenSolTypes() As SolutionNatureEnum Dim adPoint(2)
As Double Dim oNewEye As Point 'RotateCameraAbout Public Function Positive90()
LoadBaseValues RotateMatrix90 DrawCircle RotateCameraAbout -90 DeleteCircle
End Function Public Function Negitive90() LoadBaseValues RotateMatrix90
DrawCircle RotateCameraAbout 90 DeleteCircle End Function Sub LoadBaseValues()
Set oApp = ThisApplication Set oDoc = oApp.ActiveDocument Set oView =
oApp.ActiveView ' Set a reference to component definition of the active
document. ' This assumes that a part or assembly document is active. Set
oCompDef = oDoc.ComponentDefinition ' Check to see if the test graphics data
object already exists. ' If it does clean up by removing all associated of the
client graphics ' from the document. If it doesn't create it. On Error Resume
Next Set oClientGraphics =
oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID") If Err.Number = 0
Then On Error GoTo 0 ' An existing client graphics object was successfully
obtained so clean up. oClientGraphics.Delete ' update the display to see the
results. oView.Update GoTo Continue: Else Continue: Err.Clear On Error GoTo 0
' Set a reference to the transient geometry object for user later. Set
oTransGeom = oApp.TransientGeometry 'The Camera is analogous to a real-world
camera. 'You can define its position in space, the direction in which it is
pointed and how it is tipped. 'You can also control the type of lens by
setting the perspective angle.' 'Each time the Camera property of the View is
used a new Camera object is returned.' 'The Camera object returned contains
the current camera settings of the view.' 'This is important to understand
because changing the camera may not behave as expected. 'For example the
following code will result in no changes to the view contents. Set MyCamera =
oView.Camera ' Create the ClientGraphics object. Set oClientGraphics =
oCompDef.ClientGraphicsCollection.Add("SampleGraphicsID") ' Create a new
graphics node within the client graphics objects. Set oCurvesNode =
oClientGraphics.AddNode(1) Set oCenter = MyCamera.Target Set oNormal =
MyCamera.UpVector ' Create a matrix. A new matrix is initialized with an
identity matrix. Set oTransformMatrix = oTransGeom.CreateMatrix End If End Sub
Sub DrawCircle() ' Create a transient circle object Set oCircle =
oTransGeom.CreateCircle(oCenter, oNormal,
MyCamera.Target.DistanceTo(MyCamera.Eye)) ' Create a circle graphics object
within the node. Set oCircleGraphics = oCurvesNode.AddCurveGraphics(oCircle)
ThisApplication.ActiveView.Update End Sub Sub RotateCameraAbout(ByVal dAngle
As Double) ' Get the evaluator from the circle to get points along the circle.
Set oCurveEval = oCircle.Evaluator ' Calculate the angle to step with each
increment. ' Define Pi dPi = Atn(1) * 4 dIncrement = (dPi / 180) * dAngle '
Determine the position along the circle where the eye currently is. adEye(0) =
MyCamera.Eye.x adEye(1) = MyCamera.Eye.Y adEye(2) = MyCamera.Eye.Z Call
oCurveEval.GetParamAtPoint(adEye, adGuessparams, adMaxDeviations, adParams,
aenSolTypes) ' Initialize the position using the current eye position.
dCurrent = adParams(0) ' Calculate a point on the circle using the current
parameter. adParams(0) = dCurrent + dIncrement Call
oCurveEval.GetPointAtParam(adParams, adPoint) ' Create a point that defines
the eye position. Set oNewEye =
ThisApplication.TransientGeometry.CreatePoint(adPoint(0), adPoint(1),
adPoint(2)) ' Set the eye and apply the camera. MyCamera.Eye = oNewEye
MyCamera.ApplyWithoutTransition End Sub Sub DeleteCircle() Set oClientGraphics
= oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID") If Err.Number = 0
Then On Error GoTo 0 ' An existing client graphics object was successfully
obtained so clean up. oClientGraphics.Delete ' update the display to see the
results. oView.Update End If End Sub Sub RotateMatrix90() Debug.Print
MyCamera.UpVector.x Debug.Print MyCamera.UpVector.Y Debug.Print
MyCamera.UpVector.Z ' Set the rotation of the matrix for a 90 degree rotation
about the Z axis. 'I think the problem located here on the next line. ****
,oTransGeom.CreateVector(0, 1, 0) ********** ' but I don't know how to fix it.
I think the coordinates need to change as the up vector changes . ' Although I
don't know how to do it. Call oTransformMatrix.SetToRotation(3.14159265358979
/ 2, oTransGeom.CreateVector(0, 1, 0), oCenter) oNormal.TransformBy
oTransformMatrix End Sub Edited by: Stuartmp74 on Dec 13, 2008 5:09
AM
Message 5 of 12
Anonymous
in reply to: stuartmp74

If we keep doing that, how will we ever get them to fix
the frikkin' plain text editor? Personally, I don't know what
is taking them so long, except maybe they don't know WTF
they are doing at AD. I suspect there is only ONE line of
code to change.

Joe Sutphin wrote:
> Please post code using Rich Text format.
>
> Joe ...
>
>
>
> wrote in message news:6089467@discussion.autodesk.com...
> Hi Brian this is my code Please try running the Function
> 'Positive90' I am having Rotate the Model about the horizontal Axis.
> I have no trouble with rotating the model about the up vector
> (vertical axis) which is the 'Positive90' function less the
> 'RotateMatrix90' sub. But I can't seam to Rotate the Matrix to a
> position normal to the up vector so I can Rotate the Model about the
> horizontal Axis Could you help me out on this one. I have actually
> be tiring on and off for years to do it but I just can't seem to get
> my head around how the matrix translation works. I am drawing a
> circle just as a reference until I perfect the code I really work
> appreciate you time on this one. As I said before. I would like to
> map them these functions onto run by my space Explorer Option
> Explicit 'LoadBaseValues Dim oApp As Inventor.Application Dim oDoc
> As Document Dim oView As View Dim oCompDef As ComponentDefinition
> Dim oClientGraphics As ClientGraphics Dim oTransGeom As
> TransientGeometry Dim MyCamera As Camera Dim oCurvesNode As
> GraphicsNode Dim oCenter As Point Dim oNormal As UnitVector Dim
> oTransformMatrix As Matrix 'LoadBaseValues 'DrawCircle Dim oCircle
> As Inventor.Circle Dim oCircleGraphics As CurveGraphics 'DrawCircle
> 'RotateCameraAbout Dim oCurveEval As CurveEvaluator Dim dPi As
> Double Dim dIncrement As Double Dim dCurrent As Double Dim adEye(2)
> As Double Dim adGuessparams() As Double Dim adMaxDeviations() As
> Double Dim adParams(0) As Double Dim aenSolTypes() As
> SolutionNatureEnum Dim adPoint(2) As Double Dim oNewEye As Point
> 'RotateCameraAbout Public Function Positive90() LoadBaseValues
> RotateMatrix90 DrawCircle RotateCameraAbout -90 DeleteCircle End
> Function Public Function Negitive90() LoadBaseValues RotateMatrix90
> DrawCircle RotateCameraAbout 90 DeleteCircle End Function Sub
> LoadBaseValues() Set oApp = ThisApplication Set oDoc =
> oApp.ActiveDocument Set oView = oApp.ActiveView ' Set a reference to
> component definition of the active document. ' This assumes that a
> part or assembly document is active. Set oCompDef =
> oDoc.ComponentDefinition ' Check to see if the test graphics data
> object already exists. ' If it does clean up by removing all
> associated of the client graphics ' from the document. If it doesn't
> create it. On Error Resume Next Set oClientGraphics =
> oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID") If
> Err.Number = 0 Then On Error GoTo 0 ' An existing client graphics
> object was successfully obtained so clean up. oClientGraphics.Delete
> ' update the display to see the results. oView.Update GoTo Continue:
> Else Continue: Err.Clear On Error GoTo 0 ' Set a reference to the
> transient geometry object for user later. Set oTransGeom =
> oApp.TransientGeometry 'The Camera is analogous to a real-world
> camera. 'You can define its position in space, the direction in
> which it is pointed and how it is tipped. 'You can also control the
> type of lens by setting the perspective angle.' 'Each time the
> Camera property of the View is used a new Camera object is
> returned.' 'The Camera object returned contains the current camera
> settings of the view.' 'This is important to understand because
> changing the camera may not behave as expected. 'For example the
> following code will result in no changes to the view contents. Set
> MyCamera = oView.Camera ' Create the ClientGraphics object. Set
> oClientGraphics =
> oCompDef.ClientGraphicsCollection.Add("SampleGraphicsID") ' Create a
> new graphics node within the client graphics objects. Set
> oCurvesNode = oClientGraphics.AddNode(1) Set oCenter =
> MyCamera.Target Set oNormal = MyCamera.UpVector ' Create a matrix. A
> new matrix is initialized with an identity matrix. Set
> oTransformMatrix = oTransGeom.CreateMatrix End If End Sub Sub
> DrawCircle() ' Create a transient circle object Set oCircle =
> oTransGeom.CreateCircle(oCenter, oNormal,
> MyCamera.Target.DistanceTo(MyCamera.Eye)) ' Create a circle graphics
> object within the node. Set oCircleGraphics =
> oCurvesNode.AddCurveGraphics(oCircle)
> ThisApplication.ActiveView.Update End Sub Sub
> RotateCameraAbout(ByVal dAngle As Double) ' Get the evaluator from
> the circle to get points along the circle. Set oCurveEval =
> oCircle.Evaluator ' Calculate the angle to step with each increment.
> ' Define Pi dPi = Atn(1) * 4 dIncrement = (dPi / 180) * dAngle '
> Determine the position along the circle where the eye currently is.
> adEye(0) = MyCamera.Eye.x adEye(1) = MyCamera.Eye.Y adEye(2) =
> MyCamera.Eye.Z Call oCurveEval.GetParamAtPoint(adEye, adGuessparams,
> adMaxDeviations, adParams, aenSolTypes) ' Initialize the position
> using the current eye position. dCurrent = adParams(0) ' Calculate a
> point on the circle using the current parameter. adParams(0) =
> dCurrent + dIncrement Call oCurveEval.GetPointAtParam(adParams,
> adPoint) ' Create a point that defines the eye position. Set oNewEye
> = ThisApplication.TransientGeometry.CreatePoint(adPoint(0),
> adPoint(1), adPoint(2)) ' Set the eye and apply the camera.
> MyCamera.Eye = oNewEye MyCamera.ApplyWithoutTransition End Sub Sub
> DeleteCircle() Set oClientGraphics =
> oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID") If
> Err.Number = 0 Then On Error GoTo 0 ' An existing client graphics
> object was successfully obtained so clean up. oClientGraphics.Delete
> ' update the display to see the results. oView.Update End If End Sub
> Sub RotateMatrix90() Debug.Print MyCamera.UpVector.x Debug.Print
> MyCamera.UpVector.Y Debug.Print MyCamera.UpVector.Z ' Set the
> rotation of the matrix for a 90 degree rotation about the Z axis. 'I
> think the problem located here on the next line. ****
> ,oTransGeom.CreateVector(0, 1, 0) ********** ' but I don't know how
> to fix it. I think the coordinates need to change as the up vector
> changes . ' Although I don't know how to do it. Call
> oTransformMatrix.SetToRotation(3.14159265358979 / 2,
> oTransGeom.CreateVector(0, 1, 0), oCenter) oNormal.TransformBy
> oTransformMatrix End Sub Edited by: Stuartmp74 on Dec 13, 2008 5:09 AM
>
Message 6 of 12
stuartmp74
in reply to: stuartmp74

Done.

The file is an attachment too.





Option Explicit





'LoadBaseValues

Dim oApp As Inventor.Application

Dim oDoc As Document

Dim oView As View

Dim oCompDef As ComponentDefinition

Dim oClientGraphics As ClientGraphics

Dim oTransGeom As TransientGeometry

Dim MyCamera As Camera

Dim oCurvesNode As GraphicsNode

Dim oCenter As Point

Dim oNormal As UnitVector

Dim oTransformMatrix As Matrix

'LoadBaseValues



'DrawCircle

Dim oCircle As Inventor.Circle

Dim oCircleGraphics As CurveGraphics

'DrawCircle



'RotateCameraAbout

Dim oCurveEval As CurveEvaluator

Dim dPi As Double

Dim dIncrement As Double

Dim dCurrent As Double

Dim adEye(2) As Double

Dim adGuessparams() As Double

Dim adMaxDeviations() As Double

Dim adParams(0) As Double

Dim aenSolTypes() As SolutionNatureEnum

Dim adPoint(2) As Double

Dim oNewEye As Point

'RotateCameraAbout







Public Function Positive90()



LoadBaseValues

RotateMatrix90

DrawCircle

RotateCameraAbout -90

DeleteCircle





End Function



Public Function Negitive90()



LoadBaseValues

RotateMatrix90

DrawCircle

RotateCameraAbout 90

DeleteCircle



End Function



Sub LoadBaseValues()



Set oApp = ThisApplication

Set oDoc = oApp.ActiveDocument

Set oView = oApp.ActiveView





' Set a reference to component definition of the active document.

' This assumes that a part or assembly document is active.

Set oCompDef = oDoc.ComponentDefinition





' Check to see if the test graphics data object already exists.

' If it does clean up by removing all associated of the client graphics

' from the document. If it doesn't create it.

On Error Resume Next

Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID")

If Err.Number = 0 Then

On Error GoTo 0

' An existing client graphics object was successfully obtained so clean up.

oClientGraphics.Delete



' update the display to see the results.

oView.Update

GoTo Continue:

Else

Continue:

Err.Clear

On Error GoTo 0



' Set a reference to the transient geometry object for user later.

Set oTransGeom = oApp.TransientGeometry



'The Camera is analogous to a real-world camera.

'You can define its position in space, the direction in which it is pointed and how it is tipped.

'You can also control the type of lens by setting the perspective angle.'

'Each time the Camera property of the View is used a new Camera object is returned.'

'The Camera object returned contains the current camera settings of the view.'

'This is important to understand because changing the camera may not behave as expected.

'For example the following code will result in no changes to the view contents.



Set MyCamera = oView.Camera





' Create the ClientGraphics object.

Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("SampleGraphicsID")



' Create a new graphics node within the client graphics objects.

Set oCurvesNode = oClientGraphics.AddNode(1)



Set oCenter = MyCamera.Target



Set oNormal = MyCamera.UpVector



' Create a matrix. A new matrix is initialized with an identity matrix.

Set oTransformMatrix = oTransGeom.CreateMatrix



End If







End Sub





Sub DrawCircle()



' Create a transient circle object

Set oCircle = oTransGeom.CreateCircle(oCenter, oNormal, MyCamera.Target.DistanceTo(MyCamera.Eye))



' Create a circle graphics object within the node.

Set oCircleGraphics = oCurvesNode.AddCurveGraphics(oCircle)



ThisApplication.ActiveView.Update



End Sub



Sub RotateCameraAbout(ByVal dAngle As Double)





' Get the evaluator from the circle to get points along the circle.

Set oCurveEval = oCircle.Evaluator



' Calculate the angle to step with each increment.

' Define Pi

dPi = Atn(1) * 4

dIncrement = (dPi / 180) * dAngle





' Determine the position along the circle where the eye currently is.

adEye(0) = MyCamera.Eye.x

adEye(1) = MyCamera.Eye.Y

adEye(2) = MyCamera.Eye.Z



Call oCurveEval.GetParamAtPoint(adEye, adGuessparams, adMaxDeviations, adParams, aenSolTypes)



' Initialize the position using the current eye position.

dCurrent = adParams(0)



' Calculate a point on the circle using the current parameter.

adParams(0) = dCurrent + dIncrement



Call oCurveEval.GetPointAtParam(adParams, adPoint)



' Create a point that defines the eye position.

Set oNewEye = ThisApplication.TransientGeometry.CreatePoint(adPoint(0), adPoint(1), adPoint(2))



' Set the eye and apply the camera.

MyCamera.Eye = oNewEye

MyCamera.ApplyWithoutTransition





End Sub





Sub DeleteCircle()



Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID")

If Err.Number = 0 Then

On Error GoTo 0

' An existing client graphics object was successfully obtained so clean up.

oClientGraphics.Delete



' update the display to see the results.

oView.Update

End If



End Sub



Sub RotateMatrix90()



Debug.Print MyCamera.UpVector.x

Debug.Print MyCamera.UpVector.Y

Debug.Print MyCamera.UpVector.Z



' Set the rotation of the matrix for a 90 degree rotation about the Z axis.



'I think the problem located here on the next line. **** ,oTransGeom.CreateVector(0, 1, 0) **********

' but I don't know how to fix it. I think the coordinates need to change as the up vector changes .

' Although I don't know how to do it.



Call oTransformMatrix.SetToRotation(3.14159265358979 / 2, oTransGeom.CreateVector(0, 1, 0), oCenter)

oNormal.TransformBy oTransformMatrix







End Sub
Message 7 of 12
Anonymous
in reply to: stuartmp74

In all likelihood, they're not going to fix it.

Joe ...


"Bob S." wrote in message
news:6090012@discussion.autodesk.com...
If we keep doing that, how will we ever get them to fix
the frikkin' plain text editor? Personally, I don't know what
is taking them so long, except maybe they don't know WTF
they are doing at AD. I suspect there is only ONE line of
code to change.

Joe Sutphin wrote:
> Please post code using Rich Text format.
>
> Joe ...
>
>
>
> wrote in message news:6089467@discussion.autodesk.com...
> Hi Brian this is my code Please try running the Function
> 'Positive90' I am having Rotate the Model about the horizontal Axis.
> I have no trouble with rotating the model about the up vector
> (vertical axis) which is the 'Positive90' function less the
> 'RotateMatrix90' sub. But I can't seam to Rotate the Matrix to a
> position normal to the up vector so I can Rotate the Model about the
> horizontal Axis Could you help me out on this one. I have actually
> be tiring on and off for years to do it but I just can't seem to get
> my head around how the matrix translation works. I am drawing a
> circle just as a reference until I perfect the code I really work
> appreciate you time on this one. As I said before. I would like to
> map them these functions onto run by my space Explorer Option
> Explicit 'LoadBaseValues Dim oApp As Inventor.Application Dim oDoc
> As Document Dim oView As View Dim oCompDef As ComponentDefinition
> Dim oClientGraphics As ClientGraphics Dim oTransGeom As
> TransientGeometry Dim MyCamera As Camera Dim oCurvesNode As
> GraphicsNode Dim oCenter As Point Dim oNormal As UnitVector Dim
> oTransformMatrix As Matrix 'LoadBaseValues 'DrawCircle Dim oCircle
> As Inventor.Circle Dim oCircleGraphics As CurveGraphics 'DrawCircle
> 'RotateCameraAbout Dim oCurveEval As CurveEvaluator Dim dPi As
> Double Dim dIncrement As Double Dim dCurrent As Double Dim adEye(2)
> As Double Dim adGuessparams() As Double Dim adMaxDeviations() As
> Double Dim adParams(0) As Double Dim aenSolTypes() As
> SolutionNatureEnum Dim adPoint(2) As Double Dim oNewEye As Point
> 'RotateCameraAbout Public Function Positive90() LoadBaseValues
> RotateMatrix90 DrawCircle RotateCameraAbout -90 DeleteCircle End
> Function Public Function Negitive90() LoadBaseValues RotateMatrix90
> DrawCircle RotateCameraAbout 90 DeleteCircle End Function Sub
> LoadBaseValues() Set oApp = ThisApplication Set oDoc =
> oApp.ActiveDocument Set oView = oApp.ActiveView ' Set a reference to
> component definition of the active document. ' This assumes that a
> part or assembly document is active. Set oCompDef =
> oDoc.ComponentDefinition ' Check to see if the test graphics data
> object already exists. ' If it does clean up by removing all
> associated of the client graphics ' from the document. If it doesn't
> create it. On Error Resume Next Set oClientGraphics =
> oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID") If
> Err.Number = 0 Then On Error GoTo 0 ' An existing client graphics
> object was successfully obtained so clean up. oClientGraphics.Delete
> ' update the display to see the results. oView.Update GoTo Continue:
> Else Continue: Err.Clear On Error GoTo 0 ' Set a reference to the
> transient geometry object for user later. Set oTransGeom =
> oApp.TransientGeometry 'The Camera is analogous to a real-world
> camera. 'You can define its position in space, the direction in
> which it is pointed and how it is tipped. 'You can also control the
> type of lens by setting the perspective angle.' 'Each time the
> Camera property of the View is used a new Camera object is
> returned.' 'The Camera object returned contains the current camera
> settings of the view.' 'This is important to understand because
> changing the camera may not behave as expected. 'For example the
> following code will result in no changes to the view contents. Set
> MyCamera = oView.Camera ' Create the ClientGraphics object. Set
> oClientGraphics =
> oCompDef.ClientGraphicsCollection.Add("SampleGraphicsID") ' Create a
> new graphics node within the client graphics objects. Set
> oCurvesNode = oClientGraphics.AddNode(1) Set oCenter =
> MyCamera.Target Set oNormal = MyCamera.UpVector ' Create a matrix. A
> new matrix is initialized with an identity matrix. Set
> oTransformMatrix = oTransGeom.CreateMatrix End If End Sub Sub
> DrawCircle() ' Create a transient circle object Set oCircle =
> oTransGeom.CreateCircle(oCenter, oNormal,
> MyCamera.Target.DistanceTo(MyCamera.Eye)) ' Create a circle graphics
> object within the node. Set oCircleGraphics =
> oCurvesNode.AddCurveGraphics(oCircle)
> ThisApplication.ActiveView.Update End Sub Sub
> RotateCameraAbout(ByVal dAngle As Double) ' Get the evaluator from
> the circle to get points along the circle. Set oCurveEval =
> oCircle.Evaluator ' Calculate the angle to step with each increment.
> ' Define Pi dPi = Atn(1) * 4 dIncrement = (dPi / 180) * dAngle '
> Determine the position along the circle where the eye currently is.
> adEye(0) = MyCamera.Eye.x adEye(1) = MyCamera.Eye.Y adEye(2) =
> MyCamera.Eye.Z Call oCurveEval.GetParamAtPoint(adEye, adGuessparams,
> adMaxDeviations, adParams, aenSolTypes) ' Initialize the position
> using the current eye position. dCurrent = adParams(0) ' Calculate a
> point on the circle using the current parameter. adParams(0) =
> dCurrent + dIncrement Call oCurveEval.GetPointAtParam(adParams,
> adPoint) ' Create a point that defines the eye position. Set oNewEye
> = ThisApplication.TransientGeometry.CreatePoint(adPoint(0),
> adPoint(1), adPoint(2)) ' Set the eye and apply the camera.
> MyCamera.Eye = oNewEye MyCamera.ApplyWithoutTransition End Sub Sub
> DeleteCircle() Set oClientGraphics =
> oCompDef.ClientGraphicsCollection.Item("SampleGraphicsID") If
> Err.Number = 0 Then On Error GoTo 0 ' An existing client graphics
> object was successfully obtained so clean up. oClientGraphics.Delete
> ' update the display to see the results. oView.Update End If End Sub
> Sub RotateMatrix90() Debug.Print MyCamera.UpVector.x Debug.Print
> MyCamera.UpVector.Y Debug.Print MyCamera.UpVector.Z ' Set the
> rotation of the matrix for a 90 degree rotation about the Z axis. 'I
> think the problem located here on the next line. ****
> ,oTransGeom.CreateVector(0, 1, 0) ********** ' but I don't know how
> to fix it. I think the coordinates need to change as the up vector
> changes . ' Although I don't know how to do it. Call
> oTransformMatrix.SetToRotation(3.14159265358979 / 2,
> oTransGeom.CreateVector(0, 1, 0), oCenter) oNormal.TransformBy
> oTransformMatrix End Sub Edited by: Stuartmp74 on Dec 13, 2008 5:09 AM
>
Message 8 of 12
Anonymous
in reply to: stuartmp74


I'm not sure what your exact requirements
are.  I looked through your code but it seems like you're basically trying
to fly the camera around a part using a circular path where the path can be at
any orientation.  Below is another implementation to do that.  There's
a function below that takes the view and an axis and angle that does all the
work.  The axis defines the axis of rotation and the angle specifies the
amount you want to rotate around.  The center of rotation is always the
current center of the view (camera target).  To play with different
rotations just change the vector defined for the oAxisVector
variable.

 

Public Sub Test()
    Dim oView
As View
    Set oView =
ThisApplication.ActiveView
    

    ' Set the axis of
rotation.
    Dim oAxisVector As
UnitVector
    Set oAxisVector =
ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)

    ' Define
pi.
    Dim dPi As Double
    dPi = Atn(1) *
4
    
    ' To animate the camera
rotation, specify a sequence of rotations.
    Dim iNumSteps
As Integer
    iNumSteps = 180
    Dim
dAngle As Double
    dAngle = (dPi * 2) /
iNumSteps
    Dim i As Integer
    For i = 1
To iNumSteps
        Call
RotateCamera(oView, oAxisVector, dAngle)
    Next
End
Sub

 

Public Sub RotateCamera(ViewWindow As View, Axis As
UnitVector, Angle As Double)
    Dim oCamera As
Camera
    Set oCamera =
ViewWindow.Camera
   
    ' Create a new
matrix.
    Dim oTrans As Matrix
    Set
oTrans = oTG.CreateMatrix
   
    ' Set the
matrix so it defines the rotation specified by the input
arguments.
    Call oTrans.SetToRotation(Angle, Axis.AsVector,
oCamera.Target)
   
    ' Transform the
camera data using the matrix.  The target of the camera will
stay
    ' fixed, but the eye point and the up vector can
change and need to be transformed.
    Dim oTempPoint As
Point
    Set oTempPoint = oCamera.Eye
   
Call oTempPoint.TransformBy(oTrans)
    oCamera.Eye =
oTempPoint
   
    Dim oTempUpVector As
UnitVector
    Set oTempUpVector =
oCamera.UpVector
    Call
oTempUpVector.TransformBy(oTrans)
    oCamera.UpVector =
oTempUpVector
   
    ' Apply the changes
to the view.
    oCamera.ApplyWithoutTransition
End
Sub

Message 9 of 12
stuartmp74
in reply to: stuartmp74

Thanks a lot for the response Brian.

That is what I am after but I am trying to rotate it reletive to the screen not the Origin of the part or Assembly

I am guessing these line need to change

' Set the axis of rotation.
Dim oAxisVector As UnitVector
Set oAxisVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)


Any Ideas on how to make it rotate reletive to the screen.
X axis being left to right on the screen.
Y axis being bottom to top of the screen.


In other words your routine is great but I don't know at the time of rotation which way the Part or Assembly Orgins are facing
so in one case to make it rotate about the X axis reletive to the screen
I would use

Set oAxisVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)

But in another case to rotate it again about theX axis reletive to the screen
I would use

Set oAxisVector = ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 0)

What I am have trouble with is working of how to program this.

What I am trying to do is rotate it about the x or the y axis reletive to the screen no matter what the orintation of the part is in.

Please help me out if you can. Edited by: stuartmp74 on Dec 16, 2008 1:23 AM
Message 10 of 12
Anonymous
in reply to: stuartmp74


Here's the code again but with a different sub that
calls the RotateCamera sub.  It creates the vector based on the current
camera.  There is an If statement where you can change which part is
executed by setting one of them to True and the other False.  This will
demonstrate the three possible standard rotations for a view.

 

Public Sub SpinViewTest()
    Dim
oView As View
    Set oView =
ThisApplication.ActiveView
   
    Dim
oAxisVector As UnitVector
    Dim oCamera As
Camera
    Set oCamera = oView.Camera
   
Dim oSiteVector As UnitVector
    Set oSiteVector =
ThisApplication.TransientGeometry.CreateUnitVector(
_
                                   
oCamera.Eye.X - oCamera.Target.X,
_
                                   
oCamera.Eye.y - oCamera.Target.y,
_
                                   
oCamera.Eye.z -
oCamera.Target.z)
                                   

    If False
Then
        ' Spin around the vertical
axis.
        Set oAxisVector =
oCamera.UpVector
    ElseIf False
Then
        ' Spin around the horizontal
axis.
        Set oAxisVector =
oSiteVector.CrossProduct(oCamera.UpVector)
    ElseIf True
Then
        ' Spin around the line of
site vector.
        Set oAxisVector =
oSiteVector
    End If
   

    Dim dPi As Double
    dPi = Atn(1) *
4
   
    Dim iNumSteps As
Integer
    iNumSteps = 180
    Dim dAngle
As Double
    dAngle = (dPi * 2) /
iNumSteps
    Dim i As Integer
    For i = 1
To iNumSteps
        Call
RotateCamera(oView, oAxisVector, dAngle)
    Next
End
Sub

 


Public Sub Test()
    Dim oView As
View
    Set oView =
ThisApplication.ActiveView
   
    Dim
oAxisVector As UnitVector
    Set oAxisVector =
ThisApplication.TransientGeometry.CreateUnitVector(0, 1,
0)
    Dim dPi As Double
    dPi = Atn(1) *
4
   
    Dim iNumSteps As
Integer
    iNumSteps = 180
    Dim dAngle
As Double
    dAngle = (dPi * 2) /
iNumSteps
    Dim i As Integer
    For i = 1
To iNumSteps
        Call
RotateCamera(oView, oAxisVector, dAngle)
    Next
End
Sub

 

Public Sub RotateCamera(ViewWindow As View, Axis As UnitVector, Angle As
Double)
    Dim oCamera As Camera
    Set
oCamera = ViewWindow.Camera
   
    Dim oTG
As TransientGeometry
    Set oTG =
ThisApplication.TransientGeometry
   
    '
Create a new matrix.
    Dim oTrans As
Matrix
    Set oTrans = oTG.CreateMatrix
   

    ' Set the matrix so it defines the rotation specified by
the input arguments.
    Call oTrans.SetToRotation(Angle,
Axis.AsVector, oCamera.Target)
   
    '
Transform the camera data using the matrix.  The target of the camera will
stay
    ' fixed, but the eye point and the up vector can
change and need to be transformed.
    Dim oTempPoint As
Point
    Set oTempPoint = oCamera.Eye
   
Call oTempPoint.TransformBy(oTrans)
    oCamera.Eye =
oTempPoint
   
    Dim oTempUpVector As
UnitVector
    Set oTempUpVector =
oCamera.UpVector
    Call
oTempUpVector.TransformBy(oTrans)
    oCamera.UpVector =
oTempUpVector
   
    ' Apply the changes
to the view.
    oCamera.ApplyWithoutTransition
End
Sub

 

Message 11 of 12
stuartmp74
in reply to: stuartmp74

Thanks a lot Brian, I have been trying to this since V5.3



I had a similar routine in Mechanical Desktop. That I used all the time.





Here is my final code if anyone wants to use it. (See Attached as well)



I am going to map the command onto my space explorer





Public Sub RCamAbtVertAxsPos90()



RotateMain "AbtVertAxs", 90



End Sub



Public Sub RCamAbtVertAxsNeg90()



RotateMain "AbtVertAxs", -90





End Sub



Public Sub RCamAbtHorAxsPos90()



RotateMain "AbtHorAxs", 90



End Sub



Public Sub RCamAbtHorAxsNeg90()



RotateMain "AbtHorAxs", -90



End Sub



Public Sub RCamAbtScreenPos90()



RotateMain "AbtScreen", 90



End Sub



Public Sub RCamAbtScreenNeg90()



RotateMain "AbtScreen", -90



End Sub





Public Sub RotateMain(AboutAxis As String, RotAngle As Double)



Dim oView As View

Dim oAxisVector As UnitVector

Dim oCamera As Camera

Dim oSiteVector As UnitVector





Set oView = ThisApplication.ActiveView

Set oCamera = oView.Camera



Select Case AboutAxis



Case "AbtVertAxs"

' Spin around the vertical axis.

Set oAxisVector = oCamera.UpVector





Case "AbtHorAxs"

' Spin around the horizontal axis.

Set oSiteVector = ThisApplication.TransientGeometry.CreateUnitVector(oCamera.Eye.x - oCamera.Target.x, oCamera.Eye.Y - oCamera.Target.Y, oCamera.Eye.Z - oCamera.Target.Z)

Set oAxisVector = oSiteVector.CrossProduct(oCamera.UpVector)





Case "AbtScreen"

' Spin around the line of site vector.

Set oSiteVector = ThisApplication.TransientGeometry.CreateUnitVector(oCamera.Eye.x - oCamera.Target.x, oCamera.Eye.Y - oCamera.Target.Y, oCamera.Eye.Z - oCamera.Target.Z)

Set oAxisVector = oSiteVector





End Select





Dim dPi As Double

Dim dAngle As Double

Dim iNumSteps As Integer

Dim dIncrement As Double





dPi = Atn(1) * 4

dAngle = RotAngle

iNumSteps = 15 'used to slow rotation down a bit

dIncrement = (dPi / 180) * dAngle



Dim i As Integer

For i = 1 To iNumSteps

Call RotateCamera(oView, oAxisVector, dIncrement / iNumSteps)

Next





End Sub







Public Sub RotateCamera(ViewWindow As View, Axis As UnitVector, Angle As Double)





Dim oCamera As Camera

Set oCamera = ViewWindow.Camera



Dim oTG As TransientGeometry

Set oTG = ThisApplication.TransientGeometry



'Create a new matrix.

Dim oTrans As Matrix

Set oTrans = oTG.CreateMatrix





' Set the matrix so it defines the rotation specified by the input arguments.

Call oTrans.SetToRotation(Angle, Axis.AsVector, oCamera.Target)



'Transform the camera data using the matrix. The target of the camera will stay

' fixed, but the eye point and the up vector can change and need to be transformed.

Dim oTempPoint As Point

Set oTempPoint = oCamera.Eye



Call oTempPoint.TransformBy(oTrans)

oCamera.Eye = oTempPoint



Dim oTempUpVector As UnitVector

Set oTempUpVector = oCamera.UpVector

Call oTempUpVector.TransformBy(oTrans)

oCamera.UpVector = oTempUpVector



' Apply the changes to the view.

oCamera.ApplyWithoutTransition



End Sub





'Thanks again to Brian


Message 12 of 12
craigzcool
in reply to: stuartmp74

has there been any updates since this question was last asked - either in Inventor 2014 or 2015?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report