Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.