Macro: Insert constrain on a new inserted sub assembly fails

Macro: Insert constrain on a new inserted sub assembly fails

Anonymous
Not applicable
512 Views
4 Replies
Message 1 of 5

Macro: Insert constrain on a new inserted sub assembly fails

Anonymous
Not applicable

Hi

 

I have a bolt assembly with 1 bolt 2 washers and a nut.

I use the macro to insert the assembly and want to constrain a washer of that assembly to a selected hole in the main assembly.

The insertconstraint is failing. I tried the same thing with just a washer and that works fine.

So either I am doing something wrong with selecting the correct edge of the washer inside the assembly, or I need to change something with the insert constraint itself.

I did add a check to see if the edge I'm using is indeed a circle.

 

error returned:

run time error 80004005:

Method 'Addinsertconstraint' of object "assemblyconstraints' failed

 

I stripped below code from the bigger macro to be more clear.

- select a circle edge in the existing assembly

- Macro will place the assembly M10 x 25.iam

- Fails to constrain

 

Any help would be appreciated.

Bolt assembly is attached. inside are standard content centre bolt washers and nut.

Thx

 

 

Public Sub test_assy_constraint()

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oEdge As Edge
Dim oFace As Face

Set oEdge = ThisApplication.CommandManager.Pick(kPartEdgeCircularFilter, "select circular edge")

If oEdge Is Nothing Then
    Exit Sub
    Else
        If Not oEdge.GeometryType = kCircleCurve Then
            GoTo Line1
        End If
End If

Dim memberfilename As String
memberfilename = "c:\testfolder\bolts\M10 x 25.iam"
'memberfilename = "c:\testfolder\inventor content center\Content center 3D Suppliers 2019\en-US\DIN 125-1  A\DIN 125 - A 10,5.ipt"
           
            
Dim transMatrix As Matrix
Set transMatrix = ThisApplication.TransientGeometry.CreateMatrix
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim occ As ComponentOccurrence
Set occ = oAsmCompDef.Occurrences.Add(memberfilename, transMatrix)



Dim oInsert As InsertConstraint
Dim oEdge3 As Edge
Set oEdge3 = occ.Definition.Occurrences.Item(2).SurfaceBodies.Item(1).Edges.Item(1) 'item 2 = washer
'Set oEdge3 = occ.SurfaceBodies.Item(1).Edges.Item(1)

If Not oEdge3.GeometryType = kCircleCurve Then
            MsgBox ("not a circle")
End If

'On Error Resume Next
Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge, oEdge3, True, 0)
'Set oinsert = oAsmcompdef.Constraints.AddInsertConstraint2(oedge, oEdge3, True, 0)

End Sub

 

 

0 Likes
Accepted solutions (1)
513 Views
4 Replies
Replies (4)
Message 2 of 5

JamieVJohnson2
Collaborator
Collaborator

I played with the highlightset commands to verify you are getting the appropriate edge:

Dim hs As HighlightSet = ThisApplication.ActiveDocument.CreateHighlightSet
Dim oRed As Color
    oRed = ThisApplication.TransientObjects.CreateColor(255, 0, 0)

    ' Set the opacity
    oRed.Opacity = 0.8

    hs.Color = oRed
hs.AddItem(oEdge3)

It did highlight the expected edge, now the only question is have you tried to toggle the true/false to change from opposing to same direction, just to see if there is a modeling oddity?  And make sure the parts are not grounded, and also make sure the modeling constraint is being placed in the active assembly (if sub assembly, then activate it first), and the part being moved is a separate component of the active assembly (you can not place a constraint to two edges of the same component (part or assembly component).

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi

 

Thx for the reply.

To answer your questions:

- Yes I tried the true false toggle, same result.

- Nothing grounded. I can move it freely after the macro fails.

- "also make sure the modeling constraint is being placed in the active assembly (if sub assembly, then activate it first)," Not sure what you mean with this. The constraint should be placed in the main assembly. I think I'm doing that. Unless I'm making a mistake creating the insert.

- In the example code I posted you need to select the first edge tourself. So I'm sure it's not part of the subassy I'm trying to constrain.

 

I will try to add your piece of code and double check.

Thx.

 

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

I tried adding the highlight but it's not working for me.

I can get edges to from a part, but not from a subassembly wich I define, unless I use the manual picking of the edge. Then it all works fine, also the constraint. the highlighting fails on the line when I try to add the edge to the highlighset: Call hs.AddItem(oEdge3)

 

So I'm pretty sure now I do something wrong with the defining of the edge of the sub assembly but I can't figure it out.

Any else with an idea?

 

Thx.

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

I got it.

 

Replace line: Set oEdge3 = occ.Definition.Occurrences.Item(2).SurfaceBodies.Item(1).Edges.Item(1) 'item 2 = washer

with              : Set oEdge3 = occ.SubOccurrences.Item(2).SurfaceBodies.Item(1).Edges.Item(1) 'item 2 = washer

 

Can't believe I spend this much time looking for this..

0 Likes