CreateGeometryProxy

CreateGeometryProxy

Anonymous
Not applicable
5,105 Views
10 Replies
Message 1 of 11

CreateGeometryProxy

Anonymous
Not applicable

I am trying to get a number of parts into an assembly and constrain then the two origin planes, however the line "Call oOcc.CreateGeometryProxy(oFace1, oOccFaceProxy)" is causing an error.

 

Any help would be appreciated.

 

Public Function ConstrainPart(oOcc As ComponentOccurrence, ByRef oFace1 As Face, ByRef oFace2 As Face, ByVal Offset As Integer) As Boolean
    ' Make sure the occurrence is not grounded.
    If oOcc.Grounded Then
        oOcc.Grounded = False
    End If
   
    ' 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 As PartComponentDefinition
    Set oOccDef = oOcc.Definition
   
    ' Get the assembly component definition. This assumes the occurrence is
    ' is with respect to the top-level assembly.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oOcc.ContextDefinition

        ' Create a proxy for this work plane.
        Dim oOccFaceProxy As FaceProxy
        Call oOcc.CreateGeometryProxy(oFace1, oOccFaceProxy)
       
        ' Create the constraint.
        Call oAsmDef.Constraints.AddFlushConstraint(oAsmDef.WorkPlanes.Item(1), oOccFaceProxy, 0)

        Call oOcc.CreateGeometryProxy(oFace2, oOccFaceProxy)
        Call oAsmDef.Constraints.AddFlushConstraint(oAsmDef.WorkPlanes.Item(2), oOccFaceProxy, Offset)

    ConstrainPart = True
End Function

0 Likes
Accepted solutions (1)
5,106 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

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 As Inventor.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 oAsmDef AsInventor.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

0 Likes
Message 3 of 11

scottmoyse
Mentor
Mentor

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.


EESignature


RevOps Strategy Manager at Toolpath. New Zealand based.

Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project

0 Likes
Message 4 of 11

Qube-it
Advocate
Advocate

It looks to me like you're missing an "out" parameter in your "AddFlushConstraint" function call.  Keep in mind that you're adding a constraint to the constraints collection of the assembly component definition.

 

Create another variable of type AssemblyConstraint prior to the call to AddFlushConstraint function.  Then pass that variable into the "AddFlushConstraint" function as the last variable.  

 

Hope this helps.

-Brian Hall-
0 Likes
Message 5 of 11

Anonymous
Not applicable
Accepted solution

IMHO you shouldn't use CType in the following command: 

oOcc.CreateGeometryProxy(oFace1, CType(oOccFaceProxy, FaceProxy))

Be careful, your function must verify the angle between oFace1 and oFace2. If this angle <> 90° desired constraint with assembly base workplanes couldn'd be created. 

The following code works in my simple tests.

Cheers.

 

Function ConstrainPart( _
               ByVal oOcc As Inventor.ComponentOccurrence, _
               ByRef oFace1 As Inventor.Face, _
               ByRef oFace2 As Inventor.Face, _
               ByVal Offset As Integer) As Boolean

      ' Make sure the occurrence is not grounded.
      If oOcc.Grounded Then oOcc.Grounded = False

      ' Get the component definition of the occurrence. 
      Dim oOccDef As Inventor.PartComponentDefinition = oOcc.Definition

      ' Get the assembly component definition. 
      ' This assumes the occurrence is with 
      ' respect to the top-level assembly.
      Dim oAsmDef As Inventor.AssemblyComponentDefinition = oOcc.ContextDefinition

      ' Create a proxy for the 1st face
      Dim oOccFaceProxy1 As Inventor.FaceProxy = Nothing
      Try
         'oOcc.CreateGeometryProxy(oFace1, CType(oOccFaceProxy, FaceProxy))
         'previous line produce run-time error
         'next line is correct
         Call oOcc.CreateGeometryProxy(oFace1, oOccFaceProxy1)
      Catch ex As Exception
         MsgBox("Proxy 1 " & ex.Message)
         Return False
      End Try

      Try  ' Create the constraint.
         oAsmDef.Constraints.AddFlushConstraint( _
               oAsmDef.WorkPlanes.Item(1), oOccFaceProxy1, Offset)
      Catch ex As Exception
         MsgBox("Move 1 " & ex.Message)
         Return False
      End Try

      ' Create a proxy for the 2nd face
      Dim oOccFaceProxy2 As Inventor.FaceProxy = Nothing
      Try
         oOcc.CreateGeometryProxy(oFace2, oOccFaceProxy2)
      Catch ex As Exception
         MsgBox("Proxy 2 " & ex.Message)
         Return False
      End Try

      Try ' Create the constraint.
         oAsmDef.Constraints.AddFlushConstraint( _
             oAsmDef.WorkPlanes.Item(2), oOccFaceProxy2, Offset)
      Catch ex As Exception
         MsgBox("Move 2 " & ex.Message)
         Return False
      End Try

      Return True
   End Function

 

 

 

