Insert ipart from listbox

Insert ipart from listbox

jplujan
Advocate Advocate
480 Views
3 Replies
Message 1 of 4

Insert ipart from listbox

jplujan
Advocate
Advocate

Hello I hope that they can help me:

 

I have listbox that shows ipartname of one ipartfactory it would like and me that when selecting one of them it could send to the assembly ipart selected hear show code.

Dim InvApp As Inventor.Application
Set InvApp = GetObject(, "Inventor.Application")
 
Dim IpartSeleccion As ipartMember
Set  IpartSeleccion = listbox1.Value
       

Dim oDoc As AssemblyDocument
Set oDoc = InvApp.ActiveDocument
        
Dim oOccs As ComponentOccurrences
Set oOccs = oDoc.ComponentDefinition.Occurrences
        
Dim oPos As Matrix
Set oPos = InvApp.TransientGeometry.CreateMatrix
      
Dim oStep As Integer
oStep = 10
        
Dim iRow As Object
iRow = listbox1.Selected
                
' Add a translation along X axis
oPos.SetTranslation (InvApp.TransientGeometry.CreateVector(oStep, oStep, 0))
 
Dim oOcc As ComponentOccurrence
        
oOcc = oOccs.AddiPartMember("C:\Temp\Abarcon generales.ipt", oPos, iRow)
        

MsgBox (listbox1.Value)        

 Thanks in advance

 

 

0 Likes
481 Views
3 Replies
Replies (3)
Message 2 of 4

jplujan
Advocate
Advocate

Hi:

 

As I can look for the name in one iparfactory?

 

Set oOcc = oOccs.AddiPartMember("C:\Temp\ipart.ipt", oPos, ["membername & " = " & selectedvariable"])

 

 

 

Thanks

0 Likes
Message 3 of 4

Dennis.Ossadnik
Autodesk Support
Autodesk Support

Hi jplujan.

 
The property "Selected" returns a Boolean if a specific row is selected or not. (It does not return the row (as Long) which is selected)
If your list is filled with the exact names of the members you could use it this way:
 
Dim SelectedMember As String
SelectedMember = listBox1.Value

Set oOcc = oOccs.AddiPartMember("C:\Temp\Abarcon generales.ipt", oPos, SelectedMember)

 

 
Hope this helps.
 


Dennis Ossadnik
Senior Technical Support Specialist
0 Likes
Message 4 of 4

jplujan
Advocate
Advocate

Thanks for the answer, in the end I believe I have solved that it putting in listbox the index of the row and passing this one to the commando to insert, not if it could cause some problem to me

 

 

 

Private Sub button1_Click()
     
    Dim InvApp As Inventor.Application
     Set InvApp = GetObject(, "Inventor.Application")
     
    ' Open the factory document invisible.
    Dim oFactoryDoc As PartDocument
    Set oFactoryDoc = InvApp.Documents.Open("C:\Temp\Abarcon generales.ipt", False)

    ' Set a reference to the component definition.
    
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oFactoryDoc.ComponentDefinition
    
    ' Set a reference to the factory.
    Dim oiPartFactory As iPartFactory
    Set oiPartFactory = oCompDef.iPartFactory

    ' Get the number of rows in the factory.
    Dim iNumRows As Integer
    iNumRows = oiPartFactory.TableRows.Count
    


    Dim oStep As Integer
    oStep = 0#
    Dim irow As Integer
    
    
    
    For irow = 1 To iNumRows
        oStep = oStep + 10

        Dim nombre As String
        nombre = CStr(oiPartFactory.TableRows(irow).MemberName)
        
        Dim elementos As Variant
        Dim indice As String
        Dim fila As String
        elementos = Array(irow, oStep)
        indice = elementos(0)
        fila = elementos(1)
        
        listbox1.AddItem (irow & ";" & nombre)
        
  
        
    Next


End Sub



Private Sub Button2Click_Click()

        Dim InvApp As Inventor.Application
        Set InvApp = GetObject(, "Inventor.Application")
             
        ' Get the active assembly document
        Dim oDoc As AssemblyDocument
        Set oDoc = InvApp.ActiveDocument
        
        Dim oOccs As ComponentOccurrences
        Set oOccs = oDoc.ComponentDefinition.Occurrences
        
        Dim oFactoryDoc As PartDocument
        Set oFactoryDoc = InvApp.Documents.Open("C:\Temp\Abarcon generales.ipt", False)

        ' Set a reference to the component definition.
        Dim oCompDef As PartComponentDefinition
        Set oCompDef = oFactoryDoc.ComponentDefinition
    
        ' Set a reference to the factory.
        Dim oiPartFactory As iPartFactory
        Set oiPartFactory = oCompDef.iPartFactory
      
        Dim oStep As Double
        oStep = 10#
        
        Dim SeleccionIpart As Integer
        SeleccionIpart = listbox1.Column(0)
        
           
             
        'Dim nombre As iPartMember
        'Set nombre = oCompDef.iPartMember.Row
        
        Dim oPos As Matrix
        Set oPos = InvApp.TransientGeometry.CreateMatrix
                
        'Add a translation along X axis
        oPos.SetTranslation InvApp.TransientGeometry.CreateVector(oStep, oStep, 0)

        
        Dim oOcc As ComponentOccurrence
        
        Set oOcc = oOccs.AddiPartMember("C:\Temp\Abarcon generales.ipt", oPos, SeleccionIpart)
        
       
        MsgBox ("Ipt inserted")


        
End Sub

Thanks

 

0 Likes