I need get information from the first file (it could be an *.ipt or *.iam). I want to run an iLogic Rule to get the name of the first file.
Could someone please help?
Thanks lot.
Solved! Go to Solution.
Solved by cwhetten. Go to Solution.
Solved by cwhetten. Go to Solution.
Solved by cwhetten. Go to Solution.
Solved by cwhetten. Go to Solution.
How about this:
Dim oAsmComp As ComponentDefinition oAsmComp = ThisDoc.Document.ComponentDefinition Dim oFirstName As String oFirstName = oAsmComp.Occurrences(1).ReferencedFileDescriptor.FullFileName
Please click "Accept as Solution" if this response answers your question.
Cameron Whetten
Inventor 2014
Great! It is what I want.
Thanks lot.
Hello Cameron,
When I use this rule, I find there is error when the assembly is empty. Could you please help me how to know the assembly is empty by iLogic rule?
I will use it as templete, so the assembly file name is unknow, and all occurrence names are unknow too.
Thanks lot.
And I just noticed I do not need the full name. I mean I just need the file name but not the path. Could you help at same time?
Try this instead:
Dim oAsmComp As ComponentDefinition oAsmComp = ThisDoc.Document.ComponentDefinition If oAsmComp.Occurrences.Count = 0 Then 'do nothing Else Dim oFirstName As String oFirstName = oAsmComp.Occurrences(1).ReferencedFileDescriptor.FullFileName oFirstName = oFirstName.Remove(0, oFirstName.LastIndexOf("\") + 1) End If
This code tests if the collection of component occurrences is empty (count = 0). If so, it does nothing, otherwise it finds the filename (without the path this time). If you would rather have it to do something, just add the desired code where it says 'do nothing.
Please click "Accept as Solution" if this response answers your question.
Cameron Whetten
Inventor 2014
Hello Cameron,
I just have time to test the code which you contributed yesterday, it works great!
Thanks lot.
Hello Cameron,
I finished my application and the result is perfect now. Thanks lot for your help.
Now I am thinking the situation after I release it to user.
Sorry, I forget mention to you: I am trying to get infromation from the first file in my assembly which includes this rule.
As you know, when we put first file into an assembly, it automaticly put "file name" without extension name and with ":1" as suffix (as "firstblock:1")
So I used your code and took off the extension name and put ":1" to run following snippet.
iProperties.Value("Custom", "BlockHeight") = iProperties.Value(oFirstName, "Custom", "BlockHeight")
But maybe there is a chance, user put same file twice into assembly by mistake and later delete the first one. Then the first file name will be: "firstblock:2".
Then above snippet will not work well.
Do yo know how to just get the display name which without extension name and ":1" or ":2" and so on in assembly? If we can do this, then we do not need to worry how the user put the file now.
Appreciate your help again?
Hi Rich,
Getting the display name is easier than getting the filename. This should work:
Dim oAsmComp As ComponentDefinition oAsmComp = ThisDoc.Document.ComponentDefinition If oAsmComp.Occurrences.Count = 0 Then 'do nothing Else Dim oFirstName As String oFirstName = oAsmComp.Occurrences(1).Name End If
Cameron Whetten
Inventor 2014
Bingo!
All of problem is solved under your help!
Thanks lot, Cameron!
Hello Cameron,
Could I ask you one more question?
How Can I get the file type of first file?
I can get it the right letter after I get the fullfilename after run below Snippet which you gave to me.
oFirstName = oAsmComp.Occurrences(1).ReferencedFileDescriptor.FullFileName
But do we have a simple way to get it?
I tried to use this snippet, it does not work. Do you have any simple way? Thanks lot for your help in advanced.
oFirstType = oAsmComp.Occurrences(1).ReferencedFileDescriptor.FileType
Hi Rich. You can use the following to get the document type:
oFirstType = oAsmComp.Occurrences(1).DefinitionDocumentType
This returns an enumerator (enum), which is a numeric constant that represents something. In this case, it returns a DocumentTypeEnum, which as you might guess represents a type of document. According to the API help documentation, the different values for DocumentTypeEnum and what they represent are given in the image below:
The following is an example of how you might use this enum in your code:
oFirstType = oAsmComp.Occurrences(1).DefinitionDocumentType
If oFirstType = DocumentTypeEnum.kAssemblyDocumentObject Then
'do some stuff
End If
Cameron Whetten
Inventor 2014
Thanks lot.
Dim oAsmComp As ComponentDefinition oAsmComp = ThisDoc.Document.ComponentDefinition If oAsmComp.Occurrences.Count = 0 Then 'do nothing Else Dim oFirstName As String oFirstName = oAsmComp.Occurrences(1).Name End If
Could I ask a question about above code?
I put this code in my ilogic rule. When I open it fresh, it works fine. But when I worked other projects and then open the file with this rule, it cannot get correct information. I mean
oAsmComp.Occurrences.Count
does not work well.
I have to close inventor and open the file which with this rule as first open, it works again.
Could someone advise me how to fix it?
Thanks a lot in advance.
This works great, however, how could I run through all of the Occurrences? Because there is a (1), I am only allowed to get the first file. I want to get multiple. I tried doing:
oFirstName = oAsmComp.Occurrences.ReferencedFileDescriptor.FullFileName
I removed the (1) but it doesn't work