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

Sorry @Darkforce_the_ilogic_guy 

I read to fast... You want to move the occurrence from previous position. at first  I posted a code that just set a new position aswell. Thats why there's an empty post above...

 

This should do the trick!

 

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oSelSet As SelectSet = oAsm.SelectSet
oSelSet.Clear
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oUM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
For Each oComp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
	oSelSet.Select(oComp)
	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 + oY + oZ <> 0
		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
	End If
	oSelSet.Clear
	InventorVb.DocumentUpdate()
Next