iLogic to turn off adaptive of every feature in part

iLogic to turn off adaptive of every feature in part

Manuelcamposcosta
Advocate Advocate
2,294 Views
13 Replies
Message 1 of 14

iLogic to turn off adaptive of every feature in part

Manuelcamposcosta
Advocate
Advocate

I'm trying to make an ilogic which should be run from a part and will cycle trough every feature (extrusion/planes etc.) and switch adaptive off I think I'm almost there but I'm getting an error.

 

I don't want to switch off in the documents settings I want to keep the link for future reference.

 

here is what I'm trying, I'm trying to learn by myself and trying to combine codes from every where 🙂

 

The next one I will try to do is the same but trough an assembly file and for parts and assemblies that have a normal bom structure, I have one that does that for every file but trough the documents settings and breaks the links.

 

My main point is to not break the link because I might want to use that project for other things and might need to activate them.

Dim oFeature As PartFeature
oFeatures = ThisApplication.ActiveDocument.ComponentDefinition.Features

For Each oFeature In oFeatures
	'get the name of the feature
	oName=oFeature.Name
	If oName.Adaptive = True
oName.Adaptive = False End If Next

 thanks!

Manuel Campos Costa
0 Likes
Accepted solutions (2)
2,295 Views
13 Replies
Replies (13)
Message 2 of 14

J-Camper
Advisor
Advisor

This should be all you need:

 

For Each oFeature As PartFeature In ThisApplication.ActiveDocument.ComponentDefinition.Features
	If oFeature.Adaptive = True Then oFeature.Adaptive = False
Next

 

Since you are using "ThisApplication.ActiveDocument" I though you might be writing this to save externally, so If you want to use this as an external rule, you will want to put a lockout line before it like this to avoid errors if it gets run in any other document type by accident:

 

If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule is designed to only work in part documents.", "Wrong Document Type") : Exit Sub

 

 

Message 3 of 14

Manuelcamposcosta
Advocate
Advocate

Thanks for the help, yes I want to run it externally.

 

It isn't doing anything to me. Does it work for you? It's only working the file type check.

 

I saved it like this:

 

If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule is designed to only work in part documents.", "Wrong Document Type") : Exit Sub
For Each oFeature As PartFeature In ThisApplication.ActiveDocument.ComponentDefinition.Features
	If oFeature.Adaptive = True Then oFeature.Adaptive = False
Next

 

 

Manuel Campos Costa
0 Likes
Message 4 of 14

J-Camper
Advisor
Advisor

It is working as intended for me, but if you are getting the "Wrong document type" message then you must not be running it with a part document active. It won't do anything unless you have a part document open/active and that part document has features set to adaptive.  I can open a part document, set a few features to adaptive, run the rule, and the features are not adaptive anymore. 

 

Do you want a message if nothing has to be changed? it will add a couple lines of of code:

If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule is designed to only work in part documents.", "Wrong Document Type") : Exit Sub
Dim Counting As Integer = 0
For Each oFeature As PartFeature In ThisApplication.ActiveDocument.ComponentDefinition.Features
	If oFeature.Adaptive = True Then oFeature.Adaptive = False : Counting +=1
Next
If Counting = 0 Then MessageBox.Show("There were not any adaptive part features to change.","No Significant Change")

 

Let me know if you are still experiencing an error.

 

 

Message 5 of 14

Manuelcamposcosta
Advocate
Advocate

Yes I know that I was just telling that that part of the code was working, I found the problem, I was trying to run for a file outside the project folder, for precaution I copied a part file for desktop which had adaptivity on for some features and it didn't work, but now I tried for a part in the .ipj folder and it worked, strange but ok for me.

 

THANKS A LOT FOR THE HELP!! 🙂 This saves me a lot of time, because inventor doesn't allow for multiple selection of features and then turn adaptive off

 

EDIT: I'm wrong it's still not working for some files don't understand why.

What I notice is in one file it doesn't work, I switch one feature off and on and then run the rule again and it works.

 

I'm attaching one file for you that doesn't work for me.

Manuel Campos Costa
0 Likes
Message 6 of 14

Ivil
Enthusiast
Enthusiast

Can you please make this work in a assembly to remove adaptivity to all sub-parts.

0 Likes
Message 7 of 14

Manuelcamposcosta
Advocate
Advocate

I can't , it wasn't done by me, and it's not working properly for me in parts.

 

Anyway what you are asking is also very useful.

Manuel Campos Costa
0 Likes
Message 8 of 14

Manuelcamposcosta
Advocate
Advocate

@J-Camper  Could you please help me out this ilogic could be very usefull but I'm not being able to get it to work, attached is a part where it doesn't work.

 

I'm using the following ilogic:

If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then MessageBox.Show("This rule is designed to only work in part documents.", "Wrong Document Type") : Exit Sub
Dim Counting As Integer = 0
For Each oFeature As PartFeature In ThisApplication.ActiveDocument.ComponentDefinition.Features
	If oFeature.Adaptive = True Then oFeature.Adaptive = False: Counting += 1
Next
If Counting = 0 Then MessageBox.Show("There were not any adaptive part features to change.", "No Significant Change")

 

