create iLogic mate using iMate

create iLogic mate using iMate

danijel.radenkovic
Collaborator Collaborator
2,885 Views
25 Replies
Message 1 of 26

create iLogic mate using iMate

danijel.radenkovic
Collaborator
Collaborator

Hello,

I am trying to create an mate as on the image below.

Any help is very appreciated.

 

1.png

 

Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Accepted solutions (1)
2,886 Views
25 Replies
Replies (25)
Message 2 of 26

danijel.radenkovic
Collaborator
Collaborator

Any help, reference, advice??

 

Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 3 of 26

danijel.radenkovic
Collaborator
Collaborator

One more try to ask for the help...

 

 

Thanks.

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 4 of 26

Anonymous
Not applicable

I'm also looking for a solution to this...

 

Did you work something out?

Message 5 of 26

danijel.radenkovic
Collaborator
Collaborator

@c.henderson2HQZG wrote:

I'm also looking for a solution to this...

 

Did you work something out?


Hi,

I still haven't found a way. If you find something please post it as solution.

 

Regards

Danijel

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 6 of 26

Anonymous
Not applicable
Accepted solution

Yes I got there eventually, sorry I wasn't able to open your assembly so you will need change the code below to match your part and iMate names

 

'Define two occurences
Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence

'Set two occurrences using their names as in model browser
oOcc1 = oAsmCompDef.Occurrences.ItemByName("Part1")
oOcc2 = oAsmCompDef.Occurrences.ItemByName("Part2")

 

'Define iMate1 as your insert iMate on oOcc1 (i.e Part1)
i = 1
For Each iMateDefinition In oOcc1.iMateDefinitions
      If iMateDefinition.Name= "Insert1" Then 
            iMate1 = oOcc1.iMateDefinitions.Item(i)
            Exit For
      End If
i = i+1
Next

 

'Define iMate2 as your insert iMate on oOcc2 (i.e Part2)
i = 1
For Each iMateDefinition In oOcc2.iMateDefinitions
      If iMateDefinition.Name= "Insert1" Then 
            iMate2 = oOcc2.iMateDefinitions.Item(i)
            Exit For
      End If
i = i+1
Next

 

' Create an iMate result between two iMate1 and iMate2

Dim oiMateResult As iMateResult
oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(iMate1, iMate2)
 

Message 7 of 26

JBerns
Advisor
Advisor

@Anonymous,

 

Running this code in Inventor 2019 results in an error:

   'oAsmCompDef' is not declared. It may be inaccessible due to its protection level.

 

I added this statement below the other Dim statements:

 

 

Dim oAsmCompDef As AssemblyComponentDefinition

But that produces a new error:

   Object reference not set to an instance of an object.

 

Can anyone offer a solution?

 

 

Regards,

Jerry

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 8 of 26

JBerns
Advisor
Advisor

I found more examples on using iLogic to assemble parts with iMates, but the following error persists for these parts:

Error in rule: Mate Washer to Bolt, in document: Assembly_with_iMates_Test_2019-10-21_A.iam

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

I have attached the files if someone could review and explain why the rule produces the above error.

 

I look forward to the replies.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 9 of 26

Anonymous
Not applicable

@JBerns

You must assign oAsmCompDef  to an object first

Try this:

Dim doc As AssemblyDocument
doc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = doc.ComponentDefinition  

 

0 Likes
Message 10 of 26

JBerns
Advisor
Advisor

Craig (@Anonymous),

 

I believe I have similar code in my rule. See attached assembly in the zip file.

Still getting the error, "The parameter is incorrect".

 

The error occurs during this statement:

oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(iMate1, iMate2)

Through debugging, the parts are found, the iMates are found, but it fails when performing the AddByTwoiMates function. I can get the code to work with other parts in other assemblies. I cannot determine why it fails with this bolt and washer.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 11 of 26

JBerns
Advisor
Advisor

I wondered if it may have something to do with the fact that these were Content Center Parts. So, I moved them to a non-library folder, ran some code to strip the Content Center info from the parts, and then placed the parts into a new assembly.

 

Still, "The parameter is incorrect." error message persists. I am sure this is going to be a simple solution, but I just can't see it. Hopefully someone can find the issue with these parts or assemblies and explain why the rule fails.

 

I have attached a new data set containing non-library components. Thanks for any assistance you can offer.

 

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 12 of 26

JBerns
Advisor
Advisor

@chandra.shekar.g / @Curtis_Waguespack / @MjDeck ,

 

Gentlemen,

 

Would any of you have time to review the model and iLogic rule within the assembly posted directly above?

I have tried many attempts and variations of files and code, but cannot get the bolt and washer to assemble using iMates. Any assistance would be appreciated.

 

 

Kind regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 13 of 26

Curtis_Waguespack
Consultant
Consultant

Hi @JBerns 

 

I've never done anything with imates (code wise), but if someone doesn't get to it before I do I'll try to have a quick look later this week

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 14 of 26

JBerns
Advisor
Advisor

