Hello. I'm working on mating two assemblies together by work points on a part inside of them.
Here is the code I'm using. It worked with work planes, but when repurposed it to work points, I get a type mismatch when the code tries to generate the work point proxies:
Dim oPartPoint1 As WorkPoint oPartPoint1 = oOcc1.Definition.WorkPoints.Item("botMatePoint") Dim oPartPoint2 As WorkPoint oPartPoint2 = oOcc2.Definition.WorkPoints.Item("matePoint") Dim oAsmPoint1 As WorkPointProxy oOcc1.CreateGeometryProxy(oPartPoint1, oAsmPoint1) Dim oAsmPoint2 As WorkPointProxy oOcc2.CreateGeometryProxy(oPartPoint2, oAsmPoint2)
Any thoughts?
Thanks
Solved! Go to Solution.
Solved by jdkriek. Go to Solution.
Hi,
That is strange. I have the following assembly and part:
... and this VBA code works fine with it:
Sub GetWorkPointProxy() Dim asm As AssemblyDocument Set asm = ThisApplication.ActiveDocument Dim occ As ComponentOccurrence Set occ = asm.ComponentDefinition.Occurrences(1) Dim wp As WorkPoint Set wp = occ.Definition.WorkPoints("MyWorkPoint") Dim wpp As WorkPointProxy Call occ.CreateGeometryProxy(wp, wpp) MsgBox (wpp.Name) End Sub
Cheers,
Works fine in iLogic as well...
Dim asm As AssemblyDocument = ThisApplication.ActiveDocument Dim occ As ComponentOccurrence = asm.ComponentDefinition.Occurrences(1) Dim wp As WorkPoint = occ.Definition.WorkPoints("MyWorkPoint") Dim wpp As WorkPointProxy occ.CreateGeometryProxy(wp, wpp) MsgBox (wpp.Name)
kakers can you post the rest of your code? Something else is going on.
Try this assembly on for size. This is my whole run of code with a stripped down assembly due to NDA issues.
Thanks so much. Here's some additional insight from Mike Deck:
I did get the type mismatch error, and I found a solution. All the changes are in this block of code:
If DEBUGMSGS Then MsgBox("Grabbing Current Comp")
oCurrAssy = Component.InventorComponentInThisContext("MIDASSY" & x)
If DEBUGMSGS Then MsgBox("Grabbing Current Comp Stringer")
Dim oOcc1 As ComponentOccurrenceProxy = oCurrAssy.SubOccurrences.Item(1)
If DEBUGMSGS Then MsgBox("Grabbing Previous Comp")
oPrevAssy = Component.InventorComponentInThisContext("MIDASSY" & x-1)
If DEBUGMSGS Then MsgBox("Grabbing Previous Comp Stringer")
Dim oOcc2 As ComponentOccurrenceProxy = oPrevAssy.SubOccurrences.Item(1)
' Work point from each occurrence. This goes to the
' component definition of the part to get this information.
The main change is to explicitly declare oOcc1 and oOcc2 as ComponentOccurrenceProxy.
I’m not sure exactly why that is required. I think it is because the CreateGeometryProxy method can be used on both a ComponentOccurrence and a ComponentOccurrenceProxy object. It might also work if you declared it as ComponentOccurrence.
The other change is to avoid going to the definition of the subassembly. Instead, use its SubOccurrences property to get to the part. This keeps everything in the context of the assembly that is running the rule.