Suppress all features starting with 02 or 03 etc. in a part

Suppress all features starting with 02 or 03 etc. in a part

michael_janssenCN38L
Advocate Advocate
304 Views
4 Replies
Message 1 of 5

Suppress all features starting with 02 or 03 etc. in a part

michael_janssenCN38L
Advocate
Advocate

michael_janssenCN38L_0-1729231311652.png

We have an ilogic code that allows you to switch features back and forth with the suppression using the "low and high" parameters. This has worked wonderfully so far.

But I'm looking for a shorter way where I say: suppress all features that start with "03 - ".

Does anyone have a solution?

Attached is the current ilogic code

 

Dim part As PartDocument = ThisDoc.Document

Dim features As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()

Features.Add(Feature.InventorFeature("Extrusion - polygon:1"))
Features.Add(Feature.InventorFeature("Rectangular Pattern - polyon:1"))


If Level:of:detail = "low" Then
	Dim featuresToSuppress = ThisApplication.TransientObjects.CreateObjectCollection()
	For Each f As PartFeature In features
		If Not f.Suppressed Then featuresToSuppress.Add(f)
	Next

	part.ComponentDefinition.SuppressFeatures(featuresToSuppress) 'NO Error
End If

If Level:of:detail = "high" Then
	Dim featuresToUnsuppress = ThisApplication.TransientObjects.CreateObjectCollection()
	For Each f As PartFeature In features
		If f.Suppressed Then featuresToUnsuppress.Add(f)
	Next
	part.ComponentDefinition.UnsuppressFeatures(featuresToUnsuppress) ' NO Error
End If

 

Where 2 feature suppressions now take place:

Features.Add(Feature.InventorFeature("Extrusion - polygon:1"))

Features.Add(Feature.InventorFeature("Rectangular Pattern - polyon:1"))

If possible, I would like to replace this with e.g.:

Features.Add(Feature.InventorFeature("03 - *.*"))

 

michael_janssenCN38L_1-1729231864870.png

 

 

0 Likes
305 Views
4 Replies
Replies (4)
Message 2 of 5

Michael.Navara
Advisor
Advisor

You can use LINQ expression for this. Sample below just prints the count and names of the features which starts with "03 - " to iLogic log window.

 

Dim part As PartDocument = ThisDoc.Document
Dim nameStartsWith = "03 - "
Dim partFeatures As PartFeature() =
	part.ComponentDefinition.Features.OfType(Of PartFeature).Where(
		Function(partFeature) partFeature.Name.StartsWith(nameStartsWith)).ToArray()

'Do something with result
Logger.Debug(partFeatures.Count())
For Each PartFeature As PartFeature In partFeatures
	Logger.Debug(PartFeature.Name)
Next
0 Likes
Message 3 of 5

michael_janssenCN38L
Advocate
Advocate

Unfortunately, I don't get the connection. Unfortunately, my knowledge of Ilogic is too limited for that.

When I insert the code, I get the following error message:

 

michael_janssenCN38L_0-1730102990076.png

 

0 Likes
Message 4 of 5

Michael.Navara
Advisor
Advisor

This two code snippets are not compatible as is.

My code snippet shows how to select part features which name starts with "03 - " and put them to the variable partFeatures. Later on, you can do something with this array of features. For example print names to the log window (my sample) or convert the array to ObjectCollection and suppress/unsuppress this features.

The error you get because variable features is not declared and iLogic interprets it as type Inventor.Features.

0 Likes
Message 5 of 5

Curtis_Waguespack
Consultant
Consultant

@michael_janssenCN38L , I think this might work for you, or at least give you a nudge in the right direction.

 

Hope that helps,

Curtis

 

Dim part As PartDocument = ThisDoc.Document

Dim features02 As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
Dim features03 As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()

For Each f As PartFeature In part.ComponentDefinition.Features
	If Left(f.Name, 4) = "02 -" Then features02.Add(f)
	If Left(f.Name, 4) = "03 -" Then features03.Add(f)
Next

For Each f As PartFeature In features02
	f.Suppressed = (Level:Of:detail = "low")
Next

For Each f As PartFeature In features03
	f.Suppressed = (Level:Of:detail = "high")
Next

 

EESignature

0 Likes