Thanks, Curtis. ( @Curtis_Waguespack )

 

I did some more testing today and have concluded there is an issue with AddByTwoiMates when the Offset values do not evaluate to the same value. I do not have a workaround at this time. I really don't want to have to edit the custom CC parts.

 

Please see my post on this forum thread:

https://forums.autodesk.com/t5/inventor-forum/imate-constraint-with-ilogic/td-p/5593535 

 

I look forward to your findings when you have time. Much appreciated.

 

 

Kind regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 15 of 26

Curtis_Waguespack
Consultant
Consultant

Hi @JBerns 

 

Without digging into what all you're attempting to accomplish my thought is that I would likely ditch iMates and just use ilogic to create constraints ....this assumes you're using a later version of inventor that has support for constraining components I forget when that was introduced, 2018 maybe?

 

aaa.png

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 16 of 26

Anonymous
Not applicable

@JBerns 

I was unable to open your files successfully to test.

 

Can you post your full code? Have you tested that you are able to manually create an iMate between the two?

 

0 Likes
Message 17 of 26

JBerns
Advisor
Advisor

Craig ( @Anonymous ),

 

I am quite certain this is the same code posted by @Curtis_Waguespack .

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
 
Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
oOcc1 = oAsmCompDef.Occurrences.ItemByName("Shaft101:1")
oOcc2 = oAsmCompDef.Occurrences.ItemByName("ISO 1224 (I) (Inch) 0.375 x 0.625 x 0.1562:1")

i = 1
For each  iMateDefinition in oOcc1.iMateDefinitions
	If iMateDefinition.Name= "Insert100" Then
		iMate1 = oOcc1.iMateDefinitions.Item(i)
		Exit For
	End If
	i = i+1
Next

i = 1
For each  iMateDefinition in oOcc2.iMateDefinitions
	If iMateDefinition.Name= "Insert In1" Then
		iMate2 = oOcc2.iMateDefinitions.Item(i)
		Exit For
	End If
	i = i+1
Next

' Create an iMate result between two iMates
Dim oiMateResult As iMateResult
oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(iMate1, iMate2)

Modify the component names and iMate names as needed if you are not using the shaft and bearing examples posted by Curtis.

 

You can ALT-Drag the iMates together and they assemble as expected. When components are assembled with AddByTwoiMates, and the values do not match, the code fails. Incorrect parameter error results.

 

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 18 of 26

Anonymous
Not applicable

The code looks fine (pretty much same as the solution code I posted except the part/iMate naming). I've been using the same code for years with no issues. However, with the introduction of new iLogic constraint commands (as @Curtis_Waguespack mentioned in a previous post) I've slowly began to replace iMates. It's worth thinking about whether iMates are worth the effort.

 

When you say the values don't match, what exactly do you mean? If you are referring to offset values, my understanding of iMates is that the offset values in each iMate need to match, otherwise its impossible to create an iMate between them.

0 Likes
Message 19 of 26

JBerns
Advisor
Advisor

Craig,

 

Please watch this video, which demonstrates the use of iMates with varying Offset values and the ALT-Drag assembly technique.

https://autode.sk/2BGKqCH 

( I have attached the files used in the video. 2019 format)

 

The 'AddByTwoiMates' function supports non-zero values and mixed units that evaluate to the same value.

 

Why does the function require the values to match? Inventor doesn't, as shown in the video above.

 

In my opinion, 'AddByTwoiMates' has a bug. It should support unmatched Offset values just like Inventor does.

 

Do you use fasteners from custom Content Center Libraries? What methods do you use to assemble these? 

It is puzzling why the developers of the libraries chose the different edges for the 'Insert In1' iMate edge. This requires using different code when automating ANSI or ISO hardware.

 

As I continue to develop my programming knowledge and skills, I could really benefit from the experience of others in managing fasteners in assemblies.

 

I look forward to your reply.

 

 

Respectfully,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 20 of 26

Curtis_Waguespack
Consultant
Consultant

Hi @JBerns 

 

I finally took a moment to look at this.

 

If you use these file from the other thread 

and add this code as a new rule, it will use one of the existing bearing components and place a new instance and create an insert constraint with a distance offset. Would this approach work better for you than iMates?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

occName = "ISO 1224 (I) (Inch) 0.375 x 0.625 x 0.1562:1"
oOcc = Component.InventorComponent(occName)

'get the file path from the component occurrence 
oDoc_Name = oOcc.Definition.Document.fullfilename
 
 
 'add a new occurrence
 Dim oComp = Components.Add _
	("Bearing3", oDoc_Name, 
	position := Nothing, 
	grounded := False, 
	visible := True, 
	Appearance := Nothing)

 'create an insert constraint 
 Constraints.AddInsert _
	("Insert:1",
	oComp,
	"Proxy:Edge0", 
	"Shaft101:1", 
	"Edge0",
	axesOpposed := True,
	distance := 0.1,
	lockRotation : = False, 
	biasPoint1 := Nothing, 
	biasPoint2 := Nothing)

 

 

EESignature

0 Likes