Find parts with custom iProperty and suppress them

Find parts with custom iProperty and suppress them

InventorMan1
Participant Participant
2,204 Views
15 Replies
Message 1 of 16

Find parts with custom iProperty and suppress them

InventorMan1
Participant
Participant

I am creating 3D-model templates and I have a following problem:

In our model sub-assemblies and parts are suppressed using iLogic and Excel-parameters. While this is quite easy task the problems arouses, when we use copy design, because the names of the parts change (which obviously the iLogic rule is calling on). I have found a workaround on the forum to just freeze the name on the browser, but that does not please our team.

 

So what i wish to do is to add custom iProperty which holds on a permanent part name, which does not change during copy design. Then iLogic rule should find all parts with this certain custom iProperty and suppress/unsuppress them. Could someone help me with the code to find the parts inside the assembly that includes certain iProperties?

0 Likes
Accepted solutions (1)
2,205 Views
15 Replies
Replies (15)
Message 2 of 16

Cadmanto
Mentor
Mentor

Ossi,

Welcome to the forum.

Sounds like you are trying to find an iLogic routine that undoes the Ilogic routine to some degree.  I am not your guy, when it comes to iLogic, but in the interim have you tried using the filter at the top of the model browser?

 

filter.jpg

 

 

check.PNGIf this solved your issue please mark this posting "Accept as Solution".

Or if you like something that was said and it was helpful, Kudoskudos.PNG are appreciated. Thanks!!!! Smiley Very Happy

 

New EE Logo.PNG

Inventor.PNG     vault.PNG

Best Regards,
Scott McFadden
(Colossians 3:23-25)


0 Likes
Message 3 of 16

InventorMan1
Participant
Participant

Thank you!

 

And thanks for that tip, didn't know about the ability to search also through iProperty-values. But what I'm trying to accomplish here is that I want all this to happen automatically. That's why I'm seeking for the iRule for it.

 

0 Likes
Message 4 of 16

InventorMan1
Participant
Participant

So this is what I have put together. Majority of this is simply copied code from this forum with little modification, so it can include older syntax.

 

So in the code after defining variables, rule checks if custom iPropert "Fixed_Name" is empty or not. If not, then it will check does it include value "Cylinder"  and if it does, the component is suppressed or unsuppressed according to above if-sentence. Still the code is relatively messy so there should be a more simple way to all this? Also is there any idea how to make this work for many parts? In the assembly there could be many variations, which means new rule for each component?

 

Any ideas?

 

SyntaxEditor Code Snippet

Sub Main()

'Dim oDoc As AssemblyDocument
'Set oDoc = ThisApplication.ActiveDocument
oDoc = ThisDoc.Document

Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence

For Each oOcc In oDef.Occurrences

On Error Resume Next
Dim oRefDoc As Document = oOcc.Definition.Document

' Get the User Defined Property Set
Dim oCustomPropSet As PropertySet = oRefDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

'Dim oCustomProp As Property 
oCustomProp = oCustomPropSet.Item("Fixed_Name")

If Suppress_Cylinder = 1 Then
If Not oCustomProp Is Nothing Then
If oCustomProp.Value = "Cylinder" Then
oOcc.Suppress
End If
End If
ElseIf Suppress_Cylinder = 0 Then
If Not oCustomProp Is Nothing Then
oOcc.Unsuppress
End If
End If
Next

End Sub

 

0 Likes
Message 5 of 16

MechMachineMan
Advisor
Advisor

No, this will go through all occurrences in the assembly. You have a LOOP in your code that's looping through the collection of occurrences. (or should)

 

 

The only change that may be required is adding all Leaf Occurrences... I think just using Occurrences only does top level.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-729F272D-821C-4DFF-B604-8C89035D6D88

 

 

 

