Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JhoelForshav
in reply to: JhoelForshav

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()