Trying to have ilogic find parts in an assembly that start with 900C7 so I can link the to a cell in excel showing the QTY and the LENGTH..
Right now I am just trying to get ilogic to find and list them then I know I can move to the next step..
Example:
900C71.250
900C72.125
900C7A.750
900C7P1.1875
And many more.
Here is what I have but it keeps posting the NOTHING message box. I have a few of the parts in the assembly and a few none 900C7 parts.
Dim openDoc As Inventor.Document Dim docFile As Inventor.Document Dim assemblyDoc As AssemblyDocument Dim partOcc As ComponentOccurrence Dim FNamePos As Long Dim docFName As String Dim oList As Collection = New Collection openDoc = ThisApplication.ActiveDocument If openDoc.DocumentType = kAssemblyDocumentObject Then assemblyDoc = openDoc assemblyDef = assemblyDoc.ComponentDefinition Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If For Each docFile In openDoc.AllReferencedDocuments If (Left ( docFName, 6) = "900C7P") Then oList.Add(docFName) End If Next If oList.Count = 0 Then MessageBox.Show("NOTHING") Else 'print oList Dim sTotal As String = "Found: " & oList.Count For Each st As String In oList sTotal += vbNewLine & st Next MsgBox(sTotal) End If
Here is a screen shot of the excel file not sure if you need it but you may get a better idea what I am trying.
Thanks for any help..
Solved! Go to Solution.
Solved by danvang. Go to Solution.
What you want to do is surely possible. There are a couple of reason why your existing code isn't behaving as you expect. First, I don't see where you're setting the value of docFName so the If statement where you're looking for a specific file is always comparing against an empty string. Second depending on how you set docFName you need to be careful that it's just the file name and the not full filename (path and file). This is because in your comparison statement you're assuming it's just the file name with no path.
In many cases like this it's easier to write the initial code in VBA where you have some good debugging tools and then move it to iLogic once you have the basic logic working.
I recieved an email asking for more information on this but I don't see any questions..
Case 08979816
What are more information do you need?
Hey James,
Brian already pointed you to the FullFileName property of the document object.
You would have to use docFile.FullFileName to get this in your document enumeration.
The problem with this is that the FullFileName property includes the complete path to the document
plus the filename.
So you would have to substract the path from the FullFileName property to get the filename.
As an alternative you could use the displayName property from the document object if your displayName is the
same as the filename.
Hope that helps
All the best
Falk
P.S.: I just looked at some code I have and I solved it with using
Dim DocPath As String = ThisDoc.Path & "\"
I´m not sure if docFile.Path would give you the path only.
Cheers
Falk is correct that the full document name is returned. There is a very easy way to extract the full filename from that. You can use the CommandManager.GetFullFileName method. There are a few functions on the CommandManager object to make working with file names a bit easier.
Not sure I would need full path and all, is the a way to use just the iproperty part number?
So when I am in an assembly run the rule it would list them and be able to extract information from them to fill in the spread sheet?
Is autodesk working on a help book for just ilogic? Trying to use API (VBA) code is real hard to figure what works and not work in ilogic.
But it could be just me self taught on VB an C++ so not the best at it. And without a sample it is really hard for me to grasp but I will not quit LOL.
Thanks
I´m exactly on the same path James,
I started out with just iLogic 12 months ago and figured after a while that VB.net works too in
iLogic so I grabbed a book for VB.net and started to learn the basic concepts.
It´s a tough path with iLogic cause you don´t have a debugger for iLogic.
Fortunately I was able with the book on VB.net and examples from the internet to get around
most problems.
I´m still learning VB.net and Inventor API and I wouldn´t consider myself an expert.
But hey, it´s getting better everyday 🙂
One day I will make the transition to plugins with Visual Studio Express so I can get rid of the limitations.
@Brian:
That´s very useful info on the command manager. I just checked (still on 2012) and couldn´t find anything in the programming help about the GetFullFilename method. Is this something new for 2013/2014?
All the best
Hi James,
Firstly, I believe Brian meant "FileManager.GetFullFileName".
About your question, you could get the iProperties from the component document directly when you iterating the referenced documents, e.g.
For Each docFile In openDoc.AllReferencedDocuments Dim oIProInEachRefDoc oIProInEachRefDoc = docFile.PropertySets("Design Tracking Properties").Item("Part Number") Dim oPartNo oPartNo = oIProInEachRefDoc.Value MessageBox.Show(oPartNo) Next
iLogic wraps some functions of Inventor API to make it easier for some end users. In this case,
docFile.PropertySets("Design Tracking Properties").Item("Part Number")
is similar to
iProperties.Value("Project", "Part Number")
But the later can only work for the current document.
Hi falkmassmann,
The API helps shows FileManager.GetFullFileName is Introduced in Inventor version R11.
Hi James,
As falkmassmann has practised, it is the best way to debug in VB.NET on the complex code firstly and copy it to iLogic. As you may have known, we have a "My First Plugin" course for the newbie of VB.NET. It is a good material to get started with API in VB.NET
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17324828
In addition,we have a lot of training videos on the basic topics of Inventor API.
http://adndevblog.typepad.com/manufacturing/2013/05/api-webcast-archive.html
e.g. about the PropertySets in the code I provided in the last message, you could find the introduction in this video:
xiaodong,
Yes I understand that but when the help files don't work I can't find what I think I might need or look up to see.
This is why I have to post here and hope someone sees that I am trying to do this with ilogic and post the fixed code for my issue not send me to a help that don't work..
And seeing not everything in the VBA works with ilogic but you have to know what to take out what to change.
Why not work on a ilogic help file instead?
Not sure if you got an answer to this yet but here's what I got and it seems to be working. I didn't put in the code to check if the active doc is an IAM or not. I figured if it was going to be a local rule in an IAM it's not really needed. But if you are planning to write it as an external rule then you will need it. Hope this helps.
Dim oDoc As Inventor.Document = ThisDoc.Document
Dim docFile As Inventor.Document
Dim oList As Collection = New Collection
For Each docFile In oDoc.AllReferencedDocuments
'MessageBox.Show(docFile.DisplayName)
Dim FileNameTemp As String = (Left (docFile.DisplayName, 6))
If FileNameTemp.ToUpper = "900C7P" Then
oList.Add(docFile.DisplayName)
End If
Next
If oList.Count = 0 Then
MessageBox.Show("NOTHING")
Else
'print oList
Dim sTotal As String = "Found: " & oList.Count
For Each st As String In oList
sTotal += vbNewLine & st
Next
MessageBox.Show(sTotal)
End If
danvang,
Thank you that worked.
Now to write the rest of the code....
xiaodong,
No your code did not work it gave errors when ran. Was this the whole code or was this to be added to my code?