Run rule from in all parts/sub-assemblies from top

Run rule from in all parts/sub-assemblies from top

Tigerpirro
Advocate Advocate
639 Views
4 Replies
Message 1 of 5

Run rule from in all parts/sub-assemblies from top

Tigerpirro
Advocate
Advocate

I have an external rule that I use to set up all my parts and assemblies. I need a code that I can run from the top level assembly that runs that rule in all parts and sub-assemblies.

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

theo.bot
Collaborator
Collaborator

you can go thru all the referenced parts and run your external rule. Here some reference how to go thru assembly structures Mod the Machine: Accessing Assembly Components (typepad.com)

 

Sub Main    
	' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
    oAsmDoc = ThisApplication.ActiveDocument
    ' Get all of the referenced documents.
    Dim oRefDocs As DocumentsEnumerator
    oRefDocs = oAsmDoc.AllReferencedDocuments

    ' Iterate through the list of documents.
    Dim oRefDoc As Document
    For Each oRefDoc In oRefDocs
		
		'iLogicVb.RunExternalRule("ruleFileName")

    Next
End Sub

 

Message 3 of 5

Tigerpirro
Advocate
Advocate

Doesn't seem to do anything.

 

I run this code.

Sub Main    
	' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
    oAsmDoc = ThisApplication.ActiveDocument
    ' Get all of the referenced documents.
    Dim oRefDocs As DocumentsEnumerator
    oRefDocs = oAsmDoc.AllReferencedDocuments

    ' Iterate through the list of documents.
    Dim oRefDoc As Document
    For Each oRefDoc In oRefDocs
		
		iLogicVb.RunExternalRule("Test.txt")

    Next
End Sub

Test.txt is just this:

iProperties.Value("Custom", "Test") = "test"

None of the parts in my assembly got the custom iproperty, but it does run the code in the assembly that I am in.

I get no errors, and it seems to run just fine.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Hi @Tigerpirro.

Try changing this line:

iLogicVb.RunExternalRule("Test.txt")

to this:

iLogicVb.Automation.RunExternalRule(oRefDoc, "Test.txt")

 This other method tells the external rule which document to use as the context of the rule that it is going to run.  However, in most cases the rule that it is going to run would also need to be prepared correctly to use that document, but I think it should work OK in your case here.

That iProperties line:

iProperties.Value("Custom", "Test") = "test"

does not specify which document it is supposed to be targeting, as it currently is, so it would normally default to targeting the 'local' document (the document the rule is saved within), if the rule was saved within a document, but when used in an external rule, that designation gets blurred a bit.  The next document it would normally target is the 'active' document, which in your case is still the main assembly, not any of the referenced documents you are looping through.  This scenario should help fix this confusing issue of what document that iLogic snippet is targeting for you...I hope. 😉

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Actually, since the contents of that other rule are so simple and vague, it might work better for you if you just put the iProperty snippet right into this main rule and modified it a bit so it will target each reference document by name.  This would probably be the next simplest edit to your rule that would make it do the task you want.  This does not run your other rule, but instead just uses that iProperties.Value() iLogic snippet directly, and supplies it the document name that we want it to work on, as the first input variable.  This will only work when accessing documents referenced within the active or local assembly though.

 

Sub Main    
	' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    ' Get all of the referenced documents.
    oRefDocs = oAsmDoc.AllReferencedDocuments
    ' Iterate through the list of documents.
    For Each oRefDoc As Document In oRefDocs
		'get the file's name, without path, but with file extension
		oDocName = System.IO.Path.GetFileName(oRefDoc.FullFileName)
		iProperties.Value(oDocName, "Custom", "Test") = "test"
    Next
End Sub

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)