Placed part hangs on cursor

Placed part hangs on cursor

Anonymous
Not applicable
376 Views
2 Replies
Message 1 of 3

Placed part hangs on cursor

Anonymous
Not applicable

Could anybody tell me how to change this code so that a placed part does not get placed on 50,50,50, but hangs on my mouse cursor, so i can point where the part has to be inserted/placed? 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)

oOcc.Grounded = False
ThisDoc.Document.SelectSet.Select(oOcc)
0 Likes
377 Views
2 Replies
Replies (2)
Message 2 of 3

GeorgK
Advisor
Advisor

@Anonymous

 

You can use this:

 

https://modthemachine.typepad.com/my_weblog/2015/12/placing-a-part-in-inventor-with-user-interaction.html

 

Public Sub PlacePartInteractive() 
    ' Define the filename to place.
    Dim filename As String
    filename = "C:\Temp\PartTest_2016.ipt" 

    ' Post the filename to the private event queue.
    Dim cmdMgr As CommandManager
    Set cmdMgr = ThisApplication.CommandManager
    Call cmdMgr.PostPrivateEvent(kFileNameEvent, filename)

    ' Execute the "Place Component" command.
    cmdMgr.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
End Sub
Message 3 of 3

Anonymous
Not applicable

Thank you. I tried to paste it into this working code but got some errors. I don't have enough knowledge to make such modification in iLogic myself. I think your code is some kind of a function that need it's own module? and be called from the code I have with some arguments...? Many thank for helping!

 

Imports System.IO
GetInput :

Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 000000)

If Six_Digit = "" Then
	Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
GoTo GetInput

End If


Dim oDoc As Document
Dim sFilename As String

'hard code path
oLibrary_Folder = "C:\Part_Library\"


Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)

For Each oFilename As String In oFilenames
	If oFilename.Contains(Six_Digit) Then
		Dim oOptions As Inventor.NameValueMap
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
		sFilename = oFilename
		Exit For
	End If
Next

If sFilename = "" Then
	MessageBox.Show("No matching libary file found.", "iLogic")
	Return
End If

iCounter = 0

'path from current file
oActiveAssemblyfolder = ThisDoc.Path & "\"

'path from current project file ( *.ipj)
oProjectfolder = _
ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath & "\"

Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories)

'count existing project files					  
For Each oFilename As String In oProject_Filenames
	If oFilename.Contains(Six_Digit) Then
		iCounter = iCounter + 1
	End If
Next

'increment counter
iCounter = iCounter + 1


'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", - 1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)


If iCounter < 10 Then
	iCounter = "00" + CStr(iCounter)
ElseIf iCounter < 100 Then
	iCounter = "0" + CStr(iCounter)
Else
	iCounter = CStr(iCounter)
End If

oNewName = ShortName & "_" & iCounter

oPathandName = oActiveAssemblyfolder & oNewName & oExt

'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close

'[ 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)

']

'MessageBox.Show("New file created: " & vbLf & oPathandName, "iLogic")
0 Likes