insert on mouse position

insert on mouse position

Anonymous
Not applicable
1,371 Views
5 Replies
Message 1 of 6

insert on mouse position

Anonymous
Not applicable

Could anyone help me to modify this code, so a new part enters in the assembly where the mouse cursor is at that moment instead of on point 50,50,50?

 

Many thank

 

'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)


'insert new occurence
Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.Occurrences.Add( _
oPathandName, oMatrix)

oOcc.Grounded = False
ThisDoc.Document.SelectSet.Select(oOcc)

']
Accepted solutions (1)
1,372 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

Or that it "hangs" on my mouse and is placed where I click in the assmebly....

0 Likes
Message 3 of 6

Sergio.D.Suárez
Mentor
Mentor

Try a code like this, add the dialog box to select the piece and try it, but you just have to put the last lines and identify the selected file

 

Dim oFileDlg As Inventor.FileDialog
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
oFileDlg.FilterIndex = 1
oFileDlg.DialogTitle = "Select Part or Asssembly"
oFileDlg.InitialDirectory = ThisDoc.Path
oFileDlg.InsertMode = False
oFileDlg.MultiSelectEnabled = False
oFileDlg.SuppressResolutionWarnings = True
oFileDlg.CancelError = False
oFileDlg.ShowOpen()

If Err.Number <> 0 Then
MessageBox.Show("File not chosen.", "Dialog Cancellation")
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
MessageBox.Show("File " & selectedfile & " was selected.", "Dialog Selection Made")
End If




ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,selectedfile)   ' for example   "\\samba\diseño\Inventor\530 CABALLETES\530.09_D\530.09D.05.12 Parante B.ipt"

ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute

 I hope I can help you, regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 4 of 6

Anonymous
Not applicable

Thank you, but the part is already (automatically) chosen.

0 Likes
Message 5 of 6

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

If I understand, that's why I told you to take the line below, and put your "oPathandName" and I think it will do what you need

 

oPathandName = "\\samba\diseño\Inventor\530 CABALLETES\530.09_D\530.09D.05.12 Parante B.ipt"

ThisApplication
.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oPathandName) ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 6 of 6

Anonymous
Not applicable

i added those 2 lines to my code and removed a few from the original and it seems to work. many Thanks!

 

'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)


'insert new occurence
'Dim oOcc As ComponentOccurrence
'oOcc = oAsmCompDef.Occurrences.Add( _
'oPathandName, oMatrix)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oPathandName) 
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute


'oOcc.Grounded = False
'ThisDoc.Document.SelectSet.Select(oOcc)

']
0 Likes