iLogic Adaptivity Toggle

iLogic Adaptivity Toggle

Anonymous
Not applicable
510 Views
2 Replies
Message 1 of 3

iLogic Adaptivity Toggle

Anonymous
Not applicable

Hello!

 

I am attempting to adapt a script that turns off adaptivity for all parts and sub-assemblies (and their parts) to only turn off adaptivity for parts directly in the active assembly (and not sub-assemblies and their parts). This is the first script, which works as expected and turns off adaptivity for all parts and subassemblies at all levels:

'checks if active document is an assembly
dim doc as Document = ThisApplication.ActiveDocument
if doc.DocumentType <> kAssemblyDocumentObject then
    MessageBox.Show("This document is not an assembly. This script can only be used on an assembly.", "Oops...")
    return
end if

'iterates through each file and turns off adaptivity for all adaptive files
dim i as integer = 0
for each oDoc as Document in doc.AllReferencedDocuments
	try 
		if oDoc.ModelingSettings.AdaptivelyUsedInAssembly = true then
			oDoc.ModelingSettings.AdaptivelyUsedInAssembly = false
			i += 1
		end if
	catch
	end try
next

MessageBox.Show("Adaptivity was turned off for " & i & " file(s).", "Success!")

 

And this is my attempt to run this rule only on parts files directly in the active assembly:

'checks if active document is an assembly
dim doc as Document = ThisApplication.ActiveDocument
if doc.DocumentType <> kAssemblyDocumentObject then
    MessageBox.Show("This document is not an assembly. This script can only be used on an assembly.", "Oops...")
    return
end if

'iterates through each file in the active document and turns off adaptivity for all adaptive files
dim i as integer = 0
for each oDoc as Document in doc.AllReferencedDocuments
	Try 
		If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject and oDoc.ModelingSettings.AdaptivelyUsedInAssembly = True Then
			oDoc.ModelingSettings.AdaptivelyUsedInAssembly = false
			i += 1
		end if
	catch
	end try
next

MessageBox.Show("Adaptivity was turned off for " & i & " file(s).", "Success!")

 

Unfortunately, the second script seems to behave identically to the first script and I'm not sure why. Any help?

0 Likes
Accepted solutions (1)
511 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

If you change from AllReferencedDocuments to just ReferencedDocuments in your code it will only iterate the direct references and not all.

 

So instead of:

for each oDoc as Document in doc.AllReferencedDocuments

It should be

for each oDoc as Document in doc.ReferencedDocuments
Message 3 of 3

Anonymous
Not applicable

Wow, it's always something simple. I don't even need to alter the script at all beyond removing "all" from that one line. Thanks!

0 Likes