Manuel Campos Costa
0 Likes
Message 9 of 14

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Manuelcamposcosta 

 

I didn't take the time to determine the issue, but when I ran this rule to see if the features returned Adaptive = True, none of the features returned true.

 

For Each oFeature As PartFeature In ThisDoc.Document.ComponentDefinition.Features
	Logger.Info(oFeature.Name)
	Logger.Info(oFeature.Adaptive)
	Logger.Info("")
Next

 

So I used this to try and set the feature to be adaptive = true first, and then set it to adaptive = false, and it worked on this part.

 

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

For Each oFeature As PartFeature In oDoc.ComponentDefinition.Features
	Logger.Info(oFeature.Name)
	Logger.Info(oFeature.Adaptive)

	Try
		oFeature.Adaptive = True
	Catch
	End Try
	
	oFeature.Adaptive = False

Next

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

Message 10 of 14

J-Camper
Advisor
Advisor
Accepted solution

@Curtis_Waguespackthank you for that.  I don't remember why I abandoned this post last year, but I was looking into it again this morning.  I noticed the same thing about the features already being marked as not adaptive, but i started going down the rabbit hole of maybe I needed to set adaptive property for Sketch & sketch entities somehow first.  Never tried to set toggle them back and forth like that.

 

@Manuelcamposcosta& @Ivil , I put Curtis's fix into a a rule that will run in a part or assembly.  I added a prompt for the assembly to confirm you want to toggle the adaptive property for all parts in the assembly, in case it gets accidentally run.  The prompt can be removed if you want.  See code below:

 

Sub Main
	
	Dim pDoc As PartDocument = TryCast(ThisApplication.ActiveDocument, PartDocument)
	If Not IsNothing(pDoc) Then Call ToggleAdaptiveFeatures(pDoc, False) : Exit Sub
	
	Dim aDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument)
	If Not IsNothing(aDoc) Then Call RunAssemblyForAdaptiveFeatures(aDoc, False) : Exit Sub
	
	Logger.Debug("Not called in part or Assembly")
	
End Sub

Sub ToggleAdaptiveFeatures(oDoc As PartDocument, Toggle As Boolean)
	
	For Each oFeat As PartFeature In oDoc.ComponentDefinition.Features
		Try
			oFeat.Adaptive = Not (Toggle)
		Catch : End Try
		oFeat.Adaptive = Toggle
	Next
	
End Sub

Sub RunAssemblyForAdaptiveFeatures(oDoc As AssemblyDocument, PassToggle As Boolean)
	
	If MessageBox.Show("This rule will set all Part Features Adaptive Property in ALL Part components to: " & PassToggle & ".  Are You sure you want to do this?", "Verify Run", MessageBoxButtons.YesNo) <> vbYes Then Exit Sub
	
	For Each refDoc As Document In oDoc.AllReferencedDocuments
		If oDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(refDoc).Count < 1 Then Continue For
		If refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For	
		Call ToggleAdaptiveFeatures(refDoc, PassToggle)
	Next

End Sub

 

 

Let me know if you have any questions, or if this is not working as intended.

Message 11 of 14

Manuelcamposcosta
Advocate
Advocate

🙂 I had already noticed that, like @J-Camper mentioned I also tried to use sketches instead of features, because for some reason this ilogic isn't considering does features being adaptive.

 

Your ilogic is perfect it could only be improved to only act on the ones that are adaptive to make the code faster, because it's turning on and off all the features. I believe there is some sort of bug with inventor and knowin if it's adaptive or not, because the first ilogic @J-Camper posted did work if you created a feature and then test the ilogic.

 

Anyway thanks a lot for the help!! This works perfectly for what I need.

Manuel Campos Costa
0 Likes
Message 12 of 14

Manuelcamposcosta
Advocate
Advocate

@J-Camper @Curtis_Waguespack  I will consider your solutions to my problem your Christmas gift to me !

 

This is just perfect!

 

I can only see a problem with turning on and off it's because when we have moving parts that have some kind of geometry that is not always in the same place because of the movements of the machine, there could be times that you turn on the adaptivity and it could give an error because the information of the other part that was given to the other isn't there anymore or it's causing modelling problems.

 

I simple solution would be to first turn off the adpativity of every assembly and then all parts, then in the end make what you have done, turn on and off the adaptivity of every feature and every part.

 

Anyway many thanks for both of you for the fast help! I will use the every time I finish a project.

Manuel Campos Costa
0 Likes
Message 13 of 14

A.Acheson
Mentor
Mentor

Not sure if you are still in need of a solution. But I did come across the same issue when looking at purely occurrences. I found a work around by looking at the context menu of the occurrence and check if the button "make adaptive" in my case was checked or not  by the command method.   Seemed to work as a work around but it would be nice if the get portion of the adaptive boolean was working. I think you could make it work for this situation by looking at the Adaptive button on each feature. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 14 of 14

Manuelcamposcosta
Advocate
Advocate

I don't understand what you are saying😅

 

But for the problem I mentioned what I'm doing so I don't have any problem is that in the end of a project I copy all my parts to an empty assembly then I run the rule, this way the adaptive features when turn on will not do anything because those parts are already adaptive from another assembly.

Manuel Campos Costa
0 Likes