iLogic: Move body from point to coordinate

iLogic: Move body from point to coordinate

Anonymous
Not applicable
969 Views
4 Replies
Message 1 of 5

iLogic: Move body from point to coordinate

Anonymous
Not applicable

Hi,

I download lots of part pneumatic fitting to complete our library, but the origin is not very usable.

I would like to write a script to move the body from a selected point to the origin.

Is there a way in iLogic to "ask" the user to click on the point of the body that need to move from.

For now, Is use the Move body function after measuring the distance (X,Y,Z) between the origin and the point to move from.

I know that I can use the Features.MoveFeatures, but I don't know how to give to inventor the right point.

You don't need to give me all the code, I just the function to input the point. I will base my code on this post : https://forums.autodesk.com/t5/inventor-customization/ilogic-move-bodies/td-p/7294463

I will post the code here afterward.

Thanks!

0 Likes
Accepted solutions (1)
970 Views
4 Replies
Replies (4)
Message 2 of 5

clutsa
Collaborator
Collaborator

Something like this will work if the point already exists.

Dim myPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Select Point to set as origin:")
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 5

Anonymous
Not applicable

@clutsaThanks!

I works like a charm, but...

The point I need to select is the center of an arc.

Do you know if there is a way to select this kind of point?

We can select it using the Measure tool.

0 Likes
Message 4 of 5

clutsa
Collaborator
Collaborator
Accepted solution
Dim myPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Select Point to set as origin:")

Delete the text in red and type in a "k" and you will get a list of suggested filters (you may have to delete the "." and type it back in too) but there are a ton of options to filter on, I'm sure you'll find what you need.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 5

Anonymous
Not applicable

Here the code :

'On vérifie que le document est bien une pièce
If Not ThisApplication.ActiveDocument.DocumentType = kPartDocumentObject Then
	MessageBox.Show("Ce document n'est pas un assemblage", "Representation par défaut", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Return
End If

' Ce document (assemblage)
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim myVertex = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select Point or circular to set as origin:")

ButtonClicked = MessageBox.Show("Rotation autour d'un axe?", "Déplacement d'un corps", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
'OUI 6 - NON = 7
Dim myAxe

If ButtonClicked = 6 Then
	oRotation = True
	myAxe = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllLinearEntities, "Select rotation axe:")
	oRotationAngle = InputBox("Angle de rotation", "Déplacement d'un corps", "90")
Else
	oRotation = False
End If

Dim myPoint
Dim oEdgeCollection
Dim oWorkPoints As WorkPoints = oCompDef.WorkPoints
Dim i As Long

If myVertex.Type = 67120432 Then 'Point
	myPoint = myVertex.Point
Else If myVertex.Type = 67120176 Then 'Edge
	oWorkPoints.AddAtCentroid(myVertex)
	i = oWorkPoints.Count
	Try
		myPoint = oWorkPoints.Item(i).Point
		oWorkPoints.Item(i).Delete
	Catch
		MessageBox.Show("Seulement une courbe ou un point peuvent être sélectionnés." & vbCrLf & "Abandon du script", "TEST TEST TEST", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	End Try
Else
	MessageBox.Show("Seulement une courbe ou un point peuvent être sélectionnés." & vbCrLf & "Abandon du script", "TEST TEST TEST", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Return
End If

Dim oBodies As ObjectCollection
oBodies = ThisApplication.TransientObjects.CreateObjectCollection

' Specify a body to move.
oBodies.Add(oCompDef.SurfaceBodies(1))

' Create a MoveFeatureDefinition.
Dim oMoveDef As MoveDefinition
oMoveDef = oCompDef.Features.MoveFeatures.CreateMoveDefinition(oBodies)

oRangeBox = oBodies.Item(1).RangeBox

oMidX = -1*myPoint.X
oMidY = -1*myPoint.Y
oMidZ = -1*myPoint.Z
' the move operations onto the bodies.
Dim oFreeDrag As FreeDragMoveOperation
oFreeDrag = oMoveDef.AddFreeDrag(oMidX, oMidY, oMidZ)

'Dim oMoveAlongRay As MoveAlongRayMoveOperation
'oMoveAlongRay = oMoveDef.AddMoveAlongRay(oCompDef.WorkAxes(2), True, 2)

If oRotation = True Then
	Dim oRotateAboutAxis As RotateAboutLineMoveOperation
	oRotateAboutAxis = oMoveDef.AddRotateAboutAxis(myAxe, True, oRotationAngle*(PI/180))
End If

' Create the move feature.
Dim oMoveFeature As MoveFeature
oMoveFeature = oCompDef.Features.MoveFeatures.Add(oMoveDef)
ThisApplication.ActiveView.Fit