Problem related to rotation of an occurence

Problem related to rotation of an occurence

Anonymous
Not applicable
871 Views
13 Replies
Message 1 of 14

Problem related to rotation of an occurence

Anonymous
Not applicable
Hi i tried rotate a particular occurence called cabin which is in a subassembly called my final crane assembly:1
when i tried to rotate the cabin , the whole crane is rotating. my code is given below. can any one try to help me out from this issue...Public Sub CreateProxies()
Dim oassDoc As AssemblyDocument
Set oassDoc = ThisApplication.ActiveDocument

Dim oasscompdef As AssemblyComponentDefinition
Set oasscompdef = oassDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence
Dim cabin As ComponentOccurrence
Dim oPartProxy As ComponentOccurrenceProxy

Set oOcc = oasscompdef.Occurrences.ItemByName("my final crane assembly:1")
Set cabin = oOcc.Definition.Occurrences.ItemByName("cabin:1")
Call oOcc.CreateGeometryProxy(cabin, oPartProxy)


Dim oHS1 As HighlightSet
Set oHS1 = oassDoc.HighlightSets.Add
oHS1.SetColor 255, 0, 0

oHS1.Clear
oHS1.AddItem oPartProxy
MsgBox "proxy is highlighted"

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry


' Get the current matrix from the occurrence.
Dim oRotMat As Matrix
Set oRotMat = oOcc.Transformation


'Create a point based on the current position of the occurrence.
Dim oCenter As Point
Set oCenter = oTG.CreatePoint(oRotMat.Translation.x, oRotMat.Translation.y, oRotMat.Translation.z)


' Define the matrix that specifies the rotation about the Z axis and the center point.
' The angle is pi/2 or 90 degrees.
Dim dpi As Double
dpi = 1.74532925199432E-02
Dim i As Integer
For i = 1 To 5

Call oRotMat.SetToRotation(dpi, oTG.CreateVector(0, 0, 1), oCenter)


' Get the current matrix from the occurrence.
Dim oMat As Matrix

Set oMat = oOcc.Transformation

'Multiply the occurrence matrix by the rotation matrix.

Call oMat.MultiplyBy(oRotMat)


'Apply the new matrix back to the occurrence.

oOcc.Transformation = oMat
dpi = dpi + 1.74532925199432E-02

Next

End Sub
0 Likes
872 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Hello bharathc85,

you can read the follow link.

http://modthemachine.typepad.com/my_weblog/2009/04/positioning-assembly-occurrences.html

There are good information about you want.

Bye
Luizoo from Brazil
0 Likes
Message 3 of 14

Anonymous
Not applicable
thanks Luizoo.. hope this will be helpful...good site.
0 Likes
Message 4 of 14

Anonymous
Not applicable
my problem is different, it doesnt provide any solution for me..
0 Likes
Message 5 of 14

Anonymous
Not applicable
You are applying the transform to the sub-assembly occurrence in this line
of code:

oOcc.Transformation = oMat

Shouldn't you apply it to the PartProxy occurrence?

Sanjay-
0 Likes
Message 6 of 14

Anonymous
Not applicable
hi if you don't mind will u plz tell clearly. iam attaching the model, in that the brown object on which some text is written is the cabin. when i try to rotate that entire crane is rotating.
0 Likes
Message 7 of 14

Anonymous
Not applicable
i tried to change to proxy , its showing the error as OVERFLOW
0 Likes
Message 8 of 14

Anonymous
Not applicable
Hello Bharathc85,

i was analyzing your code. Pay attention:

Set oOcc = oasscompdef.Occurrences.ItemByName("my final crane assembly:1")
Set cabin = oOcc.Definition.Occurrences.ItemByName("cabin:1")
Call oOcc.CreateGeometryProxy(cabin, oPartProxy)

You took the complete Assembly with "oOcc" variable and then you applied a transform matrix on this variable.

You need to apply a transform matrix on the "cabin" object and do not on the "oOcc".
Did you understand me?

Bye
0 Likes
Message 9 of 14

