I am trying to use an ilogic rule in an assembly to open an ipart and check some iproperties.
Once the ipart is open I check that the ipart is the active document, but when I call for the Part Number from iProperties I get the part number of the assembly containign the rule, not the active document.
Thanks for any help,
Here is my code:
SyntaxEditor Code Snippet
TemPath= "K:\TEMPLATE.ipt" ThisApplication.Documents.Open(TemPath) Check=ThisApplication.ActiveDocument.FullFileName MessageBox.Show(Check) Dim Testprop As String Testprop=iProperties.Value("Project", "Part Number") MessageBox.Show(Testprop)
Solved! Go to Solution.
Solved by rossano_praderi. Go to Solution.
Hi,
there are many posts where you can find your solution, this one of my.
Read the comments in red.
Within this post there is an example that read the Iproperties of an occurence in an assembly without open the occurence file.
http://forums.autodesk.com/t5/inventor-customization/ilogic-problem/m-p/5402561#M52708
Bregs
Rossano Praderi
Hi Rossano,
Thank you for your reply.
Forgive me, whilst there may be many posts where I can find the solution I have been unable to find it and I post as a last resort. I appreciate that what I am trying to achieve maybe quite simple but I am unable to discover how to do it. Even in the link you have provided I am unable to find the solution.
This is just a snippet of a larger rule I am trying to write piece by piece, and as such it is important to open the file and check the properties. I know how to read the properties of an occurrence of an assembly.
I use this line in my rule based on your suggestion:
Dim oDocument As inventor.Document = ThisApplication.documents.itembyname(TemPath)
I take it I now need to do “something” with the oDocument, but what?
Here is my updated code which still returns the Part Number of the assembly:
SyntaxEditor Code Snippet
TemPath= "K:TEMPLATE.ipt" ThisApplication.Documents.Open(TemPath) Dim oDocument As inventor.Document = ThisApplication.documents.itembyname(TemPath) Check=oDocument.FullFileName MessageBox.Show(Check) Dim Testprop As String Testprop=iProperties.Value("Project", "Part Number") MessageBox.Show(Testprop)
Hi DRLTKSE,
when you copy and paste or write a piece of code you have to check the correct syntax.
TemPath= "D:\Projects\Inventor\Projects\Example\Example.ipt" 'fullfilename with path Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(TemPath) Testprop = oDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value MessageBox.Show(Testprop)
If you have more questions, ask.
Bregs
Rossano Praderi
Rossano,
Thank you very much. That works perfectly.
I have now added some code to change a parameter too.
SyntaxEditor Code Snippet
TemPath= "K:\TKSY WASHER TEMPLATE.ipt" ThisApplication.Documents.Open(TemPath) Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(TemPath) Check=oDocument.FullFileName 'MessageBox.Show(Check) Dim Testprop As String Testprop = oDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value MessageBox.Show(Testprop) Dim oParameters As Parameters oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters Dim oLengthParam As Parameter oLengthParam = oParameters.Item("OD") oLengthParam.Expression = "75" ThisApplication.ActiveDocument.Update
Are you sure?
Would you like to change a parameter in the "ActiveDocument" or in "oDocument"?
To change a parameter in your "oDocument" you should use "oDocument" instead of "ThisApplication.ActiveDocument".
Bregs
Rossano Praderi
Yes I know, but in some cases the "ActiveDocument" can be associated to a document that is not your "oDocument".
Right now you have a simple rule, if you gonna have a more complex code you will have some troubles to get it work properly.
If you use the assigned document (oDocument) you are always sure of the given result.
If you use the "ActiveDocument" you can not be sure at 100% of the given result.
This is my opinion.
Bregs
Rossano Praderi