I have reposted this here with a more descriptive title:
From Malcolm:
I have found the answer to the CreateGeometryProxy problem but the AddFlushConstraint is fhrowing an error "The parameter is incorrect.
Screen shot attached and the code below.
I would realy like some help with ths as it realy holding me up.
Regards Malcolm
Public
Function ConstrainPart(ByVal oOcc As Inventor.ComponentOccurrence, ByRef oFace1 As Inventor.Face, ByRef oFace2 AsInventor.Face, ByVal Offset AsInteger) AsBoolean' Make sure the occurrence is not grounded.If oOcc.Grounded Then
oOcc.Grounded =
FalseEndIf' Get the component definition of the occurrence. This could be a' part or assembly component definition depending on if the occurrence' is a part or subassembly.Dim oOccDef AsInventor.PartComponentDefinition
oOccDef = oOcc.Definition
' Get the assembly component definition. This assumes the occurrence is' is with respect to the top-level assembly.Dim oAsmDefAsInventor.AssemblyComponentDefinition
oAsmDef = oOcc.ContextDefinition
' Create a proxy for this work plane.Dim oOccFaceProxy As Inventor.FaceProxy = NothingTry
oOcc.CreateGeometryProxy(oFace1,
CType(oOccFaceProxy, FaceProxy))
Catch ex AsException
MsgBox(
"Proxy 1 "& ex.Message)
EndTry' Create the constraint.Try
oAsmDef.Constraints.AddFlushConstraint(oAsmDef.WorkPlanes.Item(1), oOccFaceProxy, 0)
Catch ex AsException
MsgBox(
"Move "& ex.Message)
EndTryTry
oOcc.CreateGeometryProxy(oFace2,
CType(oOccFaceProxy, FaceProxy))
Catch ex AsException
MsgBox(
"Proxy 1 "& ex.Message)
EndTry' Create the constraint.Try
oAsmDef.Constraints.AddFlushConstraint(oAsmDef.WorkPlanes.Item(2), oOccFaceProxy, Offset)
Catch ex AsException
MsgBox(
"Move "& ex.Message)
EndTry
ConstrainPart =
TrueEndFunction
To add to and explain malcolms post further, I believe the problem occurs when the user input for selecting the faces is required to constrain to the origin plane. I believe this did worked as a VBA macro, but now the code has been converted over to an Add-in we can't get it to work.
Essentially without being able to get this to work, we aren't able to create any addins which require onscreen interaction between the user and components and faces etc..
To push forward we really need some help with this either from Autodesk or one of the many programming legends who frequent this forum.
cheers
Scott
Scott Moyse
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
RevOps Strategy Manager at Toolpath. New Zealand based.
Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project