- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
it is possible to make an ilogic code that..
1. ask how you want it to move(X,Y,Z)
2. check if the componemt is ground
3 remove ground
4. move componemt
5. reground if componemt was grounded
6. do 2-5 on all componemt
I found this code but it only move one at the time and it does not offset location but set an location. and ground no matter want .. and it use select ... witch is offen very slow . I want to do it withont select an to all componemt on firstlevel. can anyone help with this in ilogic
'check for selection Dim compOcc As ComponentOccurrence Try compOcc = ThisDoc.Document.SelectSet.Item(1) Catch MessageBox.Show("Please select a component before running this rule.", "iLogic") Return End Try ' remove constraints for the selected component Dim oConstraint As AssemblyConstraint For Each oConstraint In compOcc.Constraints oConstraint.Delete Next 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 = compOcc.Transformation X = InputBox("Enter X", "Title", "") Y = InputBox("Enter Y", "Title", "") Z = InputBox("Enter Z", "Title", "") ' Move the occurrence ignoring any constraints. oTransform.SetTranslation(ThisApplication.TransientGeometry.CreateVector(X*convFactor, Y*convFactor, Z*convFactor)) compOcc.SetTransformWithoutConstraints(oTransform) ' ground the component compOcc.Grounded = True
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
.
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
And I see now that you only wanted to input X,Y,Z once. Not for each occurrence.
Final code![]()
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 + oY + 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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