06-03-2020
06:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
06-03-2020
06:04 AM
I just realized... If you input for example (10, -10, 0) In this rule nothing will happen. I thought it was a shortcut to determine if any value <> 0 to put If oX + oY + oZ <> 0. Because the sum of the values can be zero even though all of them isn't 0 this could result in the code doing nothing when it should be moving the occurrences.
This is the way to go...
Dim oAsm As AssemblyDocument = ThisDoc.Document Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oUM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure Dim xyz As String = InputBox("Move component X,Y,Z", "Move this component", "0,0,0") Dim oX As Double = oUM.ConvertUnits(CDbl(xyz.Split(",")(0)), oUM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits) Dim oY As Double = oUM.ConvertUnits(CDbl(xyz.Split(",")(1)), oUM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits) Dim oZ As Double = oUM.ConvertUnits(CDbl(xyz.Split(",")(2)), oUM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits) If oX <> 0 Or oY <> 0 Or oZ <> 0 For Each oComp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences Dim Grounded As Boolean = oComp.Grounded If Grounded = True Then oComp.Grounded = False Dim oVector As Vector = oTG.CreateVector(oX, oY, oZ) Dim oMatrix As Matrix = oComp.Transformation.Copy oVector.AddVector(oMatrix.Translation) oMatrix.SetTranslation(oVector, False) oComp.Transformation = oMatrix oComp.Grounded = Grounded Next End If InventorVb.DocumentUpdate()
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website