0 Likes
Message 6 of 11

Anonymous
Not applicable

Thank you for the code, it has fixed the problem and I am gratefull to you for the responce.

 

There is a warning associated with the "oOcc.CreateGeometryProxy(oFace1, oOccFaceProxy1)" line.

This does not appear to affect the operation although it would be good to know what the warning is refering to and if it can be fixed? I have attached the warning below.

 

Warning 1 Implicit conversion from 'Object' to 'Inventor.FaceProxy' in copying the value of 'ByRef' parameter 'Result' back to the matching argument. C:\Users\malcolm\Documents\Visual Studio 2008\Projects\Inventor Addins\SortRouterParts_Addin\SortRouterParts_Addin\Main.vb 263 51 SortRouterParts_Addin

 

Regards Malcolm

0 Likes
Message 7 of 11

Anonymous
Not applicable

Hi Malcolm,

May be you pass ByRef non-initialized oOccFaceProxy1 variable to CreateGeometryProxy method. In theory you may get non-initialized result. That is why VB compiler warning you.

Use the following syntax

Dim oOccFaceProxy1 As Inventor.FaceProxy = Nothing

This will initialize your object variable with null value.

See my code in previous post.

Vladimir

0 Likes
Message 8 of 11

Anonymous
Not applicable

Hi Vladimir

I have copied your code with only minor changes so if you are not getting the warning something else must be causing it that is unique to my machine?

 

Regards Malcolm

0 Likes
Message 9 of 11

Anonymous
Not applicable

If I use Option Strict On then I also get the same warning.

So let's use more accurate code style for proxy face creation:

' Create a proxy for the 1st face
Dim oObj As Object = Nothing
Call oOcc.CreateGeometryProxy(oFace1, oObj)
Dim oOccFaceProxy1 As Inventor.FaceProxy = TryCast(oObj, FaceProxy)
If oOccFaceProxy1 Is Nothing Then
   MsgBox("Proxy 1 is undefined")
   Return False
End If
0 Likes
Message 10 of 11

Anonymous
Not applicable

Hi Vladimir

 

Thanks for the help, although I don't understand the reasons for the back to front code it has fixed the warning.

 

Regards Malcolm

0 Likes
Message 11 of 11

Crstiano
Advisor
Advisor

Hi @Anonymous, @Anonymous, @Qube-it@scottmoyse.. taking advantage of this post.

 

I found the a similar error when i try create the EdgeProxy.

 

In this case:

SearchOcc = Part of the Sub-Assembly, using the TransientKey for set the Edge

NewOcc = SubAssembly is occurrence of the Assembly opened in screen.

 

But in time to create the Edgeproxy...

 

Error.png

 

Where am I going wrong??

 

Tks in advance.

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.


Cristiano Oliveira
EESignature
ConsultCAD.com

0 Likes