Place specific inventor file in assembly

Place specific inventor file in assembly

anilkumar279
Enthusiast Enthusiast
747 Views
2 Replies
Message 1 of 3

Place specific inventor file in assembly

anilkumar279
Enthusiast
Enthusiast

Hi,
I have a code from which I can place and constraint component in assemble constrained with origin.

 

I want to modify select file box to specific file.

Please help me.

 

 

 

Thank you

 

 

 

SyntaxEditor Code Snippet

'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("YZ Plane") 'Component YZ Plane
 oPartPlane2 =  oOccurrence.Definition.WorkPlanes.Item("XZ Plane") 'Component XZ Plane
 oPartPlane3 =  oOccurrence.Definition.WorkPlanes.Item("XY Plane") 'Component XY Plane
 oPartPlane4 =  oOccurrence.Definition.WorkPlanes.Item("XY Plane") '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("YZ Plane") 'Assembly YZ Plane
 oAsmPlane2 = oAsmCompDef.WorkPlanes.Item("XZ Plane") 'Assembly XZ Plane
 oAsmPlane3 = oAsmCompDef.WorkPlanes.Item("XY Plane") '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)
oOccurrence.CreateGeometryProxy(oPartPlane4, oAsmPlane7)
' Create the constraint using the part work plane proxies.

oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane1, oAsmPlane4, 0)
oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane2, oAsmPlane5, 0)
oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane3, oAsmPlane6, 0)
'oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane3, oAsmPlane7, 0)'zoom all
ThisApplication.ActiveView.Fit
oDoc = ThisDoc.Document


0 Likes
Accepted solutions (1)
748 Views
2 Replies
Replies (2)
Message 2 of 3

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @anilkumar279,

 

 

Correct me if I am wrong, "adding a file to assembly by specifying file path". If that is the case, try the following iLogic code and specify the file path before using the code.

 

If not, can you please explain the requirement with screenshots?

 

' 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("Path of specific file", 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("YZ Plane") 'Component YZ Plane
 oPartPlane2 =  oOccurrence.Definition.WorkPlanes.Item("XZ Plane") 'Component XZ Plane
 oPartPlane3 =  oOccurrence.Definition.WorkPlanes.Item("XY Plane") 'Component XY Plane
 oPartPlane4 =  oOccurrence.Definition.WorkPlanes.Item("XY Plane") '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("YZ Plane") 'Assembly YZ Plane
 oAsmPlane2 = oAsmCompDef.WorkPlanes.Item("XZ Plane") 'Assembly XZ Plane
 oAsmPlane3 = oAsmCompDef.WorkPlanes.Item("XY Plane") '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)
oOccurrence.CreateGeometryProxy(oPartPlane4, oAsmPlane7)
' Create the constraint using the part work plane proxies.

oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane1, oAsmPlane4, 0)
oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane2, oAsmPlane5, 0)
oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane3, oAsmPlane6, 0)
'oConstraint = oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane3, oAsmPlane7, 0)'zoom all
ThisApplication.ActiveView.Fit
oDoc = ThisDoc.Document

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 3

anilkumar279
Enthusiast
Enthusiast

Thank you!

0 Likes