Anonymous
Not applicable
Here is a fragment of code that we have used.
We selected some componentes inside one Assembly and then the macro move and rotate these componentes to the assembly origin.
Maybe is can help you.

'Variables Declarations
Dim oAssDoc As AssemblyDocument
Dim oAssDef As AssemblyComponentDefinition
Dim oAssOcc As ComponentOccurrence
Dim oTrans As TransientGeometry
Dim oWorkPlane As WorkPlane
Dim oMatrix As Matrix
Dim oPlane As Plane
Dim oWorldOrigin As Point
Dim oWorldXvector As UnitVector
Dim oWorldYvector As UnitVector
Dim oWorldZvector As UnitVector

'***Geting Assembly Coordinate System.

'Verifing if the active document is an Assembly Document
If ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
'Geting the active document if YES
Set oAssDoc = ThisApplication.ActiveDocument
Else
'Exiting if NOT
Exit Sub
End If

'Geting active document XY plane
Set oWorkPlane = oAssDoc.ComponentDefinition.WorkPlanes(3)

'Geting XY plane Position
'A plane position is defined by Origin, X Vector and Y Vector
Call oWorkPlane.GetPosition(oWorldOrigin, oWorldXvector, oWorldYvector)

'Geting a Transient Plane Geometry abou XY plane
Set oPlane = oWorkPlane.Plane

'Geting the Z vector
Set oWorldZvector = oPlane.Normal

'Define Trasformation Matrix
Set oTrans = ThisApplication.TransientGeometry
Set oMatrix = oTrans.CreateMatrix
Call oMatrix.SetCoordinateSystem(oWorldOrigin, oWorldXvector.AsVector, oWorldYvector.AsVector, oWorldZvector.AsVector)

' Initialize flag.
bStillSelecting = True

' Create an InteractionEvents object.
Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents

oInteractEvents.StatusBarText = "Select a component."

' Ensure interaction is enabled.
oInteractEvents.InteractionDisabled = False

' Set a reference to the select events.
Set oSelectEvents = oInteractEvents.SelectEvents

' Set the filter using the value passed in.
oSelectEvents.AddSelectionFilter kAssemblyOccurrenceFilter

' Start the InteractionEvents object.
oInteractEvents.Start

' Loop until a selection is made.
Do While bStillSelecting
DoEvents
Loop

' Get the selected item. If more than one thing was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As ObjectsEnumerator
Set oSelectedEnts = oSelectEvents.SelectedEntities

'Moving and Rotating the Component

If oSelectedEnts.Count > 0 Then
For iNumber = 1 To oSelectedEnts.Count

oSelectedEnts.Item(iNumber).Transformation = oMatrix
oSelectedEnts.Item(iNumber).Grounded = True

'Set Pick = oSelectedEnts.Item(1)

Next
Else
'Set Pick = Nothing
End If

' Stop the InteractionEvents object.
oInteractEvents.Stop

' Clean up.
Set oSelectEvents = Nothing
Set oInteractEvents = Nothing

End
0 Likes
Message 10 of 14

Anonymous
Not applicable
i tried that also , but the constraints are restricting it, as u can see in the attachment also, iam trying very hard, but not able to rotate . i tried without constarints transformation also its not giving desired motion.
is there any other way.
0 Likes
Message 11 of 14

Anonymous
Not applicable
thanks for this example. Edited by: bharathc85 on Sep 21, 2009 2:47 PM
0 Likes
Message 12 of 14

Anonymous
Not applicable
Hello again,

so, i do not know exactly the mates you have, but you can make an Angular Mate and then you can change the angle of it through Macro.

In this case, you do not need to use transformation matrix.

:-)

Bye.
Luizoo from Brazil
0 Likes
Message 13 of 14

Anonymous
Not applicable
Hi thats good suggestion, Iam about to post that , i tried to rotate through the angle constraint its rotating as i desired . thanks for u r timely suggestion.
0 Likes
Message 14 of 14

Anonymous
Not applicable
Ok, Goooood.

Luizoo from Brazil
0 Likes