Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open a file and check iproperties with iLogic

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
DRLTKSE
1498 Views, 7 Replies

Open a file and check iproperties with iLogic

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)

 

 

7 REPLIES 7
Message 2 of 8
rossano_praderi
in reply to: DRLTKSE

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
DRLTKSE
in reply to: 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)

 

 

Message 4 of 8
rossano_praderi
in reply to: DRLTKSE

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
DRLTKSE
in reply to: 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
Message 6 of 8
rossano_praderi
in reply to: DRLTKSE

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!
---------------
Message 7 of 8
DRLTKSE
in reply to: rossano_praderi

It works either way

Message 8 of 8
rossano_praderi
in reply to: DRLTKSE

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!
---------------

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report