Run external rulel for child in assembly

Run external rulel for child in assembly

gert-leonvanlier
Collaborator Collaborator
426 Views
4 Replies
Message 1 of 5

Run external rulel for child in assembly

gert-leonvanlier
Collaborator
Collaborator

I have an external rule that should be run on every part in an assembly. The rule is triggered form within the parts. The trouble I have is that I can't find a solution for the fact that the rule is now only working on the active document (which is always the assembly) instead of the part. This is because right now the code is as follows.

'Check document type, customize definitions to suit type, then either continue or exit if wrong type.
If oDocType = DocumentTypeEnum.kPartDocumentObject Then
	oPDoc = ThisApplication.ActiveDocument
	oPDef = oPDoc.ComponentDefinition
	oParams = oPDef.Parameters
	oCustomProps = oPDoc.PropertySets.Item("User Defined Properties") 
ElseIf oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
	oADoc = ThisApplication.ActiveDocument
	oADef = oADoc.ComponentDefinition
	oParams = oADef.Parameters
	oCustomProps = oADoc.PropertySets.Item("User Defined Properties") 
ElseIf oDocType = DocumentTypeEnum.kDrawingDocumentObject Then
	oDDoc = ThisApplication.ActiveDocument
	oParams = oDDoc.Parameters
	oCustomProps = oDDoc.PropertySets.Item("User Defined Properties")
'Else Return
End If

 

My question is how to change the document to the document being edited. ThisApplication.ActiveEditDocument does not seem to work. I think it should be something like ThisDoc, but I can not find any info on how to use that for properties inside the parts.

 

 

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

Anonymous
Not applicable

I'm not master of iLogic, but I managed to piece a rule together some years ago that referenced all documents.

 

I think you're missing something along the lines of this:

 

For Each oDoc In oAsmDoc.AllReferencedDocuments - See below for context.

 

Sub Main
ChangeAllPartMaterial()
End Sub

Public Sub ChangeAllPartMaterial() 
    ' Get the active assembly document. 
    Dim oAsmDoc As AssemblyDocument  
    oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the material to assign to all of the parts. 
    Dim strMaterialName As String 
    strMaterialName = "S235" 

    Dim oMaterial As Material 
    On Error Resume Next 
    ' Try to get the material of the specified name. 
     oMaterial = oAsmDoc.Materials.Item(strMaterialName) 
    
    On Error Goto 0 

    ' Iterate through all of the documents refrenced by the assembly. 
    Dim oDoc As Document 
    For Each oDoc In oAsmDoc.AllReferencedDocuments 
        ' Check to see if this is a part. 
        If oDoc.DocumentType = kPartDocumentObject Then 
            Dim oPartDoc As PartDocument 
            oPartDoc = oDoc 

            ' Set the material. 
            oPartDoc.ComponentDefinition.Material = oMaterial 
        End If 
		ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
    Next 
End Sub 

 

 

0 Likes
Message 3 of 5

gert-leonvanlier
Collaborator
Collaborator

Thanks, but that is not what I am looking for. The rule I wrote should only be run on one particular part when it is changed from within the assembly.

0 Likes
Message 4 of 5

dutt.thakar
Collaborator
Collaborator

@gert-leonvanlier 

Whatever I managed to understand from your question, I have tried to put together an iLogic code, I am assuming that you are targeting a specific Occurrence inside an assembly and want to run an external rule by accessing it. The rule you have added in the question, I have created a function of it and to test I have created a simple external rule that shows the file name in which it is running.

 

Sub Main

Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

Dim oIL = iLogicVb.Automation

Dim oOcc As ComponentOccurrence = oDef.Occurrences.ItemByName("Cylinder")

GetTyp(oOcc)

oIL.RunExternalRule(oOcc.Definition.Document, "External Rule Name")

End Sub

Function GetTyp(oOcc As ComponentOccurrence) As DocumentTypeEnum If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then oPDoc = ThisApplication.ActiveDocument oPDef = oPDoc.ComponentDefinition oParams = oPDef.Parameters oCustomProps = oPDoc.PropertySets.Item("User Defined Properties") ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then oADoc = ThisApplication.ActiveDocument oADef = oADoc.ComponentDefinition oParams = oADef.Parameters oCustomProps = oADoc.PropertySets.Item("User Defined Properties") ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then oDDoc = ThisApplication.ActiveDocument oParams = oDDoc.Parameters oCustomProps = oDDoc.PropertySets.Item("User Defined Properties") 'Else Return End If End Function

 Hope I have understood correctly and it helps.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

In your first post you stated that the external rule is being triggered from the parts.  What specific event is triggering this external rule to run?  Is the Event Triggers set-up in the Part (and not in the Assembly), in the Assembly (but not in the Part), or in both?

In your first post you said this rule needed to run on every part in the assembly, but in your other post you said it only needed to run on one particular part when it is changed from within the assembly.  This is confusing.  Is it to be ran on each PartDocument in the main assembly, or is it only supposed to run on one part within the assembly?

Is the code you posted the whole rule, or just the beginning of it?  What is the whole rule supposed to be doing?

 

The two ways to define a document work almost identical within external rules, but function differently in local rules.  ThisApplication.ActiveDocument will always get whichever document is 'active' at that moment within the code where it is used, no matter what.  ThisDoc.Document, in a local rule, always points to the document in which the rule is located (the local document), but when used in an external rule, I'm almost certain it will always get whichever document is 'active' when it is called.  You can cause other documents to become active throughout your rule, where needed, using a method of the document object itself.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes