I have looked through the forum and cannot find an answer...forgive me if I missed it ๐
Our company is looking for a way to hide (turn off visibility) of all bolts, washers, and nuts ONLY within an Assembly (including any sub-assemblies).
This hardware is from the Content Center (Vault Environment), so I am hoping there is a way to code using a "relative" parameter or other means to only search, hide and save.
I am not sure if a View Representation or a LOD would be more advantageous, but we tend to prefer View Reps as they are a bit more friendly on the drawing side of things.
There are several folks here familiar with iLogic/VBA, so if even a start in the right direction would be greatly appreciated!
We have also searched the apps.autodesk with no luck.
Thank you in advance and look forward to any information you all might have!
You could use the path for the 'relative' value. The file paths of all nuts and bolts would still be in the 'content center files' designated local storage (and vault storage library folder) for standard content center parts. View reps would be fine (that's where visibility is used anyway) so long as your not interested in calculating independent mass properties per view setting (requires level of detail rep with suppression overrides).
Using the Assembly.ComponentDefinition.Occurrences you can create a recursive program (program that calls itself, see my other posts for the code) to search for all components with a file path that includes your keywords, then tell the occurrence to become invisible. For nested assemblies be sure to use suboccurrences, and not plain occurrences, so they are rooted in the main assembly tree.
Good idea!
After looking more, I did find some code (from chandra.shekar.g) that simply looks at the Part Number/Stock Number but the code is throwing a syntax error for some reason...haven't figured it out yet.
I will likely contact or reply to his post for further assistance.
Thank you again for responding and the heads up on suboccurrences!
Please mention the forum discussion link which is used. I will look into it.
A document on "Design View Representation" is attached with post. Please go through it.
Thanks and regards,
Thank you for the reply bt.
After consideration, we would rather not use a path since our Vault environment (paths) will change in the near future due to software update, server and Vault configurations.
FYI: Vault\Content Center Files\en-US\ (this is not actually the path because of local workspace C:\$Work\...)
Chandra has also responded on his code and I believe using an iProperty field will suffice...just need to get it working with "Part Number" iProperty and suboccurrences.
Thank you again. Your willingness to help is VERY much appreciated!
Hi bferrell,
If you want to save yourself some coding time you can use the View Rep Hero app on the app store. It allows easy management of saved assembly 'filters' using any iProperties.
Luke
Chandra,
Sorry for the multiple posts...I replied on the mentioned forum link instead of here.
Here is your original code where I changed the iProperties field and "BT".
Dim assemblyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition Dim occ As Inventor.ComponentOccurrence For Each occ In assemblyDef.Occurrences.AllLeafOccurrences Dim refDoc As PartDocument = occ.Definition.Document If iProperties.Value(occ.Name,"Project", "Part Number").Contains("BT") Then occ.Visible = False Else occ.Visible = True End If Next
What appears to be happening is that because "BT" is not at the beginning of the field, the code is not parsing the field to see it.
If I change it to "A", it turns off visibility for everything in the assembly (since our Part Numbering always starts with "A")...curiously though it does not turn off a single Bolt Assembly (which are also named with "A").
Any thoughts?
I can't help but wonder if the Part Number and the File Name are different in some cases, could this be causing misleading results? Occurrence nodes are named by default off of the file name, not the part number. Part numbers are created by default off of the File Name when the file is first saved, so that would be expected behavior, but anybody can make the two not synchronized. The string.contains("text") should be able to find the text anywhere in a string value.
True, but we have code that pushes the file name into the part number field regardless of what someone may try to overwrite. Therefore, the part number and file name always match (synchronized).
I would hope that ".CONTAINS" searches the entire string. It just seemed odd that it works when using the 1st "entity" in the file name/part number, but nothing beyond that.
I assume there are other things going on with this code because I get errors when trying to use it on a different assembly.
AutoCAD LISP was never this frustrating (sarcasm).
Thank you for the response.
Strange. All parameters are correct. Also getting this error now after trying with a different assembly file.
CONTAINS do test hole string on my computer.... but see what the partnumber is first... look at the part number ... not Browser note , not filename but part number .... filename and Part number are not always the same.... Browser note can be anything and are not lock to filename or partnumber.''
if you want to use the browser name for this try this code
Dim assemblyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition Dim occ As Inventor.ComponentOccurrence For Each occ In assemblyDef.Occurrences.AllLeafOccurrences Dim refDoc As PartDocument = occ.Definition.Document MessageBox.Show(occ.Name.ToString, "Title") MessageBox.Show(iProperties.Value(occ.Name,"Project", "Part Number").ToString, "Title") 'without extension If iProperties.Value(occ.Name,"Project", "Part Number").Contains(":BT") Then occ.Visible = False Else occ.Visible = True End If Next End Sub
Part Number is correct (in iProperties...not browser).
The previous error is corrected by closing the file and reopening.
But code will not turn off visibility on a bolt assembly (created through "Bolted Connection").
If I edit the code to .Contains ("12345"), it will hide all parts with Part Number=12345 except the bolts.
Forgive my ignorance here, but is the code reading Part Number (iProperties) at the assembly level or down into each component (meaning the individual bolt, washer, nut, etc)?
Because these bolts are a Bolted Connection, the actual .ipt is found on Vault or locally and is Read-only...and when the bolt is first created the Part Number field is left empty.
So, the code only needs to read Part Number at the assembly level...not each .ipt within the assembly.
Could this be the issue?
Add a log statement in the loop that calls AllLeafOccurrences to read out the occurrence name and part number of each occurrence, then add a second statement right after the line that makes it invisible.
The first will confirm the file is even looked at (by AllLeafOccurrences), while the second will confirm it is not being filtered out by your IF statement.
Another method could be to create a self recursing program to go through the tree:
dim ACD as AssemblyComponentDefinition =asmDoc.ComponentDefinition
dim occs as List(of ComponentOccurrence) = ManualGetAllLeafOccurrences(ACD.Occurrences)
for each occ as ComponentOccurrence in occs
'if you didn't filter in the function before, do so now
occ.visible= false
next
Function ManualGetAllLeafOccurrences(occs as ComponentOccurrencesEnumerator) as List(of ComponentOccurrence)
dim occs as new List(of ComponentOccurrence)
for each occ as ComponentOccurrence in occs
'you can add some conditional statement here if you wish to filter, I'm just adding all of them
occs.add(occ)
if occ.SubOccurrences.count > 0 then
dim occSub as List(of ComponentOccurrence) = ManualGetAllLeafOccurrences(occ.SubOccurrences)
if occSub.count < 0 then
occs.addrange(occSub)
next
End Function
Or something like that. It would be good to see what relevant code you have written so far so we can look for minor snags that are getting in the way.
It seems the code is looking at the highest level assembly parts only and not looking at any/all sub-assemblies.
I keep seeing "suboccurrences" in other code examples, but I am not sure how to incorporate it into the code provided.
I do not need to look at all the parts (.ipt) in the assembly...only the sub-assemblies.
Example:
Main assembly: A12345.iam
Sub-assemblies: A12345 BT01.iam, BT02.iam, etc.
The code only needs to look at the Part Number value in each of the sub-assemblies and turn off visibility for any that contain "BT".
Here is the code so far:
Dim assemblyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition Dim occ As Inventor.ComponentOccurrence For Each occ In assemblyDef.Occurrences.AllLeafOccurrences Dim refDoc As PartDocument = occ.Definition.Document If iProperties.Value(occ.Name,"Project", "Part Number").Contains("BT") Then occ.Visible = False Else occ.Visible = True End If Next
Can't find what you're looking for? Ask the community or share your knowledge.