New to iLogic: how to order/split code

New to iLogic: how to order/split code

DavidTunnard
Collaborator Collaborator
951 Views
7 Replies
Message 1 of 8

New to iLogic: how to order/split code

DavidTunnard
Collaborator
Collaborator

Hi All,

 

I am just starting out with iLogic. I have got two separate rules which work together. Basically where I work saves files in such a way that the part number gets overwritten whenever the file gest saved as. So the first bit moves the part number:

iProperties.Value("Summary", "Title") = iProperties.Value("Project", "Part Number")

and the second part moves the part number back and deletes it from where I moved it to:

iProperties.Value("Project", "Part Number") = iProperties.Value("Summary", "Title")
iProperties.Value("Summary", "Title") = Nothing

These work for what I want. However, think it would be better to have them in one rule. so I put them together like so:

While iProperties.Value("Summary", "Title") = iProperties.Value("Project", "Part Number")
End While


While iProperties.Value("Project", "Part Number") = iProperties.Value("Summary", "Title")
iProperties.Value("Summary", "Title") = Nothing
End While

 This does not work anymore though... Can someone help explain to me what I need to do? If you need anymore info, please let me know!

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

DavidTunnard
Collaborator
Collaborator

just realised I copied the rules from when I was playing around with different functions. Here is what I have been starting with...

iProperties.Value("Summary", "Title") = iProperties.Value("Project", "Part Number")


iProperties.Value("Project", "Part Number") = iProperties.Value("Summary", "Title")
iProperties.Value("Summary", "Title") = Nothing

 

0 Likes
Message 3 of 8

WCrihfield
Mentor
Mentor

Hi @DavidTunnard.  I'm not sure I fully understand what you are trying to achieve here.  My system works the same way, where when you save a part using a SaveAs operation, it changes the Part Number value to match the new file name.  Are you trying to preserve the original Part Number value from before a SaveAs operation, then set it back in place after that SaveAs operation is finished? 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 8

DavidTunnard
Collaborator
Collaborator

Ah OK. I will try to explain it a bit better.

 

So say we have a part with a file name of 'Cap'. The iProperties description will be 'Cap' but the part number is usually something like '1000-01-01'. If we make a revision to that part we usually 'Save As' the file and call it 'Cap - Rev A'.

 

This then overwrites the part number field to the new file name. The last sentence of your message is correct. I am trying to keep the part number the same.

0 Likes
Message 5 of 8

WCrihfield
Mentor
Mentor
Accepted solution

OK.  I think I understand the situation now.  But in your initial posts you were using the 'Title', then in your last post, you said you were using the 'Description', so for now, I'm going to assume they both the 'Title' iProperty and the 'Description' iProperty contain the same data (what you call the part, other than its part number).  In this situation, I believe you will need two iLogic rules.  One that runs just before the document saves, which copies the current part number value to a custom iProperty, and is set-up within the Event Triggers dialog under the "Before Save Document" event.  Then the second rule, which will check for that custom iProperty, and if it exists, will copy its value to the 'Part Number' iProperty, which will be set-up within the Event Triggers dialog under the "After Save Document" event.

The first rule would look like this:

iProperties.Value("Custom","Saved Part Number") = iProperties.Value("Project", "Part Number")

The second rule would look like this:

Try
	iProperties.Value("Project", "Part Number") = iProperties.Value("Custom", "Saved Part Number")
Catch
End Try

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 8

DavidTunnard
Collaborator
Collaborator

Sorry, I should have explained that better.

 

I was just using the 'Title' field as a sort of placeholder for my part number as we never use that field. my next question was going to be how to copy it to an external temp file or something. But your use of a custom iProperty has solved this so thank you for that.

 

I have just tried it quickly and yes, I think this is working. Thank you very much!

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @DavidTunnard.  I thought I should also warn you that this is a very basic set-up, and should work OK when actively working with this document, however, the interface being used ("iProperties.Value()") within those two rules will always act upon whichever document is currently 'active' at that time (the 'active' document).  So, if this part is being referenced within an assembly or drawing, then then when you attempt to save the assembly or drawing, it may want to indirectly also save this part document, it may trigger these two rules to run.  In that situation, that assembly or drawing is currently visibly open and is the 'active' document, so the code will be trying to work with the iProperties of that assembly or drawing, instead of the part.  (Here is a link to one of my contribution posts where I go into document references in greater detail.)

 

If you need to avoid that situation, you may need to layout out these two iLogic rules a little differently, and make sure they are 'local' rules (saved within the document), instead of external rules.  In this scenario, you could set these two rules up like this:

Rule 1

 

Dim oDoc As Document = ThisDoc.Document 'points to 'local' document
Dim oPN As String = oDoc.PropertySets.Item(3).Item("Part Number").Value
Dim oCProps As PropertySet = oDoc.PropertySets.Item(4)
Try
	'try to find the custom iProperty (if it already exists), then set its value
	oCProps.Item("Saved Part Number").Value = oPN
Catch
	'it didn't find that custom iProperty, so create it, then sets its value
	oCProps.Add(oPN, "Saved Part Number")
End Try

 

Rule 2

 

Dim oDoc As Document = ThisDoc.Document 'points to 'local' document
Dim oPNProp As Inventor.Property = oDoc.PropertySets.Item(3).Item("Part Number")
Dim oCProps As PropertySet = oDoc.PropertySets.Item(4)
Dim oCProp As Inventor.Property
Try
	'Try to set the Part Number value from the custom iProperty
	oPNProp.Value = oCProps.Item("Saved Part Number").Value
Catch
	'it didn't find that custom iProperty,
	'so just exit the rule without doing anything
	'may be first time the file is saved
	Exit Sub
End Try

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

DavidTunnard
Collaborator
Collaborator

Thanks for the revision. I have put the rules you made into assembly documents and played around with different scenarios. All seems to be working fine without the revised, extra, code so far. I will stick with the original for now as I understand that and if I run into any problems I will change to the more advanced rules.

 

I had a read through the post you linked. Pretty hard for me to understand everything right now. I'm more of a visual learner so really need to work through some problems on my own I think to get a grasp of everything being explained to me.

 

thanks again!

0 Likes