API Constraining to Work features

API Constraining to Work features

Anonymous
Not applicable
371 Views
0 Replies
Message 1 of 1

API Constraining to Work features

Anonymous
Not applicable

As part of an AddIn am writing I want to place two constraints on a newly inserted content center part. I am trying to place a flush and a mate constraint  based upon selecting two faces from the existing item and using the YZ Plane and X Axis of the newly inserted part. but am now completley stuck. No matter what I try,  the line of code to create the constraints keep throwing up the incorrect parameter error:

 

[The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]

 

I can make the code work if I manually select both surfaces for each constraint, but not otherwise.

 

        Dim ADoc As AssemblyDocument = InvApp.ActiveDocument

        Dim Invpart1 As ComponentOccurrence = InvApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part")
        Dim Invpart2 As ComponentOccurrence
        If Invpart1 Is Nothing Then Exit Sub

        Dim oPlane1 As Face = InvApp.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select First  Face")
        Dim Hole1 As Face = InvApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Select  Hole")

'Commented out as seems to make no difference.
        'Dim oPLane1Proxy As FaceProxy = Nothing
        'Invpart1.CreateGeometryProxy(oPlane1, CType(oPLane1Proxy, FaceProxy))
        'Dim Hole1Proxy As FaceProxy = Nothing
        'Invpart1.CreateGeometryProxy(Hole1, CType(Hole1Proxy, FaceProxy))

'------
'part that added new item ommitted for clarity/size
'------
Invpart2 = asmDef.Occurrences.Add(memberFilename, transMatrix) Dim oPlane2 As WorkPlane = Invpart2.Definition.workplanes.item(2) Dim oAxis1 As WorkAxis = Invpart2.Definition.workaxes.item(1) Dim oPLane2Proxy As WorkPlaneProxy = Nothing Dim oAxis1Proxy As WorkAxisProxy = Nothing 'Invpart2.CreateGeometryProxy(oPlane2, oPLane2Proxy) Invpart2.CreateGeometryProxy(oPlane2, CType(oPLane2Proxy, WorkPlaneProxy)) Invpart2.CreateGeometryProxy(oAxis1, CType(oAxis1Proxy, WorkAxisProxy)) If Invpart2.Grounded Then Invpart2.Grounded = False
'The code runs fine down to here:
'asmDef.Constraints.AddMateConstraint(Hole1, oAxis1Proxy, 0) asmDef.Constraints.AddFlushConstraint(oPlane1, oPLane2Proxy, 0)

 

If someone can tell me what I'm missing here.

 

As always, any help is greatly appreciated.

0 Likes
372 Views
0 Replies
Replies (0)