- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All, I just started playing with iLogic and reading through all Forum posts to edit code to accomplish what I need.
We use Part1,Part2 etc. to name our parts and can include extra info after for example Part1 70x70x6 Angle
I have the following code that checks if part number is the same as file name then change Part number to Upper Case and if the Part number includes "PART" I get the number of the part and set it to Stock Number (As I only want to set Stock number for certain parts)
If Part number is not the Same it Changes it to file name and does the rest.
The Reason I am Getting the Stock Numbers is for my Parts Lists as I cant be certain Item numbers In BOM is same as Part Number and 99% of the time I have to set it Manually and keep making sure it is correct by enabling the part number in parts list checking and the removing part number again.
I set the Rule to Run After Open Document Trigger to make sure all Parts Assemblies and drawings have the Correct Part Number to Stop Errors from occurring in our drawings.
Our Parts Lists have Columns ITEM(Where I will now use Stock Number), Description, Mass and Material.
So Stock Number will now be used in our Balloons and Part detail labels Will Use Stock Number.
Sorry for the long Explanation, Here is my Question.
If the Part Number is Already the same as Filename and is set to Uppercase and Stock Number is Correct, can I stop it From Doing it again and again every time I open that File. So Basically just Check and Exit if it is Correct.
Stopping it from changing it every time will Reduce Processing time Immensely.
If my code is messy any Tips would be great!!
Before Rule
After Rule
Thank you
oDoc = ThisDoc.FileName(False) PartNumber = iProperties.Value("Project", "Part Number") If UCase(PartNumber) = UCase(oDoc) iProperties.Value("Project", "Part Number") = UCase(iProperties.Value("Project", "Part Number")) If iProperties.Value("Project", "Part Number").Contains("PART") Then GetString = Split(iProperties.Value("Project", "Part Number"), " ") 'Get First String Of Part Number, Get String from 5th Character(Starting Position), 5 Characters iProperties.Value("Project", "Stock Number") = Mid(GetString(0), 5, 5) End If Return Else iProperties.Value("Project", "Part Number") = oDoc iProperties.Value("Project", "Part Number") = UCase(iProperties.Value("Project", "Part Number")) End If If iProperties.Value("Project", "Part Number").Contains("PART") Then GetString = Split(iProperties.Value("Project", "Part Number"), " ") iProperties.Value("Project", "Stock Number") = Mid(GetString(0), 5, 5) End If
P.S. This was Compiled from Different posts about different changes adapted to fit my needs
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
with exit sub
Public Sub main
oDoc = ThisDoc.FileName(False)
PartNumber = iProperties.Value("Project", "Part Number")
If UCase(PartNumber) = UCase(oDoc)
iProperties.Value("Project", "Part Number") = UCase(iProperties.Value("Project", "Part Number"))
Exit Sub
If iProperties.Value("Project", "Part Number").Contains("PART") Then
GetString = Split(iProperties.Value("Project", "Part Number"), " ")
'Get First String Of Part Number, Get String from 5th Character(Starting Position), 5 Characters
iProperties.Value("Project", "Stock Number") = Mid(GetString(0), 5, 5)
End If
Return
Else
iProperties.Value("Project", "Part Number") = oDoc
iProperties.Value("Project", "Part Number") = UCase(iProperties.Value("Project", "Part Number"))
End If
If iProperties.Value("Project", "Part Number").Contains("PART") Then
GetString = Split(iProperties.Value("Project", "Part Number"), " ")
iProperties.Value("Project", "Stock Number") = Mid(GetString(0), 5, 5)
End If
End Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, thank you for the help.
Is there a way to check if the Stock number is correct and if it is, to then exit and do nothing.
Im trying to do it this way, if there are no changes needed the part wont need saving as saving every part again reduces processing speed.
This code makes it much more automated but some of my assemblies contain more than 5000 parts.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Did the new code from the Part number help top solve the initial problem?
I will help you further with Stock Number..
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, Sorry for the late reply.
Your code did clean it up, my code also worked but clearly yours is better.
What I Need to do is stop the Rule from running again if part number and Stock Number is correct.
Thanx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @helouise. You mentioned before that you did not want to save the part again if no changes were needed, but i didn't see anything within the code for saving the part. However, just in case this might be useful to you, there is a technique I often use in my rules that deal with iProperties. I use this to avoid saving the file if it is not necessary. When you access the iProperty sets the manual way (Document.PropertySets) the PropertySets object has a Property you can check called 'Dirty', which has a Boolean value that is ReadOnly. If any iProperties have changed since the document was opened, this property will change to True. At the end of a rule that may have changed some iProperties, where I would normally save and/or close the document, I check this value, and only Save if it is True.
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
What I meant is if I open the file it runs the rule and then it requires a save. Even if the properties were correct the rule still changed it so then it will prompt for save if I want to close the file.
If there are many parts in assembly this then takes a lot of time when i press save.
So I Just want the Rule to change the values if they are not correct otherwise do nothing.
It needs to check if part number is in capitals and the stock number is indeed the correct one according to Part Number if it is the do nothing.
Could you please Elaborate on your post for checking if it is dirty, I dont completely understand.
Apologies I am new to iLogic and this is a trial and Error process which takes a lot of time.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK. So that tip likely won't help you in this specific situation. So in Inventor's API or iLogic, Document objects and this PropertySets object both have this property called 'Dirty'. When you first open a document, the value of this property is False by default. When anything happens while that document is open that modifies it in a way that may cause it to want to save when you close it, that will change the value of that property to True. So checking the value of this property is one way of determining whether or not you may need to save a document. Lets say I have a rule that checks the value of an iProperty, and if the value isn't what I'm expecting, it will then change its value. If I just opened a document, then ran this rule, it may or may not have made any changes to that iProperty, because it may have not needed to change the value of the iProperty. At the end of that rule, I may want to determine if any changes were made that may need to be saved. I can check the value of that 'Dirty' property, and if its value is True, that means I should save the document, but if its value is False, I don't need to save the document, because no changes were made. It's just one fairly simple way to avoid saving a document, if its not needed, in case it may take a long time to save the document, and you want to avoid if possible.
So, just to recap, after reading your response, I don't believe you would benefit from using this technique here in this case. It's just a tip to keep in mind as your future rules get more complex.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
first check if the Partnumber is already Ucase
If Not PartNumber = UCase(oDoc)
iProperties.Value("Project", "Part Number") = UCase(iProperties.Value("Project", "Part Number"))
Exit Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning,
I have a similar issue which I am trying to solve, so basically, I have assembly idw's which I am updating. I have multiple parts and each one of them have stock number which I want to remove. I am doing it manually atm, I dont want to remove stock number from the iproperties but just on the idw. is there a way or code which I can use thanks.
i want to remove "basket support 2" but without manually clicking it and deleting it.
thanks, would appreciate the help