- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In order to make laying out large projects, I'm trying to make a program that will allow us to rotate ground parts with respect to an origin axis, but keep their relative position. I have tried using a couple of the matrix operations, but they are not functioning as expected.
As in below, I have created a dummy from vector in the context of the assembly, and then use an angle to set a dummy to vector on the same flat plane. However, every time I run this rule, the transformation instead changes the matrix to align the horizontal planes of both occurrences, whereas I just want the rotation to be as per the given orientation. (Every time I run the rule, it performs 2 rotations, instead of the 1 rotation I am looking for.)
Sub Main() Dim oDoc As Document oDoc = ThisApplication.ActiveDocument Dim oOcc As ComponentOccurrence Dim oSelectSet As SelectSet oSelectSet = oDoc.SelectSet If oSelectSet.Count = 1 oOcc = oSelectSet.Item(1) Else MsgBox("Invalid Selection Set!" & vbLf & vbLf & "Aborting rule!") Exit Sub End If r = InputBox("Set values of relative rotation of occurence in context of assembly:", "Rotation", "0") Call RotateOccurrence(oDoc, oOcc, r, "Y") End Sub Sub RotateOccurrence(oAsmDoc As Document, oOcc As ComponentOccurrence, oRotationDeg As Double, oAxis As String) Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Select Case True Case oAxis = "X" oAsmAxis = oAsmDoc.ComponentDefinition.WorkAxes.Item(1) Case oAxis = "Y" oAsmAxis = oAsmDoc.ComponentDefinition.WorkAxes.Item(2) Case oAxis = "Z" oAsmAxis = oAsmDoc.ComponentDefinition.WorkAxes.Item(3) Case Else MsgBox("Error in fectching Asm Axis") Exit Sub End Select oOcc.CreateGeometryProxy(oOcc.Definition.WorkPoints.Item(1), oCenterPointProxy) Dim oOccTransform As Matrix = oOcc.Transformation Dim oTransVec As Vector = oOccTransform.Translation Dim oFromVector As Vector = oTG.CreateVector(1,0,0) Dim oToVector As Vector = oTG.CreateVector(Math.Cos(oRotationDeg*Math.PI/180), 0, Math.Sin(oRotationDeg*Math.PI/180)) oOccTransform.SetToRotateTo(oFromVector,oToVector, oAsmAxis.Line.Direction.AsVector) oOccTransform.SetTranslation(oTransVec, False) oOcc.SetTransformWithoutConstraints(oOccTransform) End Sub
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
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
Solved! Go to Solution.