- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to place a part in an assembly using the iLogic code below:
oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("filename", False)
It works well on most of my files but there's one in particular that has a composite iMate and a single iMate, because it requires constraining to two different parts. The code only generates one of these when executed.
Does anyone have experience with this or knows of an alternative solution?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You could create a dummy part / master part to constraint alll parts to. put in only sketches and workplanes for constrainning the parts to the right place.
Then you have two parts and can use the imates. further you can freely delete other parts without messing up the assembly.
Kudo's are also appreciated
Succes on your project, and have a nice day
Herm Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for your suggestion,
I was hoping there was something out there that could generate a result between two iMates with matching names?
And I could then use this workflow:
- Place component with AddUsingiMates, which generates a result for iMate1 on each part.
- Generate a result between iMate2 on each part using another line of code.
Appreciate any advice!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried what you are doing in Inventor 2016 and it works fine...!?
I have a block1, cilinder1 and block 2.
block1 and cilinder1 are constrained.
block2 has one imate connecting with the other end of the cilinder1.
block2 has two imates in a composite connecting with block1
all imates/composite have matching names.
when I place block2 (manually), the imate and composite get connected
when I do this with your code, this also works.
it could be something with 2015?
what happens when you place it manually?
are the imates all at the same level in the browser? and not in a sub assembly?
what happens if you copy the part you want to place and create a different part (with other name).
then place one of the parts, so that the imate/composite are connected.
then Replace it with the copy. this should work. if not, then probably the imates are incorrect.
could you post a (stripped) assembly with the tree involving parts?
Kudo's are also appreciated
Succes on your project, and have a nice day
Herm Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I got there with it eventually. This code will delete any instances of part with a specific name, place it in the assembly again and generate a result on the 1st iMate (i.e Part1 with Part2) which in my case was a composite iMate, then generate a result on the 2nd iMate (i.e Part1 with Part3) which was a single Insert iMate.
' Get the component definition of the currently open assembly.
' This will fail if an assembly document is not open.
Dim doc As AssemblyDocument
doc = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences
oComps = doc.ComponentDefinition.Occurrences
Dim oOccEnumerator As ComponentOccurrencesEnumerator
'Delete any instances of files containing "Spring"
For Each oComp In oComps
If oComp.Name.Contains("Spring") Then
oComp.Delete
End If
Next
'Place part in assembly using automatically generated iMates (will generate a result for the 1st iMate in the placed part)
oOccEnumerator = oAsmCompDef.Occurrences.AddUsingiMates("fullfilepath\Spring.iam", False)
'Set part to flexible (remove if not required)
i = 1
For Each oComp In oComps
If oComp.Name.Contains("Spring") Then
oComp.Flexible = True
i = i+1
End If
Next
'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("Spring")
oOcc2 = oAsmCompDef.Occurrences.ItemByName("Panel")
'Define iMate1 on oOcc1
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 on oOcc2
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Nice that it is working.
I am wondering why both, the imate and composite are not connected, maybe a 2015 issue..
Kudo's are also appreciated
Succes on your project, and have a nice day
Herm Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Perhaps its due to version, could you post your files so I can test them on my Inventor?
I'd prefer not to have the code so long and complicated so if I can get it to work with just AddUsingiMates that would be great.
P.S When I place the part manually it only constrains the composite.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My files are created in 2016, You can't open them in 2015....
but here the are, open the assembly, delete part2. then insert part2 again, and they are connected.
here is a screencast: http://autode.sk/2dVrnIF
one other thing you could try is making the copy. this copy can be a dummy and should only have the iMate and Composite.
Place this dummy in the assembly (you will not see it, only in the browser). now you can use the replace function.
this is also less code and should work.
Kudo's are also appreciated
Succes on your project, and have a nice day
Herm Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
did you get any further?
Kudo's are also appreciated
Succes on your project, and have a nice day
Herm Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It must be due to the version. For now I'm just going to stick with the long code I have as it's at least working the way I want, and perhaps if we upgrade to 2016 I will simplify it.
Thanks for your help though.