Placing and rotating parts around multiple axis

Placing and rotating parts around multiple axis

Thomas.Long
Advocate Advocate
291 Views
0 Replies
Message 1 of 1

Placing and rotating parts around multiple axis

Thomas.Long
Advocate
Advocate

I have a function that is meant to place a part, rotate and move it to its proper placement, then ground it there. However, I'm having a bit of an issue with my rotation portion of the function. It appears that its either flipping it 180 degrees or doing nothing at all in all three directions. If I try to rotate it three different times however, it just uses the final rotation and ignores the other 2. How do I get it to rotate different angles for all 3 axis?



'Places, rotates and grounds component '////////////////////////////////////////////////// Public Function PlaceComponent(Part As String, X As Double, Y As Double, Z As Double, XYRotation As Double, XZRotation As Double, YZRotation As Double) 'Select component to be placed '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ InventorVb.RunMacro("ApplicationProject","Place_Part","Place_Part", Part) '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Dim FileNameArray() As String = Part.Split("\") Dim PartName() As String = FileNameArray(UBound(FileNameArray)).Split(".") 'Set Active Assembly Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument 'Assembly definition Dim oAsmDef As AssemblyComponentDefinition oAsmDef = oAsmDoc.ComponentDefinition 'Component definition Dim oOcc As ComponentOccurrence 'Get all leaf occurrences of the assembly Dim oLeafOccs As ComponentOccurrencesEnumerator oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 'Latest occurrrence holder Dim MaxValue MaxValue = 0 'Name of Latest Occurrence Dim Name As String Name = "" 'Iterate through all Of the occurrence In this collection, finds the latest occurrence, And sets it To reference Dim Instances As New ArrayList For Each oOcc In oLeafOccs Dim oOccPart() As String = oOcc.Name.Split(":") If oOccPart(0) = PartName(0) Then Instances.add(oOcc.Name) Next For Each oval in Instances Dim InstanceNumber() As String = oOcc.Name.Split(":") If InstanceNumber(1) > MaxValue Then Name = oval Next For Each oOcc In oLeafOccs If oOcc.Name = Name oOcc.Grounded = False Dim uom As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure Dim convFactor As Double = uom.ConvertUnits(1.0, uom.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits) ' Get the current transformation matrix from the occurrence. Dim oTransform As Matrix = oOcc.Transformation Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry XYRotationRadian = XYRotation*PI/180 XZRotationRadian = XZRotation*PI/180 YZRotationRadian = YZRotation*PI/180 ' Move the occurrence ignoring any constraints. oTransform.SetToRotation(PI, oTG.CreateVector(XYRotationRadian, XZRotationRadian, YZRotationRadian), oTG.CreatePoint(X / 10, Y / 10, Z / 10)) oTransform.SetTranslation(ThisApplication.TransientGeometry.CreateVector(X*convFactor, Y*convFactor, Z*convFactor)) oOcc.SetTransformWithoutConstraints(oTransform) ' ground the component oOcc.Grounded = True End If Next End Function
0 Likes
292 Views
0 Replies
Replies (0)