iLogic - Suppress all features except Features with "DXFn" name

iLogic - Suppress all features except Features with "DXFn" name

amarcoc
Advocate Advocate
896 Views
11 Replies
Message 1 of 12

iLogic - Suppress all features except Features with "DXFn" name

amarcoc
Advocate
Advocate

Hi.

 

I rename features with DXF1, DXF2, DXF3, etc to export DXF faces with only those features active.

 

Am trying to make a simple iLogic macro to run feature tree and find DXF on each feature (that can be any type), but I cant even access features name. 

 

I want to exclude all features except features with DXF on its name. 

 

Any help?

 

Thanks!!!

0 Likes
Accepted solutions (2)
897 Views
11 Replies
Replies (11)
Message 2 of 12

JhoelForshav
Mentor
Mentor

Hi @amarcoc 

Do you simply want to suppress all features within a part without dxf in the name?

For Each oFeature As PartFeature In ThisDoc.Document.ComponentDefinition.Features
	If oFeature.Name.Contains("DXF") = False Then oFeature.Suppressed = True
Next

 

Message 3 of 12

amarcoc
Advocate
Advocate

Well, you made it look too simple 😅 . But Yes, that's what I need.

 

Made a small improvement to be case in-sensitive.

 

For Each oFeature As PartFeature In ThisDoc.Document.ComponentDefinition.Features
	If UCase(oFeature.Name).Contains("DXF") = False Then oFeature.Suppressed = True
Next

 

Any chance on saving features state before suppressing? To be able to restore original state later.

0 Likes
Message 4 of 12

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @amarcoc 

Regarding saving the state:

I thought I'd use the features attributes to store a simple boolean value in it for it's suppressed state.

For some reason though I couldn't create an attribute with boolean value, so i had to make it a string. I don't know why because I think it should work with ValueTypeEnum.kBooleanType.

 

Anyways,

this rule stores a string "True"/"False" as an attribute in the feature:

For Each oFeature As PartFeature In ThisDoc.Document.ComponentDefinition.Features
	If oFeature.Name.Contains("DXF") = False Then
		Dim oAttributeSet As AttributeSet
		Dim oAttribute As Inventor.Attribute
		If oFeature.AttributeSets.NameIsUsed("SuppressedInfo")
			oAttributeSet = oFeature.AttributeSets.Item("SuppressedInfo")
			Try
				oAttribute = oAttributeSet.Item("Suppressed")
				oAttribute.Value = If (oFeature.Suppressed, "True", "False")
			Catch
				If oAttributeSet Is Nothing Then MsgBox("hejhejhej")
				oAttribute = oAttributeSet.Add("Suppressed", ValueTypeEnum.kStringType, If (oFeature.Suppressed, "True", "False"))
			End Try
		Else
			oAttributeSet = oFeature.AttributeSets.Add("SuppressedInfo")
			oAttribute = oAttributeSet.Add("Suppressed", ValueTypeEnum.kStringType, If (oFeature.Suppressed, "True", "False"))
		End If
		oFeature.Suppressed = True
	End If
Next

Then to restore the features use this rule:

For Each oFeature As PartFeature In ThisDoc.Document.ComponentDefinition.Features
	If oFeature.AttributeSets.NameIsUsed("SuppressedInfo")
		Try
			Dim oSuppressed As String = oFeature.AttributeSets.Item("SuppressedInfo").Item("Suppressed").Value
			oFeature.Suppressed = If (oSuppressed = "True", True, False)
		Catch
		End Try
	End If
Next

Hope it helps 🙂

 

EDIT: I forgot to add your UpperCase improvement. Don't forget to add it to the code again 😉

Message 5 of 12

JhoelForshav
Mentor
Mentor

To late to edit the post now, but obviously the line

If oAttributeSet Is Nothing Then MsgBox("hejhejhej")

Should not be there! 😆 I just forgot to delete it...

Message 6 of 12

amarcoc
Advocate
Advocate

Thanks!!!!

 

That's it. I will work on your code from here. 

 

Thanks!!!

Message 7 of 12

amarcoc
Advocate
Advocate

Hi again.

 

One small issue:

- I run the first code. It will create the attribute set.

- If I suppress or unsuppress some feature, the attributeset will be outdated.

 

Any way to delete the whole attribute set before checking if the attribute exists?

0 Likes
Message 8 of 12

amarcoc
Advocate
Advocate
@JhoelForshav Could you check my last question? Any help? 🙂

 

0 Likes
Message 9 of 12

JhoelForshav
Mentor
Mentor

Hi @amarcoc 

Sorry I missed this question...

I don't really understand what you mean. Could you try to explain further? 🙂

0 Likes
Message 10 of 12

amarcoc
Advocate
Advocate

Please check attached "_TESTE.ipt" file.

 

You can make a quick test:

- Run your first macro and then run your second macro.

- You will find Hole5 and Hole4 suppressed, even if it wasn't suppressed before.

 

Under some conditions, the second macro won't restore original suppress state.

0 Likes
Message 11 of 12

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @amarcoc 

Thank you. Now I see the problem.

Try this as the first rule 🙂

Dim oDoc As PartDocument = ThisDoc.Document
Dim oSuppress As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oFeature As PartFeature In oDoc.ComponentDefinition.Features
	If oFeature.Name.Contains("DXF") = False Then
		Dim oAttributeSet As AttributeSet
		Dim oAttribute As Inventor.Attribute
		If oFeature.AttributeSets.NameIsUsed("SuppressedInfo")
			oAttributeSet = oFeature.AttributeSets.Item("SuppressedInfo")
			Try
				oAttribute = oAttributeSet.Item("Suppressed")
				oAttribute.Value = If (oFeature.Suppressed, "True", "False")
			Catch
				oAttribute = oAttributeSet.Add("Suppressed", ValueTypeEnum.kStringType, If (oFeature.Suppressed, "True", "False"))
			End Try
		Else
			oAttributeSet = oFeature.AttributeSets.Add("SuppressedInfo")
			oAttribute = oAttributeSet.Add("Suppressed", ValueTypeEnum.kStringType, If (oFeature.Suppressed, "True", "False"))
		End If
		If oFeature.Suppressed = False Then oSuppress.Add(oFeature)
	End If
Next
oDoc.ComponentDefinition.SuppressFeatures(oSuppress)

The thing is that because of relationships. Suppressing one feature resulted in another feature being suppressed before the code had the chance to check it. Therefore the attribute was set to suppressed.

0 Likes
Message 12 of 12

amarcoc
Advocate
Advocate

Thank you. Understood the problem!

 

Worked perfect.

 

0 Likes