Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
phani.gampala
365 Views, 6 Replies

Placing and constraining multiple instances of fastners

Hello everyone,

I'm trying to place fasteners as sets, example: M10 x 25 SET SCREW, M10 FLAT WASHER AND M10 SPRING WASHER into my assembly so that I can constrain them to my assembly quicker. However when I place these components from content center and constrain them using ilogic it only works the first time. When a second instance of the fastener is placed  (for example:  SS Flat Washers 10 mm:2), how do I update the mate constraint that is supposed to constrain the fastener set. I have only pasted the problematic portion of the code. I need the code to place new instances every single time it is run and constrain them in the same way.

 

Component1 = Components.AddContentCenterPart("SS Flat Washers 10 mm:1","Fasteners:Washers:Plain","SS Flat Washers",
                                                 {"STOCK_TYPE","S","NND","10"},
                                                 position := Nothing, grounded := False, 
                                                 visible := True, appearance := Nothing)
Component2 = Components.AddContentCenterPart("SS Spring Washers 10 mm:1","Fasteners:Washers:Spring","SS Spring Washers",
                                                 {"STOCK_TYPE","S","NND","10"},
                                                 position := Nothing, grounded := False, 
                                                 visible := True, appearance := Nothing)

Constraints.AddMate("", "SS Flat Washers 10 mm:1", "Work Axis1", "SS Spring Washers 10 mm:1", "Work Axis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
Constraints.AddMate("", "SS Flat Washers 10 mm:1", "YZ PLANE", "SS Spring Washers 10 mm:1", "YZ PLANE",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

 

A.Acheson
in reply to: phani.gampala

If you replace the static occurrence name with "" in AddContentCenterPart this will then automatically assign the name as the part is added therefore adding the index :1,:2,:3 etc.You don't need to deal with creating new/duplicate names.

Next for the constraint replace the static occurrence name with the name linked to the object occurrence added previously. 

Component1 = Components.AddContentCenterPart("","Fasteners:Washers:Plain","SS Flat Washers",
                                                 {"STOCK_TYPE","S","NND","10"},
                                                 position := Nothing, grounded := False, 
                                                 visible := True, appearance := Nothing)
Component2 = Components.AddContentCenterPart("","Fasteners:Washers:Spring","SS Spring Washers",
                                                 {"STOCK_TYPE","S","NND","10"},
                                                 position := Nothing, grounded := False, 
                                                 visible := True, appearance := Nothing)

Constraints.AddMate("", Component1.Name, "Work Axis1", Component2.Name, "Work Axis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
Constraints.AddMate("", Component1.Name, "YZ PLANE", Component2.Name, "YZ PLANE",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
phani.gampala
in reply to: A.Acheson

Thank you very much for the reply @A.Acheson 

I have tried leaving the name blank like you mentioned. Then inventor just creates parts with the numbering scheme set automatically. However, I dont want to manually add the constraint name for every single fastener placed. For example there might already be a 100 M10 Flat Washers in the assembly added before. If I run the code it will place M10 Flat Washer:101 like you said but wont update the mate number to mate:101. It will just replace some older constraint. I need a way to update the constraint name automatically to suit the new instance name.

A.Acheson
in reply to: phani.gampala

In my test if I left the mate name blank it automatically assigned a new number. It wasn't associated with the occurrence number. I didn't test your example specifically so maybe check that the mate name is correctly referenced. You can use capture snippet to reference the original constraint. 

As far as I am aware it just takes the next available index for that mate type. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
phani.gampala
in reply to: A.Acheson

Sorry @A.Acheson  I missed one part of your correction. Thank you very much, you saved me a lot of time. It works perfectly. Was a very easy fix. Any suggestion on how I can learn these basics? I'm writing codes for simple assemblies but I'm not a programmer and things like this eat up a lot of time..

A.Acheson
in reply to: phani.gampala

For ilogic specific snippets like what your working with just simple practice and trial and error is the best. I don't think there is much tutorials on these little tricks. This forum is the best to pick these up. That particular one of leaving the string blank I picked up from another user leaving it blank when using ipart change row. 

 

The Inventor API help has a lot of samples and also information about objects you are working  with. Although this is a level deeper than ilogic it still has some background information as to what the objects do and what the methods are and how you can use them. As for the ilogic API help that is also there and can offer more information to as to how the code is to be constructed. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Thanks @A.Acheson