run ilogic rule to trigger mouse selection and perform a action

run ilogic rule to trigger mouse selection and perform a action

Anonymous
Not applicable
1,389 Views
3 Replies
Message 1 of 4

run ilogic rule to trigger mouse selection and perform a action

Anonymous
Not applicable

Hi, I am trying to put together a iLogic script that will perform this:

 

I want to select many inserted parts (unconstrained) in a assembly (with mouse) then run the flush to origin script I found in other sections of this forum

 

Im quite new to iLogic, but have tried to alter this script to perform the actions I want.

 

Any suggestions?

 

I dont want the script to insert a new part as this one do:

 

Trigger = iTrigger0
'get file to place
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.DialogTitle = "Select a File"
oFileDlg.InitialDirectory = ThisDoc.Path
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
MessageBox.Show("File not chosen.", "Dialog Cancellation")
Return
ElseIf oFileDlg.FileName <> "" Then
oFile = oFileDlg.FileName
End If

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
    
' Create a matrix.  
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix

'place an instance of the component 
Dim oOccurrence As ComponentOccurrence
oOccurrence = oAsmCompDef.Occurrences.Add(oPath & oFile, oMatrix) 
' Set the translation portion of the matrix so the part will be 
'positioned at the co-ordinates
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0)) 

'check for grounded component, such as the first component in the assembly
If oOccurrence.Grounded = True Then
    oGrounded = MessageBox.Show("Should this component be grounded?", _
    "iLogic",MessageBoxButtons.YesNo)
    If oGrounded = vbNo Then
    oOccurrence.Grounded = False
    Else 
    End If
End If

'Get the plane from the selected part.
' The work plane obtained is in the context of the part, not the assembly.
Dim oPartPlane1 As WorkPlane
Dim oPartPlane2 As WorkPlane
Dim oPartPlane3 As WorkPlane
 oPartPlane1 =  oOccurrence.Definition.WorkPlanes.Item(1) 'Component YZ Plane
 oPartPlane2 =  oOccurrence.Definition.WorkPlanes.Item(2) 'Component XZ Plane
 oPartPlane3 =  oOccurrence.Definition.WorkPlanes.Item(3) 'Component XY Plane

 'Get the plane from the assembly
Dim oAsmPlane1 As WorkPlane
Dim oAsmPlane2 As WorkPlane
Dim oAsmPlane3 As WorkPlane
 oAsmPlane1 = oAsmCompDef.WorkPlanes.Item(1) 'Assembly YZ Plane
 oAsmPlane2 = oAsmCompDef.WorkPlanes.Item(2) 'Assembly XZ Plane
 oAsmPlane3 = oAsmCompDef.WorkPlanes.Item(3) 'Assembly XY Plane

' Create proxies for the work planes of the part.
' The proxies represent the part work planes in the context of the assembly.
Dim oAsmPlane4 As WorkPlaneProxy
Dim oAsmPlane5 As WorkPlaneProxy
Dim oAsmPlane6 As WorkPlaneProxy
oOccurrence.CreateGeometryProxy(oPartPlane1, oAsmPlane4)
oOccurrence.CreateGeometryProxy(oPartPlane2, oAsmPlane5)
oOccurrence.CreateGeometryProxy(oPartPlane3, oAsmPlane6)

 

I found the script to perform mouse selection, but have not been able to combine them

 

 

'get file to place
Dim doc = ThisApplication.ActiveDocument

Dim entity = ThisApplication.CommandManager.Pick(
	SelectionFilterEnum.kAssemblyOccurrenceFilter, 
	"Select Component:")

If (Not entity Is Nothing) Then
	MsgBox(entity.Name)
End If

 

0 Likes
1,390 Views
3 Replies
Replies (3)
Message 2 of 4

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

I've just written a blog post which I hope will help you with combining selection and the rest of your code: http://adndevblog.typepad.com/manufacturing/2013/11/do-selection-from-ilogic.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 4

Anonymous
Not applicable

Great code thx.

But I have not been able to implement the code to replace the openfile commands 😞

 

Guess I will try some more 🙂

0 Likes
Message 4 of 4

Anonymous
Not applicable

It sounds like you want to constrain all selected parts to the origin. Basically take the orgin plans of the part and constrain it to the origin of the assembly? If so, use the Ground and Root Component tool from the Productivity panel. This tool will only do one part at a time tho but once you've use it select the next part in the browser or onscreen and press Enter (repeats command).

0 Likes