Open a file and check iproperties with iLogic

Open a file and check iproperties with iLogic

Anonymous
Not applicable
1,780 Views
7 Replies
Message 1 of 8

Open a file and check iproperties with iLogic

Anonymous
Not applicable

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)

 

 

0 Likes
Accepted solutions (1)
1,781 Views
7 Replies
Replies (7)
Message 2 of 8

rossano_praderi
Collaborator
Collaborator

Hi,

there are many posts where you can find your solution, this one of my.

Read the comments in red.

 

http://forums.autodesk.com/t5/inventor-general-discussion/ilogic-rules-work-when-run-separately-not-...

 

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



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 8

Anonymous
Not applicable

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)

 

 

0 Likes
Message 4 of 8

rossano_praderi
Collaborator
Collaborator
Accepted solution

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



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 5 of 8

Anonymous
Not applicable

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
0 Likes
Message 6 of 8

rossano_praderi
Collaborator
Collaborator

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



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
0 Likes
Message 7 of 8

Anonymous
Not applicable

It works either way

0 Likes
Message 8 of 8

rossano_praderi
Collaborator
Collaborator

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

 



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
0 Likes