Sub Main()

    oDoc = ThisDoc.Document

    Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

    Dim oOcc As ComponentOccurrence

    For Each oOcc In oDef.Occurrences.AllLeafOccurrences
        On Error Resume Next
        Dim oRefDoc As Document = oOcc.Definition.Document

        Dim oCustomPropSet As PropertySet = oRefDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

        oCustomProp = oCustomPropSet.Item("Fixed_Name")

        If Suppress_Cylinder = 1 Then
            If Not oCustomProp Is Nothing Then
                If oCustomProp.Value = "Cylinder" Then
                    oOcc.Suppress
                End If
            End If
        ElseIf Suppress_Cylinder = 0 Then
            If Not oCustomProp Is Nothing Then
                oOcc.Unsuppress
            End If
        End If
    Next

End Sub

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 6 of 16

InventorMan1
Participant
Participant

Thank you, that is good suggestion. But it really does not help on all the problems.

 

1. If part is suppressed, the iProperty-data is not readable. That's why in my newest version I active each part during the For-Loop.

 

2. For some reason the For-Loop breaks or something unexpected happens, since this does not work logically. Does End If also break out from For-Loop ?

 

3. If the Assembly is large, activating every component one by one can probably be slow, so this is not the best option.

 

SyntaxEditor Code Snippet

Sub Main()

	oDoc = ThisDoc.Document

	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

	Dim oOcc As ComponentOccurrence
	
	For Each oOcc In oDef.Occurrences.AllLeafOccurrences
		On Error Resume Next
		Dim oRefDoc As Document = oOcc.Definition.Document
		Dim oCustomPropSet As PropertySet = oRefDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
		oCustomProp = oCustomPropSet.Item("Fixed_Name")
		Component.IsActive(oOcc.Name) = True
		If Not oCustomProp Is Nothing Then
			If oCustomProp.Value = "Box" Then
				If Suppress_Box = 0 Then
					Component.IsActive(oOcc.Name) = False
				End If
			ElseIf oCustomProp.Value = "Cylinder" Then
				If Suppress_Cylinder = 0 Then
					Component.IsActive(oOcc.Name) = False
				End If
			End If
		End If
	Next

End Sub

 

 

 

0 Likes
Message 7 of 16

MechMachineMan
Advisor
Advisor
Accepted solution

I believe it could be because of the On Error Resume Next behavior.

 

Is there a reason you can't run the rule from a master LOD, or create a copy of the master LOD with everything unsuppressed to initially run it from?

 

You could always just put in a quick oOcc.Suppressed = True test and skip all files that are already suppressed.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 8 of 16

InventorMan1
Participant
Participant

The On Error Resume Next was the problem, right on ! I figured out to change it to Try-Catch-End Try- format and it works. Below the code that works for now (comments mainly for our staff).

 

Basically the idea is that the whole thing runs autonomously. So that's why I created iLogic-LOD that is also selected on drawings. And now when the code includes the unsuppressing parts, when changing parameter values, we can change back on forth between different product-types just by changing values on excel.

 

If someone has better ideas on this, please comment!

 

Sub Main()

    oDoc = ThisDoc.Document
    Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
    Dim oOcc As ComponentOccurrence
    
	For Each oOcc In oDef.Occurrences	'For-Loop, that goes through every part
        Component.IsActive(oOcc.Name) = True	'Unsuppress every component
		Try		'Try-Catch-Try skips component, if it doesn't include "Fixed_Name"-iProperty
        	Dim oRefDoc As Document = oOcc.Definition.Document
        	Dim oCustomPropSet As PropertySet = oRefDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
        	oCustomProp = oCustomPropSet.Item("Fixed_Name")	'Defining wanted custom iProperty name
				
				' Different classes for suppressing components:
				
				If oCustomProp.Value = "Cylinder" And Suppress_Cylinder = 0 Then
					Component.IsActive(oOcc.Name) = False	'Suppresses part if it contains correct iProperty AND parameter is zero
				ElseIf oCustomProp.Value = "Box" And Suppress_Box = 0 Then
					Component.IsActive(oOcc.Name) = False	'Suppresses part if it contains correct iProperty AND parameter is zero
				End If
				
		Catch
		End Try
    Next 'Ends For-Loop

End Sub

 

