- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Inventor 2022
API VB.NET VisualStudio
I try to Create a Part in SubAssembly.
Then, i want to Projecting a Curve from Sketch from Other Part.
I Got Error with AddByProjectingEntity
I got 2 PlanrSketchProxy, but they are in Other Assembly, is this ok.
What i need ?
This is my Code:
Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Module CommandFunctionButton_01
Public Sub CommandFunctionfweButton_01()
Dim oAsmDoc As AssemblyDocument = g_inventorApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
'Create Matrix
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
'Create occurence, PartComp.def, Sketch and Proxy for this Sketch
Dim oOccPartA As ComponentOccurrence = oAsmCompDef.Occurrences.ItemByName("Part_A:1")
Dim oPartA_Def As PartComponentDefinition = oOccPartA.Definition
Dim oSketchPartA As PlanarSketch = oPartA_Def.Sketches("Sketch_A")
Dim oSketchPartA_Proxy As PlanarSketchProxy
Call oOccPartA.CreateGeometryProxy(oSketchPartA, oSketchPartA_Proxy)
'Create New Assembly
Dim oNameFile As String = InputBox("text")
Dim oNewAssembly_01 As AssemblyDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject)
oNewAssembly_01.SaveAs("C:\InventorAPI\1780-006\CAD\3D\Assembly_" & oNameFile & ".iam", False)
'Create Assembly occurence
Dim oSubAssyOcc As ComponentOccurrence
oSubAssyOcc = oAsmCompDef.Occurrences.AddByComponentDefinition(oNewAssembly_01.ComponentDefinition, oMatrix)
oNewAssembly_01.Close()
oSubAssyOcc.Edit()
'Create New Assembly Comp.def
Dim oAsmDoc02 As AssemblyDocument
oAsmDoc02 = g_inventorApplication.ActiveEditDocument
Dim oAsmCompDef02 As AssemblyComponentDefinition
oAsmCompDef02 = oAsmDoc02.ComponentDefinition
'Create New Part in New Assembly using New Comp.def
Dim oNameFile2 As String = InputBox("text")
Dim oPartB As PartDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
oPartB.SaveAs("C:\InventorAPI\1780-006\CAD\3D\SheetMetal_Curved_Inside_" & oNameFile2 & ".ipt", False)
Dim oOccPartB As ComponentOccurrence
oOccPartB = oAsmCompDef02.Occurrences.AddByComponentDefinition(oPartB.ComponentDefinition, oMatrix)
oPartB.Close()
'Create New PartComp.def, Sketch and Proxy for this Sketch
Dim oPartB_Def As PartComponentDefinition = oOccPartB.Definition
Dim oSketchPartB As PlanarSketch = oPartB_Def.Sketches.Add(oPartB_Def.WorkPlanes.Item(3), False)
Dim oSketchPartB_Proxy As PlanarSketchProxy
Call oOccPartB.CreateGeometryProxy(oSketchPartB, oSketchPartB_Proxy)
'Select Curve from Part A
Dim oCurve As Object = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveFilter, "Pick a Curve")
'Projecting Curve from Proxy Sketch_A to Proxy Sketch_B
Dim oEnt As SketchEntity
oEnt = oSketchPartB_Proxy.AddByProjectingEntity(oCurve)
oAsmDoc.Update()
End Sub
End Module
Error:
Unknow Error HRESULT: 0x80004005 (E_FAIL))"
Assembly:
When during Creating new Part i choose the AssemblyComponentDef. from Main Assembly, then The New part is not in SubAssembly, but the Projecting is Working good.
Also, when i Delete, the:
Then the part is not add to Subassembly, but the Projecting is Working Good.
My Goal is to Add the Part to New SubAssembly and Projecting the Curve
Do i need any Subassembly Method or ComponentOccurrenceProxy etc... ?
Thanks for Any Suggestion
Solved! Go to Solution.