
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everybody,
I am trying to constraint two work plan of two part ( Pièce:1 and Pièce2:1) inside a the subassembly (Test:1):
When I open "Test:1" like this:
I select in Inventor the two parts and I launch this code and it is working:
Public Sub TestSub1() Dim oMainAsmDoc As AssemblyDocument Set oMainAsmDoc = ThisApplication.ActiveDocument Dim oSelectedObject As ComponentOccurrence Dim oSelectedObject2 As ComponentOccurrence Set oSelectedObject = oMainAsmDoc.SelectSet.Item(1) Set oSelectedObject2 = oMainAsmDoc.SelectSet.Item(2) Dim oSelectedObjectPlaneYZ As WorkPlane Dim oSelectedObject2PlaneYZ As WorkPlane Set oSelectedObjectPlaneYZ = oSelectedObject.Definition.WorkPlanes.Item(1) 'YZ Set oSelectedObject2PlaneYZ = oSelectedObject2.Definition.WorkPlanes.Item(1) 'YZ Dim oSelectedObjectPlaneYZProxy As WorkPlaneProxy Dim oSelectedObject2PlaneYZProxy As WorkPlaneProxy Call oSelectedObject.CreateGeometryProxy(oSelectedObjectPlaneYZ, oSelectedObjectPlaneYZProxy) Call oSelectedObject2.CreateGeometryProxy(oSelectedObject2PlaneYZ, oSelectedObject2PlaneYZProxy) ShowProxyPath oSelectedObjectPlaneYZ ShowProxyPath oSelectedObjectPlaneYZProxy Set Contraintes = oMainAsmDoc.ComponentDefinition.constraints Call Contraintes.AddMateConstraint(oSelectedObject2PlaneYZProxy, oSelectedObjectPlaneYZProxy, 50) End Sub
But now when I am in the context of "Ensemble1:1" like the first picture when I launch the code it doesn't work because I don't have created the geometry proxy to the top assembly.
I tried like this :
Public Sub TestSub3() Dim oAssemblyLevel0 As AssemblyDocument Set oAssemblyLevel0 = ThisApplication.ActiveDocument Dim oSelectedObjectLevel2 As ComponentOccurrence Dim oSelectedObject2Level2 As ComponentOccurrence Set oSelectedObjectLevel2 = oAssemblyLevel0.SelectSet.Item(1) Set oSelectedObject2Level2 = oAssemblyLevel0.SelectSet.Item(2) Dim oSelectedObjectLevel2PlaneYZ As WorkPlane Dim oSelectedObject2Level2PlaneYZ As WorkPlane Set oSelectedObjectLevel2PlaneYZ = oSelectedObjectLevel2.Definition.WorkPlanes.Item(1) 'YZ Set oSelectedObject2Level2PlaneYZ = oSelectedObject2Level2.Definition.WorkPlanes.Item(1) 'YZ Dim PlaneYZForProxyForLevel1 As WorkPlaneProxy Dim Plane2YZForProxyForLevel1 As WorkPlaneProxy Call oSelectedObjectLevel2.CreateGeometryProxy(oSelectedObjectLevel2PlaneYZ, PlaneYZForProxyForLevel1) Call oSelectedObject2Level2.CreateGeometryProxy(oSelectedObject2Level2PlaneYZ, Plane2YZForProxyForLevel1) Set oAssemblyLevel1 = oAssemblyLevel0.ComponentDefinition.Occurrences.ItemByName("Test:1") Dim PlaneYZProxyForLevel0 As WorkPlaneProxy Dim Plane2YZProxyForLevel0 As WorkPlaneProxy Call oAssemblyLevel1.CreateGeometryProxy(PlaneYZForProxyForLevel1, PlaneYZProxyForLevel0) Call oAssemblyLevel1.CreateGeometryProxy(Plane2YZForProxyForLevel1, Plane2YZProxyForLevel0) Set Contraintes = oAssemblyLevel0.ComponentDefinition.constraints Call Contraintes.AddMateConstraint(PlaneYZProxyForLevel0, Plane2YZProxyForLevel0, 50) End Sub
But I got an error on the line :
Call Contraintes.AddMateConstraint(PlaneYZProxyForLevel0, Plane2YZProxyForLevel0, 50)
I also tried to edit "Test:1" in the assembly "Ensemble1.iam" when runing the code, I get the same error:
I tried many other method to get the correct proxy to put this constraint but I didn't find the good way.
Can someone help me please ?
Thank you for your help in advance !
Jérémie.
Solved! Go to Solution.