- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 ![]()
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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...
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @amarcoc
Sorry I missed this question...
I don't really understand what you mean. Could you try to explain further? ![]()
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report