Message 9 of 16

diego_dorta
Enthusiast
Enthusiast

Hello everyone, trying to modify this rule to have a view representation that isolate the components with a certain iProp but not finding the way!!

 

can someone help?

 

thank you

0 Likes
Message 10 of 16

wfajber
Contributor
Contributor

I have such a routine where I traverse the entire assembly looking for all the parts or assembly files that matches a certain iProperty.  In our case we use a custom iProperty called ComponentClass.  If it is structural steel, then we are looking for iProperty ComponentClass = Structure, 

 

I create an empty collection and then do the assembly traverse, looking at each part and assembly file. If I find a  match  to the iProperty, I add it to the collection.

 

Then create a new design view representation (or see if it is existing, delete it, and create a new one).

Set the design view to HideAll so nothing is shown, then use

DesignViewRepresentation.SetVisibilityOfOccurrences( the collection I just made, visible = true)

 

This way it is easy to create a viewrep with say Structures only or Structures and Concrete, etc.

I found that setting the visibility one at a time goes very slow, but passing it a collection goes quite quickly.  We have some very assemblies and it works quite well.

 

There are also useful variations where we do a ShowAll, then turn the visibility = off.

0 Likes
Message 11 of 16

b_krznaric
Participant
Participant

I know this is an old post, but I am hoping you may be able to help me......I have been trying to find a way to search by iproperty. In the recent files this is possible but it seems like there is no way to search through all my files for a specific iproperty. Any help would be a life saver! Thank You

 

(PS I have heard vault does this but was hoping not to have to go that route just for search functionality)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 12 of 16

WCrihfield
Mentor
Mentor

Hi @b_krznaric.  Please provide as many details about what you are trying to do as possible.  There are so many questions I could ask here, to try and clarify exactly what you want or need, but maybe you could save us the time of asking all of those questions by providing more details.

  • What version/year of Inventor are you using?
  • When you say 'search by iProperty'...
    • Do you just mean a single iProperty, or multiple iProperties?
    • Only search for/within custom iProperties, or also search within all 'standard' iProperties?
    • If custom ones only, then just find if that property exists, or does its value matter?
      • If its value matters, then please explain that situation in more detail.
  • What do you mean by 'recent files'?
  • What do you mean by 'all my files?
    • Do you mean all documents that are being referenced by a specific assembly?
    • Do you mean all files in your entire Inventor Project file's workspace?
    • Do you mean all files in an entire directory on your local computer, or on a shared network drive?
  • What are you planning on doing with each 'file' or 'document' when it is found?...or what should the result be when one is found?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 16

b_krznaric
Participant
Participant

OK so there are 3 of us. We only do individual parts, I am the one who brought inventor to the company so its been a tough ask to get them to try to learn that (they were using pencil and paper with limited CAD software for some parts). So we get orders that most of the time have a "drawing" name or number, sometimes they don't. Then we take those orders, give them an internal order number and make them into usable prints for the machinist. (We have to add grind stock and we have shrink factors) Sometimes the orders have a reference to the last time we made them (they give a reference to our internal order number) and sometimes they don't. Right now we have a whole filing cabinet system where some people are organized by part type and some customers are in by order number. Its a pain but until I can get other departments to make some changes its the hand we are dealt. When I make a part I like to save it as the drawing name example. TB5467B9  then we will label it the internal order number ex. 199123-1........if I could save everything by drawing name and add the order number to the comment section of the iproperties then we would be able to search for the drawing or the order name. Now there might be an easier way but we have some parts that are super similar but have 1000 variations.  I have made full templates so I just have to punch in numbers to get a print made but that only helps on common style jobs. We do have alot of jobs that only come in once a year or once every 3 years. Please let me know if I can provide any more information. Thanks!

 

Inventor 2026

We don't use assembly at all.

0 Likes
Message 14 of 16

WCrihfield
Mentor
Mentor

Thanks, @b_krznaric.

So, it sounds like you would need a tool or utility that you could use to search through an entire specified directory of files, and maybe even all of that directories sub directories.  Does that part sound correct to you?

And while it is searching, it will need to find all Inventor Part files (.ipt file extension) or all Inventor drawing files (.idw or .dwg file extension), or both types of files, right?

And when if finds those types of files, it will need to 'open' them (can be invisibly, which processes faster) in Inventor, so that it can access their iProperties.  When it gets them open, it sounds like it would need to check the value of two different iProperties.  It sounds like one of those would be the one called "Comments", where you are planning on putting the 'internal order number' information.  But I am not sure which other iProperty you were planning on using for what you are calling the 'drawing name'.  Is that going to be in the "Part Number" iProperty, or in the "Title" iProperty, or in the "Description" iProperty, or are you just talking about the name of the file itself, without its path, and without its file extension?

 

All that so far sounds possible to create an iLogic rule based tool for, but what should happen when a file is found that matches one, or both search criteria?

  • Should that file just be 'visibly' opened in Inventor?
    • If so, what if there are multiple matches?
    • Should is stop searching when it finds the first match, or keep searching to see if there are multiple matches.
    • If there are tons of files in that directory for it to search through, it might degrade Inventor's performance while it is running, or cause Inventor to freeze-up, because no telling how long it might take to process.
  • Should it just show a pop-up message, with some information in it?...If so, what message or what information?
  • Should it do something else...

Also keep in mind that when dealing with String type data (text), capitalization differences, leading or trailing spaces differences, spelling differences, special character differences, can all lead to two relatively similar pieces of text not being a match (or 'equal' to each other).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 16

b_krznaric
Participant
Participant

Just being able to search thru the comments, so if we do part x and but in comment 1001 the first time we do it. The next time we get it we would go to the next line down in the comment section and for example name it 1502 (if that is where we are in the order numbers)......then when we get a reference number (usually but not always) the most recent time we did the job (1502) we could search for 1502 and it would come up, sometimes unfortunitly we get an old order number for this example 1001, but because both would be in there in the comment section we would hopefully be able to search for either one and get the same file. If making the file open is the only way to make it work that is ok but any option would work where we would be able to find it.

So there "should" never be more then 1 instance of the same number but it would be good to show if it did find another. There will eventually be some customers with 100's of files. Will searching through those take along time?

0 Likes
Message 16 of 16

WCrihfield
Mentor
Mentor

Yes, Inventor documents must be opened before we can access their iProperties.  I am not really sure how they support the ability to right-click on Inventor files in the Windows file explorer, choose Properties in the context menu, and be able to get access to some of the iProperties that way.  Must be an external helper app that gets installed with Inventor, or the Inventor SDK stuff.  As I mentioned though, files can be opened invisibly, so that there is no document tab for them, and no 'view' for them in the user interface.  Opening them that way makes stuff process faster, because there are no 'graphics' to process or keep updated.

This is sounding like it might potentially be either too difficult, or too long running for a simple iLogic rule, ran from within Inventor, to handle, but I'm not sure.  Sounds like it might be better suited for 'Apprentice' which is sort of like a lighter version of Inventor, with no user interface, and very limited abilities, used from external EXE type applications, instead of Inventor, for doing lighter tasks like reading or editing iProperties, inspecting stuff, and minor tweaks.  I have never used it before myself, because I can not develop EXE's right now where I work, due to corporate security restrictions.  It sort of depends on how many files there are, and if it may run into any files that have 'issues' that might pop-up when opened, and such things.

You still did not answer my question about what should happen when a file is found with matching text in its Comments iProperty value.

I do not have Vault, and have never used it myself, but yes, from the sounds of it, that resource would likely be very helpful in a situation like this.

Actually, now that I think of it, if you do not have Vault, you could try using the Inventor Design Assistant application.  It is a separate application that usually get installed when you install Inventor.  It has various uses, but I think one of its uses is for 'finding Inventor files' that match certain criteria.  And I believe it will let you search within their iProperty values also.  It should let you specify what types of Inventor files, and what project area or directory to search within also.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes